Mercurial > octave-nkf
comparison scripts/io/textread.m @ 19630:0e1f5a750d00
maint: Periodic merge of gui-release to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 10:24:46 -0500 |
parents | 6ca096827123 446c46af4b42 |
children | 4197fc428c7d |
comparison
equal
deleted
inserted
replaced
19626:37d37297acf8 | 19630:0e1f5a750d00 |
---|---|
131 eol_char = "\n"; | 131 eol_char = "\n"; |
132 endif | 132 endif |
133 ## Set up default endofline param value | 133 ## Set up default endofline param value |
134 varargin(end+1:end+2) = {"endofline", eol_char}; | 134 varargin(end+1:end+2) = {"endofline", eol_char}; |
135 endif | 135 endif |
136 | 136 |
137 ## Now that we know what EOL looks like, we can process format_repeat_count. | 137 ## Now that we know what EOL looks like, we can process format_repeat_count. |
138 ## FIXME: The below isn't ML-compatible: counts lines, not format string uses | 138 ## FIXME: The below isn't ML-compatible: counts lines, not format string uses |
139 if (isfinite (nlines) && (nlines > 0)) | 139 if (isfinite (nlines) && (nlines > 0)) |
140 l_eol_char = length (eol_char); | 140 l_eol_char = length (eol_char); |
141 eoi = findstr (str, eol_char); | 141 eoi = findstr (str, eol_char); |
168 else | 168 else |
169 fseek (fid, st_pos, "bof"); | 169 fseek (fid, st_pos, "bof"); |
170 str = fread (fid, "char=>char").'; | 170 str = fread (fid, "char=>char").'; |
171 endif | 171 endif |
172 fclose (fid); | 172 fclose (fid); |
173 | 173 |
174 ## Set up default whitespace param value if needed | 174 ## Set up default whitespace param value if needed |
175 if (isempty (find (strcmpi ("whitespace", varargin)))) | 175 if (isempty (find (strcmpi ("whitespace", varargin)))) |
176 varargin(end+1:end+2) = {"whitespace", " \b\t"}; | 176 varargin(end+1:end+2) = {"whitespace", " \b\t"}; |
177 endif | 177 endif |
178 | 178 |
180 [varargout{1:max (nargout, 1)}] = strread (str, format, varargin {:}); | 180 [varargout{1:max (nargout, 1)}] = strread (str, format, varargin {:}); |
181 | 181 |
182 ## Hack to concatenate/reshape numeric output into 2D array (undocumented ML) | 182 ## Hack to concatenate/reshape numeric output into 2D array (undocumented ML) |
183 ## In ML this only works in case of an empty format string | 183 ## In ML this only works in case of an empty format string |
184 if (isempty (format)) | 184 if (isempty (format)) |
185 ## Get number of fields per line. | 185 ## Get number of fields per line. |
186 ## 1. Get eol_char position | 186 ## 1. Get eol_char position |
187 iwhsp = find (strcmpi ("whitespace", varargin)); | 187 iwhsp = find (strcmpi ("whitespace", varargin)); |
188 whsp = varargin{iwhsp + 1}; | 188 whsp = varargin{iwhsp + 1}; |
189 idx = regexp (str, eol_char, "once"); | 189 idx = regexp (str, eol_char, "once"); |
190 ## 2. Get first data line til EOL. Avoid corner case of just one line | 190 ## 2. Get first data line til EOL. Avoid corner case of just one line |