Mercurial > octave-nkf
comparison scripts/io/textscan.m @ 16060:f837bdd535f7
textscan.m: catch wrong headerlines values, tests added
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Thu, 14 Feb 2013 21:11:46 +0100 |
parents | 1733bd181cb6 |
children | 23636765e00a |
comparison
equal
deleted
inserted
replaced
16059:2175c41b12d1 | 16060:f837bdd535f7 |
---|---|
1 ## Copyright (C) 2010-2012 Ben Abbott <bpabbott@mac.com> | 1 ## Copyright (C) 2010-2013 Ben Abbott <bpabbott@mac.com> |
2 ## | 2 ## |
3 ## This file is part of Octave. | 3 ## This file is part of Octave. |
4 ## | 4 ## |
5 ## Octave is free software; you can redistribute it and/or modify it | 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 | 6 ## under the terms of the GNU General Public License as published by |
165 str = fid; | 165 str = fid; |
166 else | 166 else |
167 st_pos = ftell (fid); | 167 st_pos = ftell (fid); |
168 ## Skip header lines if requested | 168 ## Skip header lines if requested |
169 headerlines = find (strcmpi (args, "headerlines"), 1); | 169 headerlines = find (strcmpi (args, "headerlines"), 1); |
170 ## Beware of zero valued headerline, fskipl would skip to EOF | 170 if (! isempty (headerlines)) |
171 if (! isempty (headerlines) && (args{headerlines + 1} > 0)) | 171 ## Beware of missing or wrong headerline value |
172 fskipl (fid, args{headerlines + 1}); | 172 if (headerlines == numel (args) |
173 args(headerlines:headerlines+1) = []; | 173 || ! isnumeric (args{headerlines + 1})) |
174 st_pos = ftell (fid); | 174 error ("Missing or illegal value for 'headerlines'" ); |
175 endif | 175 endif |
176 ## Read a first file chunk. Rest follows after endofline processing | 176 ## Avoid conveying floats to fskipl |
177 [str, count] = fscanf (fid, "%c", BUFLENGTH); | 177 args{headerlines + 1} = round (args{headerlines + 1}); |
178 if (args{headerlines + 1} > 0) | |
179 ## Beware of zero valued headerline, fskipl would skip to EOF | |
180 fskipl (fid, args{headerlines + 1}); | |
181 args(headerlines:headerlines+1) = []; | |
182 st_pos = ftell (fid); | |
183 elseif (args{headerlines + 1} < 0) | |
184 warning ("textscan.m: negative headerline value ignored"); | |
185 endif | |
186 endif | |
178 endif | 187 endif |
179 | 188 |
180 ## Check for empty result | 189 ## Check for empty result |
181 if (isempty (str)) | 190 if (isempty (str)) |
182 warning ("textscan: no data read"); | 191 warning ("textscan: no data read"); |
495 %! rh = tc{k}; | 504 %! rh = tc{k}; |
496 %! rh(rh == ";") = ""; | 505 %! rh(rh == ";") = ""; |
497 %! rh = strtrim (rh); | 506 %! rh = strtrim (rh); |
498 %! assert (strcmp (lh, rh)); | 507 %! assert (strcmp (lh, rh)); |
499 %! end | 508 %! end |
509 | |
510 %!error <missing or illegal value for> textread (file_in_loadpath ("textscan.m"), "", "headerlines") | |
511 %!error <missing or illegal value for> textread (file_in_loadpath ("textscan.m"), "", "headerlines", 'hh') | |
512 %!error <character value required for> textread (file_in_loadpath ("textscan.m"), "", "endofline", true) |