Mercurial > hg > octave-nkf
annotate scripts/io/textscan.m @ 17338:1c89599167a6
maint: End m-files with 1 blank line.
Simplifies automated grammarchecking script.
* scripts/@ftp/ascii.m, scripts/@ftp/binary.m, scripts/@ftp/cd.m,
scripts/@ftp/close.m, scripts/@ftp/delete.m, scripts/@ftp/dir.m,
scripts/@ftp/display.m, scripts/@ftp/ftp.m, scripts/@ftp/loadobj.m,
scripts/@ftp/mget.m, scripts/@ftp/mkdir.m, scripts/@ftp/mput.m,
scripts/@ftp/rename.m, scripts/@ftp/rmdir.m, scripts/@ftp/saveobj.m,
scripts/audio/lin2mu.m, scripts/audio/loadaudio.m, scripts/audio/mu2lin.m,
scripts/audio/record.m, scripts/audio/saveaudio.m, scripts/audio/setaudio.m,
scripts/deprecated/__error_text__.m, scripts/deprecated/cut.m,
scripts/deprecated/error_text.m, scripts/deprecated/isstr.m,
scripts/deprecated/polyderiv.m, scripts/deprecated/studentize.m,
scripts/deprecated/sylvester_matrix.m, scripts/general/bicubic.m,
scripts/general/celldisp.m, scripts/general/colon.m,
scripts/general/cplxpair.m, scripts/general/del2.m, scripts/general/display.m,
scripts/general/isdir.m, scripts/general/isequaln.m, scripts/general/loadobj.m,
scripts/general/private/__isequal__.m, scripts/general/private/__splinen__.m,
scripts/general/profexplore.m, scripts/general/quadgk.m,
scripts/general/randi.m, scripts/general/repmat.m, scripts/general/saveobj.m,
scripts/geometry/delaunay.m, scripts/help/__unimplemented__.m,
scripts/help/doc_cache_create.m, scripts/help/get_first_help_sentence.m,
scripts/help/help.m, scripts/help/print_usage.m,
scripts/help/private/__additional_help_message__.m,
scripts/help/private/__strip_html_tags__.m, scripts/help/type.m,
scripts/image/imfinfo.m, scripts/image/imformats.m, scripts/image/imread.m,
scripts/image/imwrite.m, scripts/image/private/__imfinfo__.m,
scripts/image/private/__imread__.m, scripts/image/private/__imwrite__.m,
scripts/image/private/imageIO.m, scripts/image/private/imwrite_filename.m,
scripts/image/private/ind2x.m, scripts/io/beep.m, scripts/io/strread.m,
scripts/io/textread.m, scripts/io/textscan.m, scripts/linear-algebra/krylov.m,
scripts/linear-algebra/subspace.m, scripts/miscellaneous/bug_report.m,
scripts/miscellaneous/bunzip2.m, scripts/miscellaneous/cast.m,
scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m,
scripts/miscellaneous/dir.m, scripts/miscellaneous/dump_prefs.m,
scripts/miscellaneous/error_ids.m, scripts/miscellaneous/fileattrib.m,
scripts/miscellaneous/gunzip.m, scripts/miscellaneous/isdeployed.m,
scripts/miscellaneous/ismac.m, scripts/miscellaneous/mex.m,
scripts/miscellaneous/mexext.m, scripts/miscellaneous/mkoctfile.m,
scripts/miscellaneous/movefile.m, scripts/miscellaneous/namelengthmax.m,
scripts/miscellaneous/news.m, scripts/miscellaneous/pack.m,
scripts/miscellaneous/perl.m,
scripts/miscellaneous/private/display_info_file.m,
scripts/miscellaneous/python.m, scripts/miscellaneous/rmappdata.m,
scripts/miscellaneous/run.m, scripts/miscellaneous/tar.m,
scripts/miscellaneous/tempname.m, scripts/miscellaneous/untar.m,
scripts/miscellaneous/unzip.m, scripts/miscellaneous/what.m,
scripts/miscellaneous/zip.m, scripts/optimization/fminunc.m,
scripts/optimization/fsolve.m, scripts/optimization/fzero.m,
scripts/optimization/glpk.m, scripts/optimization/optimget.m,
scripts/optimization/optimset.m, scripts/optimization/qp.m,
scripts/optimization/sqp.m, scripts/path/pathdef.m, scripts/pkg/pkg.m,
scripts/pkg/private/build.m, scripts/pkg/private/describe.m,
scripts/pkg/private/dirempty.m, scripts/pkg/private/get_forge_download.m,
scripts/pkg/private/get_forge_pkg.m,
scripts/pkg/private/get_unsatisfied_deps.m, scripts/pkg/private/install.m,
scripts/pkg/private/is_architecture_dependent.m,
scripts/pkg/private/list_forge_packages.m, scripts/pkg/private/rebuild.m,
scripts/pkg/private/shell.m, scripts/pkg/private/uninstall.m,
scripts/plot/axes.m, scripts/plot/box.m, scripts/plot/closereq.m,
scripts/plot/diffuse.m, scripts/plot/ezpolar.m, scripts/plot/findfigs.m,
scripts/plot/gco.m, scripts/plot/guidata.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/linkprop.m, scripts/plot/peaks.m,
scripts/plot/print.m, scripts/plot/private/__add_datasource__.m,
scripts/plot/private/__axis_label__.m, scripts/plot/private/__clabel__.m,
scripts/plot/private/__color_str_rgb__.m, scripts/plot/private/__contour__.m,
scripts/plot/private/__default_plot_options__.m,
scripts/plot/private/__errcomm__.m, scripts/plot/private/__file_filter__.m,
scripts/plot/private/__fltk_file_filter__.m,
scripts/plot/private/__getlegenddata__.m,
scripts/plot/private/__gnuplot_open_stream__.m,
scripts/plot/private/__gnuplot_print__.m,
scripts/plot/private/__go_draw_axes__.m,
scripts/plot/private/__interp_cube__.m, scripts/plot/private/__is_function__.m,
scripts/plot/private/__line__.m, scripts/plot/private/__marching_cube__.m,
scripts/plot/private/__next_line_style__.m, scripts/plot/private/__patch__.m,
scripts/plot/private/__pie__.m, scripts/plot/private/__pltopt__.m,
scripts/plot/private/__quiver__.m, scripts/plot/private/__scatter__.m,
scripts/plot/private/__stem__.m, scripts/plot/private/__uigetdir_fltk__.m,
scripts/plot/private/__uigetfile_fltk__.m,
scripts/plot/private/__uiobject_split_args__.m,
scripts/plot/private/__uiputfile_fltk__.m, scripts/plot/refresh.m,
scripts/plot/saveas.m, scripts/plot/shg.m, scripts/plot/specular.m,
scripts/plot/sphere.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/uicontextmenu.m, scripts/plot/uicontrol.m, scripts/plot/uipanel.m,
scripts/plot/uipushtool.m, scripts/plot/uiresume.m,
scripts/plot/uitoggletool.m, scripts/plot/uitoolbar.m, scripts/plot/uiwait.m,
scripts/plot/waitforbuttonpress.m, scripts/polynomial/pchip.m,
scripts/polynomial/polyeig.m, scripts/polynomial/ppval.m,
scripts/prefs/addpref.m, scripts/prefs/getpref.m, scripts/prefs/ispref.m,
scripts/prefs/private/loadprefs.m, scripts/prefs/private/prefsfile.m,
scripts/prefs/private/saveprefs.m, scripts/prefs/setpref.m,
scripts/set/private/validargs.m, scripts/set/unique.m,
scripts/signal/arch_fit.m, scripts/signal/arch_rnd.m,
scripts/signal/arch_test.m, scripts/signal/arma_rnd.m,
scripts/signal/durbinlevinson.m, scripts/signal/fractdiff.m,
scripts/signal/freqz.m, scripts/signal/freqz_plot.m, scripts/signal/hurst.m,
scripts/signal/periodogram.m, scripts/signal/private/rectangle_lw.m,
scripts/signal/private/rectangle_sw.m, scripts/signal/private/triangle_sw.m,
scripts/signal/spectral_adf.m, scripts/signal/spectral_xdf.m,
scripts/signal/stft.m, scripts/signal/synthesis.m, scripts/signal/yulewalker.m,
scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m,
scripts/sparse/gmres.m, scripts/sparse/private/__sprand_impl__.m,
scripts/sparse/spdiags.m, scripts/sparse/sprandn.m, scripts/specfun/bessel.m,
scripts/specfun/betaln.m, scripts/specfun/expint.m,
scripts/special-matrix/gallery.m, scripts/startup/__finish__.m,
scripts/statistics/base/qqplot.m, scripts/statistics/distributions/tcdf.m,
scripts/statistics/distributions/wienrnd.m,
scripts/statistics/models/logistic_regression.m,
scripts/statistics/models/private/logistic_regression_derivatives.m,
scripts/statistics/models/private/logistic_regression_likelihood.m,
scripts/statistics/tests/anova.m, scripts/statistics/tests/bartlett_test.m,
scripts/statistics/tests/chisquare_test_homogeneity.m,
scripts/statistics/tests/chisquare_test_independence.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/f_test_regression.m,
scripts/statistics/tests/hotelling_test.m,
scripts/statistics/tests/hotelling_test_2.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/manova.m, scripts/statistics/tests/mcnemar_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/run_test.m,
scripts/statistics/tests/sign_test.m, scripts/statistics/tests/t_test.m,
scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m, scripts/strings/strcat.m,
scripts/strings/strjoin.m, scripts/strings/strsplit.m,
scripts/testfun/__have_feature__.m, scripts/testfun/__printf_assert__.m,
scripts/testfun/__prog_output_assert__.m, scripts/testfun/__run_test_suite__.m,
scripts/time/clock.m, scripts/time/datenum.m, scripts/ui/errordlg.m,
scripts/ui/private/message_dialog.m: End m-files with 1 blank line.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 28 Aug 2013 08:33:02 -0700 |
parents | b81b9d079515 |
children | 2ce1f1966fc3 |
rev | line source |
---|---|
16768 | 1 ## Copyright (C) 2010-2013 Ben Abbott |
11141 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
20 ## @deftypefn {Function File} {@var{C} =} textscan (@var{fid}, @var{format}) |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{C} =} textscan (@var{fid}, @var{format}, @var{n}) |
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{C} =} textscan (@var{fid}, @var{format}, @var{param}, @var{value}, @dots{}) |
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{C} =} textscan (@var{fid}, @var{format}, @var{n}, @var{param}, @var{value}, @dots{}) |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
24 ## @deftypefnx {Function File} {@var{C} =} textscan (@var{str}, @dots{}) |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
25 ## @deftypefnx {Function File} {[@var{C}, @var{position}] =} textscan (@var{fid}, @dots{}) |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
26 ## Read data from a text file or string. |
11141 | 27 ## |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
28 ## The string @var{str} or file associated with @var{fid} is read from and |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14800
diff
changeset
|
29 ## parsed according to @var{format}. The function behaves like @code{strread} |
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14800
diff
changeset
|
30 ## except it can also read from file instead of a string. See the documentation |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
31 ## of @code{strread} for details. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
32 ## |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
33 ## In addition to the options supported by @code{strread}, this function |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
34 ## supports a few more: |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
35 ## |
11141 | 36 ## @itemize |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
37 ## @item @qcode{"collectoutput"}: |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
38 ## A value of 1 or true instructs textscan to concatenate consecutive columns |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
39 ## of the same class in the output cell array. A value of 0 or false (default) |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
40 ## leaves output in distinct columns. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
41 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
42 ## @item @qcode{"endofline"}: |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
43 ## Specify @qcode{"\r"}, @qcode{"\n"} or @qcode{"\r\n"} (for CR, LF, or |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
44 ## CRLF). If no value is given, it will be inferred from the file. If set |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
45 ## to "" (empty string) EOLs are ignored as delimiters and added to |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
46 ## whitespace. |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
47 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
48 ## @item @qcode{"headerlines"}: |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
49 ## The first @var{value} number of lines of @var{fid} are skipped. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
50 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
51 ## @item @qcode{"returnonerror"}: |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
52 ## If set to numerical 1 or true (default), return normally when read errors |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
53 ## have been encountered. If set to 0 or false, return an error and no data. |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
54 ## As the string or file is read by columns rather than by rows, and because |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
55 ## textscan is fairly forgiving as regards read errors, setting this option |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
56 ## may have little or no actual effect. |
11141 | 57 ## @end itemize |
58 ## | |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
59 ## When reading from a character string, optional input argument @var{n} |
14621
1804d5422f61
doc: Periodic spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14582
diff
changeset
|
60 ## specifies the number of times @var{format} should be used (i.e., to limit |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
61 ## the amount of data read). |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
62 ## When reading from file, @var{n} specifies the number of data lines to read; |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
63 ## in this sense it differs slightly from the format repeat count in strread. |
11141 | 64 ## |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
65 ## The output @var{C} is a cell array whose second dimension is determined |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
66 ## by the number of format specifiers. |
11141 | 67 ## |
68 ## The second output, @var{position}, provides the position, in characters, | |
69 ## from the beginning of the file. | |
70 ## | |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
71 ## If the format string is empty (not: omitted) and the file contains only |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
72 ## numeric data (excluding headerlines), textscan will return data in a number |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
73 ## of columns matching the number of numeric fields on the first data line of |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
74 ## the file. |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
75 ## |
11141 | 76 ## @seealso{dlmread, fscanf, load, strread, textread} |
77 ## @end deftypefn | |
78 | |
16768 | 79 ## Author: Ben Abbott <bpabbott@mac.com> |
80 | |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
81 function [C, position] = textscan (fid, format = "%f", varargin) |
11141 | 82 |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17312
diff
changeset
|
83 BUFLENGTH = 4096; # Read buffer |
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17312
diff
changeset
|
84 emptfmt = 0; # Signals deliberately empty format string |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
85 |
11141 | 86 ## Check input |
87 if (nargin < 1) | |
88 print_usage (); | |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
89 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
90 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
91 if (isempty (format)) |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
92 emptfmt = 1; |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11191
diff
changeset
|
93 format = "%f"; |
11141 | 94 endif |
95 | |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
96 if (! ischar (format)) |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
97 error ("textscan: FORMAT must be a string"); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
98 endif |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
99 |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
100 ## Determine the number of data fields & initialize output array |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
101 num_fields = numel (strfind (format, "%")) - numel (strfind (format, "%*")); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
102 C = cell (1, num_fields); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
103 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
104 if (! (isa (fid, "double") && fid > 0) && ! ischar (fid)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
105 error ("textscan: first argument must be a file id or character string"); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
106 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
107 |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
108 args = varargin; |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
109 if (nargin > 2 && isnumeric (args{1})) |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
110 nlines = args{1}; |
11141 | 111 else |
112 nlines = Inf; | |
113 endif | |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
114 if (nlines < 1) |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
115 printf ("textscan: N = 0, no data read\n"); |
17312
088d014a7fe2
Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
116 return; endif |
11141 | 117 |
118 if (! any (strcmpi (args, "emptyvalue"))) | |
119 ## Matlab returns NaNs for missing values | |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
120 args(end+1:end+2) = {'emptyvalue', NaN}; |
11141 | 121 endif |
122 | |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
123 ## Check default parameter values that differ for strread & textread |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
124 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
125 ipos = find (strcmpi (args, "whitespace")); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
126 if (isempty (ipos)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
127 ## Matlab default whitespace = " \b\t" |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
128 args(end+1:end+2) = {'whitespace', " \b\t"}; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
129 whitespace = " \b\t"; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
130 else |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
131 ## Check if there's at least one string format specifier |
14213
a022c04f68cc
Replace to-be-deprecated strmatch occurrences with alternate code.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
132 has_str_fmt = regexp (format, '%[*]?\d*s', "once"); |
a022c04f68cc
Replace to-be-deprecated strmatch occurrences with alternate code.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
133 ## If there is a string format AND whitespace value = empty, |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
134 ## don't add a space (char(32)) to whitespace |
14213
a022c04f68cc
Replace to-be-deprecated strmatch occurrences with alternate code.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
135 if (! (isempty (args{ipos+1}) && has_str_fmt)) |
15871
878623ca15e1
textscan.m: fix treatment of whitespace argument (bug #37961)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
136 args{ipos+1} = unique ([" ", args{ipos+1}]); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
137 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
138 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
139 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
140 if (! any (strcmpi (args, "delimiter"))) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12916
diff
changeset
|
141 ## Matlab says default delimiter = whitespace. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
142 ## strread() will pick this up further |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
143 args(end+1:end+2) = {'delimiter', ""}; |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
144 delimiter = ""; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
145 else |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
146 delimiter = args{find (strcmpi (args, "delimiter")) + 1}; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
147 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
148 |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
149 collop = false; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
150 ipos = find (strcmpi (args, "collectoutput")); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
151 if (! isempty (ipos)) |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
152 ## Search & concatenate consecutive columns of same class requested |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
153 if (isscalar (args{ipos+1}) |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
154 && (islogical (args{ipos+1}) || isnumeric (args{ipos+1}))) |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
155 collop = args{ipos+1}; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
156 else |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
157 warning ("textscan: illegal value for CollectOutput parameter - ignored"); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
158 endif |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
159 ## Remove argument before call to strread() below |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
160 args(ipos:ipos+1) = []; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
161 endif |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
162 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
163 if (any (strcmpi (args, "returnonerror"))) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
164 ## Because of the way strread() reads data (columnwise) this parameter |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
165 ## can't be neatly implemented. strread() will pick it up anyway |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
166 warning ('textscan: ReturnOnError is not fully implemented'); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
167 else |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
168 ## Set default value (=true) |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
169 args(end+1:end+2) = {"returnonerror", 1}; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
170 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
171 |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
172 ## Check if a headerlines argument is specified |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
173 headerlines = find (strcmpi (args, "headerlines"), 1); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
174 if (! isempty (headerlines)) |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
175 ## Yep. But it is stray when reading from strings... |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
176 if (ischar (fid)) |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
177 warning ("textscan: 'headerlines' ignored when reading from strings"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
178 endif |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
179 endif |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
180 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
181 if (ischar (fid)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
182 ## Read from a text string |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
183 if (nargout == 2) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
184 error ("textscan: cannot provide position information for character input"); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
185 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
186 str = fid; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
187 else |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
188 st_pos = ftell (fid); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
189 ## Skip header lines if requested |
16060
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
190 if (! isempty (headerlines)) |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
191 ## Beware of missing or wrong headerline value |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
192 if (headerlines == numel (args) |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
193 || ! isnumeric (args{headerlines + 1})) |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
194 error ("Missing or illegal value for 'headerlines'" ); |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
195 endif |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
196 ## Avoid conveying floats to fskipl |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
197 args{headerlines + 1} = round (args{headerlines + 1}); |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
198 if (args{headerlines + 1} > 0) |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
199 ## Beware of zero valued headerline, fskipl would skip to EOF |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
200 fskipl (fid, args{headerlines + 1}); |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
201 args(headerlines:headerlines+1) = []; |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
202 st_pos = ftell (fid); |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
203 elseif (args{headerlines + 1} < 0) |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
204 warning ("textscan.m: negative headerline value ignored"); |
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
205 endif |
16305
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
206 endif |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
207 ## Read a first file chunk. Rest follows after endofline processing |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
208 [str, count] = fscanf (fid, "%c", BUFLENGTH); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
209 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
210 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
211 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
212 ## Check for empty result |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
213 if (isempty (str)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
214 warning ("textscan: no data read"); |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
215 return; |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
216 endif |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
217 |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
218 ## Check value of 'endofline'. String or file doesn't seem to matter |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
219 endofline = find (strcmpi (args, "endofline"), 1); |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
220 if (! isempty (endofline)) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12916
diff
changeset
|
221 if (ischar (args{endofline + 1})) |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
222 eol_char = args{endofline + 1}; |
14213
a022c04f68cc
Replace to-be-deprecated strmatch occurrences with alternate code.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
223 if (! any (strcmp (eol_char, {"", "\n", "\r", "\r\n"}))) |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
224 error ("textscan: illegal EndOfLine character value specified"); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
225 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
226 else |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12916
diff
changeset
|
227 error ("textscan: character value required for EndOfLine"); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
228 endif |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
229 else |
15868
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
230 if (! ischar (fid)) |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
231 ## Determine EOL from file. Search for EOL candidates in first BUFLENGTH chars |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
232 eol_srch_len = min (length (str), BUFLENGTH); |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
233 ## First try DOS (CRLF) |
16311
9c4ac8f25a8c
textscan.m, textread.m: fix wrong code assessing EOL char(s), remove duplicate code
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16305
diff
changeset
|
234 if (! isempty (strfind (str(1 : eol_srch_len), "\r\n"))) |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
235 eol_char = "\r\n"; |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
236 ## Perhaps old Macintosh? (CR) |
16311
9c4ac8f25a8c
textscan.m, textread.m: fix wrong code assessing EOL char(s), remove duplicate code
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16305
diff
changeset
|
237 elseif (! isempty (strfind (str(1 : eol_srch_len), "\r"))) |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
238 eol_char = "\r"; |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
239 ## Otherwise, use plain UNIX (LF) |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
240 else |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
241 eol_char = "\n"; |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
242 endif |
15868
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
243 else |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
244 eol_char = "\n"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
245 endif |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
246 ## Set up the default endofline param value |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
247 args(end+1:end+2) = {"endofline", eol_char}; |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
248 endif |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
249 |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
250 if (!ischar (fid)) |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
251 ## Now that we know what EOL looks like, we can process format_repeat_count. |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
252 ## FIXME The below isn't ML-compatible: counts lines, not format string uses |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
253 if (isfinite (nlines) && (nlines >= 0)) |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
254 l_eol_char = length (eol_char); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
255 eoi = findstr (str, eol_char); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
256 n_eoi = length (eoi); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
257 nblks = 0; |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
258 ## Avoid slow repeated str concatenation, first seek requested end of data |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
259 while (n_eoi < nlines && count == BUFLENGTH) |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
260 [nstr, count] = fscanf (fid, "%c", BUFLENGTH); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
261 if (count > 0) |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
262 ## Watch out for multichar EOL being missed across buffer boundaries |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
263 if (l_eol_char > 1) |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
264 str = [str(end - length (eol_char) + 2 : end) nstr]; |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
265 else |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
266 str = nstr; |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
267 endif |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
268 eoi = findstr (str, eol_char); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
269 n_eoi += numel (eoi); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
270 ++nblks; |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
271 endif |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
272 endwhile |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
273 ## OK, found EOL delimiting last requested line. Compute ptr (incl. EOL) |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
274 if (isempty (eoi)) |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
275 printf ("textscan: format repeat count specified but no endofline found\n"); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
276 data_size = nblks * BUFLENGTH + count; |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
277 else |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
278 ## Compute data size to read incl complete EOL |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
16768
diff
changeset
|
279 data_size = (nblks * BUFLENGTH) + eoi(end + min (nlines, n_eoi) - n_eoi) ... |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
280 + l_eol_char - 1; |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
281 endif |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
282 fseek (fid, st_pos, "bof"); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
283 str = fscanf (fid, "%c", data_size); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
284 else |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
285 fseek (fid, st_pos, "bof"); |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
286 str = fread (fid, "char=>char").'; |
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
287 endif |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
288 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
289 |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
290 ## Strip trailing EOL to avoid returning stray missing values (f. strread). |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
291 ## However, in case of CollectOutput request, presence of EOL is required; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
292 ## also in case of deliberately entered empty format string |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
293 eol_at_end = strcmp (str(end-length (eol_char) + 1 : end), eol_char); |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
294 if (collop || emptfmt) |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
295 if (! eol_at_end) |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
296 str(end+1 : end+length (eol_char)) = eol_char; |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
297 endif |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
298 elseif (eol_at_end) |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
299 str(end-length (eol_char) + 1 : end) = ""; |
14800
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
300 ## A corner case: str may now be empty.... |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
301 if (isempty (str)); return; endif |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
302 endif |
11141 | 303 |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
304 ## Call strread to make it do the real work |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
305 C = cell (1, num_fields); |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
306 [C{:}] = strread (str, format, args{:}); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12916
diff
changeset
|
307 |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
308 ## I.c.o. empty format, match nr. of cols to nr. of fields on first read line |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
309 if (emptfmt) |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
310 ## Find end of first line |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
311 eoi = index (str, eol_char); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
312 if (eoi) |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
313 ## str contains an EOL, proceed with assessing nr. of columns |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
314 ncols = countcols (C, str(1 : eoi-1), delimiter, whitespace); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
315 ## See if lowermost data row must be completed |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
316 pad = mod (numel (C{1}), ncols); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
317 if (pad) |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
318 ## Textscan returns NaNs for empty fields |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
319 C(1) = [C{1}; NaN(ncols - pad, 1)]; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
320 endif |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
321 ## Replace NaNs with EmptyValue, if any |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
322 ipos = find (strcmpi (args, "emptyvalue")); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
323 if (ipos) |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
324 C{1}(find (isnan (C{1}))) = args{ipos+1}; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
325 endif |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
326 ## Compute nr. of rows |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
327 nrows = floor (numel (C{1}) / ncols); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
328 ## Reshape C; watch out, transpose needed |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
329 C(1) = reshape (C{1}, ncols, numel (C{1}) / ncols)'; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
330 ## Distribute columns over C and wipe cols 2:end of C{1} |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
331 for ii=2:ncols |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
332 C(ii) = C{1}(:, ii); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
333 endfor |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
334 C{1} = C{1}(:, 1); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
335 endif |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
336 endif |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
337 |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
338 ## If requested, collect output columns of same class |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
339 if (collop) |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
340 C = colloutp (C); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
341 endif |
11141 | 342 |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
343 if (nargout == 2) |
14565
98aaebc56d7c
2012-03-25 Philip Nienhuis <prnienhuis@users.sf.net>
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
14552
diff
changeset
|
344 ## Remember file position (persistent var) |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
345 position = ftell (fid); |
11141 | 346 endif |
347 | |
348 endfunction | |
349 | |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
350 |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
351 ## Assess nr of data fields on first line of data |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
352 function ncols = countcols (C, str, dlm, wsp) |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
353 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
354 if (isempty (dlm)) |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
355 ## Field separator = whitespace. Fold multiple whitespace into one |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
356 str = regexprep (str, sprintf ("[%s]", wsp), " "); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
357 str = strtrim (str); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
358 ncols = numel (strfind (str, " ")) + 1; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
359 else |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
360 ncols = numel (regexp (str, sprintf ("[%s]", dlm))) + 1; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
361 endif |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
362 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
363 endfunction |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
364 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
365 |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
366 ## Collect consecutive columns of same class into one cell column |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
367 function C = colloutp (C) |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
368 |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
369 ## Start at rightmost column and work backwards to avoid ptr mixup |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
370 ii = numel (C); |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
371 while (ii > 1) |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
372 clss1 = class (C{ii}); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
373 jj = ii; |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
374 while (jj > 1 && strcmp (clss1, class (C{jj - 1}))) |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
375 ## Column to the left is still same class; check next column to the left |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
376 --jj; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
377 endwhile |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
378 if (jj < ii) |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
379 ## Concatenate columns into current column |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
380 C{jj} = [C{jj : ii}]; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
381 ## Wipe concatenated columns to the right, resume search to the left |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
382 C(jj+1 : ii) = []; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
383 ii = jj - 1; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
384 else |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
385 ## No similar class in column to the left, search from there |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
386 --ii; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
387 endif |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
388 endwhile |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
389 |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
390 endfunction |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
391 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
392 |
11141 | 393 %!test |
394 %! str = "1, 2, 3, 4\n 5, , , 8\n 9, 10, 11, 12"; | |
395 %! fmtstr = "%f %d %f %s"; | |
396 %! c = textscan (str, fmtstr, 2, "delimiter", ",", "emptyvalue", -Inf); | |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
397 %! assert (isequal (c{1}, [1;5])); |
11141 | 398 %! assert (length (c{1}), 2); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
399 %! assert (iscellstr (c{4})); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
400 %! assert (isequal (c{3}, [3; -Inf])); |
11141 | 401 |
402 %!test | |
403 %! b = [10:10:100]; | |
404 %! b = [b; 8*b/5]; | |
405 %! str = sprintf ("%g miles/hr = %g kilometers/hr\n", b); | |
406 %! fmt = "%f miles/hr = %f kilometers/hr"; | |
407 %! c = textscan (str, fmt); | |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
408 %! assert (b(1,:)', c{1}, 1e-5); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
409 %! assert (b(2,:)', c{2}, 1e-5); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
410 |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
411 %!test |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
412 %! str = "13, 72, NA, str1, 25\r\n// Middle line\r\n36, na, 05, str3, 6"; |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
413 %! a = textscan (str, "%d %n %f %s %n", "delimiter", ",","treatAsEmpty", {"NA", "na"},"commentStyle", "//"); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
414 %! assert (a{1}, int32 ([13; 36])); |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
415 %! assert (a{2}, [72; NaN]); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
416 %! assert (a{3}, [NaN; 5]); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
417 %! assert (a{4}, {"str1"; "str3"}); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
418 %! assert (a{5}, [25; 6]); |
11141 | 419 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
420 %!test |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
421 %! str = "Km:10 = hhhBjjj miles16hour\r\n"; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
422 %! str = [str "Km:15 = hhhJjjj miles241hour\r\n"]; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
423 %! str = [str "Km:2 = hhhRjjj miles3hour\r\n"]; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
424 %! str = [str "Km:25 = hhhZ\r\n"]; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
425 %! fmt = "Km:%d = hhh%1sjjj miles%dhour"; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
426 %! a = textscan (str, fmt, "delimiter", " "); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
427 %! assert (a{1}', int32 ([10 15 2 25])); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12679
diff
changeset
|
428 %! assert (a{2}', {'B' 'J' 'R' 'Z'}); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
429 %! assert (a{3}', int32 ([16 241 3 0])); |
11141 | 430 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12880
diff
changeset
|
431 %% Test with default endofline parameter |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12880
diff
changeset
|
432 %!test |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12880
diff
changeset
|
433 %! c = textscan ("L1\nL2", "%s"); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12880
diff
changeset
|
434 %! assert (c{:}, {"L1"; "L2"}); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12880
diff
changeset
|
435 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
436 %% Test with endofline parameter set to "" (empty) - newline should be in word |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12880
diff
changeset
|
437 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
438 %! c = textscan ("L1\nL2", "%s", "endofline", ""); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
439 %! assert (int8 (c{:}{:}), int8 ([ 76, 49, 10, 76, 50 ])); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12880
diff
changeset
|
440 |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
441 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17312
diff
changeset
|
442 %! ## No delimiters at all besides EOL. Skip fields, even empty fields |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
443 %! str = "Text1Text2Text\nTextText4Text\nText57Text"; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
444 %! c = textscan (str, "Text%*dText%dText"); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
445 %! assert (c{1}, int32 ([2; 4; 0])); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
446 |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
447 %!test |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
448 %% CollectOutput test |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
449 %! b = [10:10:100]; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
450 %! b = [b; 8*b/5; 8*b*1000/5]; |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
451 %! str = sprintf ("%g miles/hr = %g (%g) kilometers (meters)/hr\n", b); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
452 %! fmt = "%f miles%s %s %f (%f) kilometers %*s"; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
453 %! c = textscan (str, fmt, "collectoutput", 1); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
454 %! assert (size (c{3}), [10, 2]); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
455 %! assert (size (c{2}), [10, 2]); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
456 |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
457 %!test |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
458 %% CollectOutput test with uneven column length files |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
459 %! b = [10:10:100]; |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
460 %! b = [b; 8*b/5; 8*b*1000/5]; |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
461 %! str = sprintf ("%g miles/hr = %g (%g) kilometers (meters)/hr\n", b); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
462 %! str = [str "110 miles/hr"]; |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
463 %! fmt = "%f miles%s %s %f (%f) kilometers %*s"; |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
464 %! c = textscan (str, fmt, "collectoutput", 1); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
465 %! assert (size (c{1}), [11, 1]); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
466 %! assert (size (c{3}), [11, 2]); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
467 %! assert (size (c{2}), [11, 2]); |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
468 %! assert (c{3}(end), NaN); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
469 %! assert (c{2}{11, 1}, "/hr"); |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14621
diff
changeset
|
470 %! assert (isempty (c{2}{11, 2}), true); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
471 |
12877
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
472 %% Test input validation |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
473 %!error textscan () |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
474 %!error textscan (single (4)) |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
475 %!error textscan ({4}) |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
476 %!error <must be a string> textscan ("Hello World", 2) |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
477 %!error <cannot provide position information> [C, pos] = textscan ("Hello World") |
ddea3962b024
Various improvements to strread, textread, textscan functions
Rik <octave@nomad.inbox5.com>
parents:
12873
diff
changeset
|
478 %!error <character value required> textscan ("Hello World", '%s', 'EndOfLine', 3) |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
479 |
14800
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
480 %! Test incomplete first data line |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
481 %! R = textscan (['Empty1' char(10)], 'Empty%d %f'); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
482 %! assert (R{1}, int32 (1)); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
483 %! assert (isempty (R{2}), true); |
15263
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
484 |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
485 %% bug #37023 (actually a strread test) |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
486 %!test |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
487 %! data = textscan(" 1. 1 \n 2 3\n", '%f %f'); |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
488 %! assert (data{1}, [1; 2], 1e-15); |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
489 %! assert (data{2}, [1; 3], 1e-15); |
15868
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
490 |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
491 %% Whitespace test (bug #37333) using delimiter ";" |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
492 %!test |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
493 %! tc = []; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
494 %! tc{1, 1} = "C:/code;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
495 %! tc{1, end+1} = "C:/code/meas;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
496 %! tc{1, end+1} = " C:/code/sim;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
497 %! tc{1, end+1} = "C:/code/utils;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
498 %! string = [tc{:}]; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
499 %! c = textscan (string, "%s", "delimiter", ";"); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
500 %! for k = 1:numel (c{1}) |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
501 %! lh = c{1}{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
502 %! rh = tc{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
503 %! rh(rh == ";") = ""; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
504 %! rh = strtrim (rh); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
505 %! assert (strcmp (lh, rh)); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
506 %! end |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
507 |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
508 %% Whitespace test (bug #37333), adding multipleDelimsAsOne true arg |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
509 %!test |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
510 %! tc = []; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
511 %! tc{1, 1} = "C:/code;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
512 %! tc{1, end+1} = " C:/code/meas;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
513 %! tc{1, end+1} = "C:/code/sim;;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
514 %! tc{1, end+1} = "C:/code/utils;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
515 %! string = [tc{:}]; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
516 %! c = textscan (string, "%s", "delimiter", ";", "multipleDelimsAsOne", 1); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
517 %! for k = 1:numel (c{1}) |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
518 %! lh = c{1}{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
519 %! rh = tc{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
520 %! rh(rh == ";") = ""; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
521 %! rh = strtrim (rh); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
522 %! assert (strcmp (lh, rh)); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
523 %! end |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
524 |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
525 %% Whitespace test (bug #37333), adding multipleDelimsAsOne false arg |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
526 %!test |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
527 %! tc = []; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
528 %! tc{1, 1} = "C:/code;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
529 %! tc{1, end+1} = " C:/code/meas;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
530 %! tc{1, end+1} = "C:/code/sim;;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
531 %! tc{1, end+1} = ""; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
532 %! tc{1, end+1} = "C:/code/utils;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
533 %! string = [tc{:}]; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
534 %! c = textscan (string, "%s", "delimiter", ";", "multipleDelimsAsOne", 0); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
535 %! for k = 1:numel (c{1}) |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
536 %! lh = c{1}{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
537 %! rh = tc{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
538 %! rh(rh == ";") = ""; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
539 %! rh = strtrim (rh); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
540 %! assert (strcmp (lh, rh)); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
541 %! end |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
542 |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
543 %% Whitespace test (bug #37333) whitespace "" arg |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
544 %!test |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
545 %! tc = []; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
546 %! tc{1, 1} = "C:/code;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
547 %! tc{1, end+1} = " C:/code/meas;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
548 %! tc{1, end+1} = "C:/code/sim;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
549 %! tc{1, end+1} = "C:/code/utils;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
550 %! string = [tc{:}]; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
551 %! c = textscan (string, "%s", "delimiter", ";", "whitespace", ""); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
552 %! for k = 1:numel (c{1}) |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
553 %! lh = c{1}{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
554 %! rh = tc{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
555 %! rh(rh == ";") = ""; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
556 %! assert (strcmp (lh, rh)); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
557 %! end |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
558 |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
559 %% Whitespace test (bug #37333), whitespace " " arg |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
560 %!test |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
561 %! tc = []; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
562 %! tc{1, 1} = "C:/code;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
563 %! tc{1, end+1} = " C:/code/meas;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
564 %! tc{1, end+1} = "C:/code/sim;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
565 %! tc{1, end+1} = "C:/code/utils;"; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
566 %! string = [tc{:}]; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
567 %! c = textscan (string, "%s", "delimiter", ";", "whitespace", " "); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
568 %! for k = 1:numel (c{1}) |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
569 %! lh = c{1}{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
570 %! rh = tc{k}; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
571 %! rh(rh == ";") = ""; |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
572 %! rh = strtrim (rh); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
573 %! assert (strcmp (lh, rh)); |
6251fa48d28b
textscan.m: various whitespace & delimiter tests added
Andy Register <andy.register@gatech.edu>
parents:
15263
diff
changeset
|
574 %! end |
16060
f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15872
diff
changeset
|
575 |
16305
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
576 %% Test reading from a real file |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
577 %!test |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
578 %! f = tmpnam (); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
579 %! fid = fopen (f, "w+"); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
580 %! d = rand (1, 4); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
581 %! fprintf (fid, " %f %f %f %f ", d); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
582 %! fseek (fid, 0, "bof"); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
583 %! A = textscan (fid, "%f %f"); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
584 %! fclose (fid); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
585 %! unlink (f); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
586 %! assert (A{1}, [d(1); d(3)], 1e-6); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
587 %! assert (A{2}, [d(2); d(4)], 1e-6); |
23636765e00a
textscan.m: re-enable reading from file id, test added (bug #38517)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16060
diff
changeset
|
588 |
16357
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
589 %% Tests reading with empty format, should return proper nr of columns |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
590 %!test |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
591 %! f = tmpnam (); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
592 %! fid = fopen (f, "w+"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
593 %! fprintf (fid, " 1 2 3 4\n5 6 7 8"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
594 %! fseek (fid, 0, "bof"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
595 %! A = textscan (fid, ""); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
596 %! fclose (fid); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
597 %! unlink (f); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
598 %! assert (A{1}, [1 ; 5], 1e-6); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
599 %! assert (A{2}, [2 ; 6], 1e-6); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
600 %! assert (A{3}, [3 ; 7], 1e-6); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
601 %! assert (A{4}, [4 ; 8], 1e-6); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
602 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
603 %% Tests reading with empty format; empty fields & incomplete lower row |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
604 %!test |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
605 %! f = tmpnam (); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
606 %! fid = fopen (f, "w+"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
607 %! fprintf (fid, " ,2,,4\n5,6"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
608 %! fseek (fid, 0, "bof"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
609 %! A = textscan (fid, "", "delimiter", ",", "EmptyValue", 999, "CollectOutput" , 1); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
610 %! fclose (fid); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
611 %! unlink (f); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
612 %! assert (A{1}, [999, 2, 999, 4; 5, 6, 999, 999], 1e-6); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
613 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
614 %% Error message tests |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
615 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
616 %!test |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
617 %! f = tmpnam (); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
618 %! fid = fopen (f, "w+"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
619 %! msg1 = "Missing or illegal value for 'headerlines'"; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
620 %! try |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
621 %! A = textscan (fid, "", "headerlines"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
622 %! end_try_catch; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
623 %! fclose (fid); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
624 %! unlink (f); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
625 %! assert (msg1, lasterr); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
626 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
627 %!test |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
628 %! f = tmpnam (); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
629 %! fid = fopen (f, "w+"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
630 %! msg1 = "Missing or illegal value for 'headerlines'"; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
631 %! try |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
632 %! A = textscan (fid, "", "headerlines", "hh"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
633 %! end_try_catch; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
634 %! fclose (fid); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
635 %! unlink (f); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
636 %! assert (msg1, lasterr); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
637 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
638 %!test |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
639 %! f = tmpnam (); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
640 %! fid = fopen (f, "w+"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
641 %! fprintf (fid,"some_string"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
642 %! fseek (fid, 0, "bof"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
643 %! msg1 = "textscan: illegal EndOfLine character value specified"; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
644 %! try |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
645 %! A = textscan (fid, "%f", "EndOfLine", "\n\r"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
646 %! end_try_catch; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
647 %! fclose (fid); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
648 %! unlink (f); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
649 %! assert (msg1, lasterr); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
650 |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
651 %!test |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
652 %! f = tmpnam (); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
653 %! fid = fopen (f, "w+"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
654 %! fprintf (fid,"some_string"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
655 %! fseek (fid, 0, "bof"); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
656 %! msg1 = "textscan: character value required for EndOfLine"; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
657 %! try |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
658 %! A = textscan (fid, "%f", "EndOfLine", 33); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
659 %! end_try_catch; |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
660 %! fclose (fid); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
661 %! unlink (f); |
0cbe330f39a2
textscan.m, textread.m: allow reading multi-column data files with empty format + tests (bug #38317)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16311
diff
changeset
|
662 %! assert (msg1, lasterr); |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
663 |