comparison scripts/io/strread.m @ 11469:c776f063fefe

Overhaul m-script files to use common variable name between code and documentation.
author Rik <octave@nomad.inbox5.com>
date Sun, 09 Jan 2011 12:41:21 -0800
parents 5e5c513ea4c5
children 1740012184f9
comparison
equal deleted inserted replaced
11468:e1edf0ba3bcb 11469:c776f063fefe
97 ## @end table 97 ## @end table
98 ## 98 ##
99 ## @seealso{textread, load, dlmread, fscanf} 99 ## @seealso{textread, load, dlmread, fscanf}
100 ## @end deftypefn 100 ## @end deftypefn
101 101
102 function varargout = strread (str, formatstr = "%f", varargin) 102 function varargout = strread (str, format = "%f", varargin)
103 ## Check input 103 ## Check input
104 if (nargin < 1) 104 if (nargin < 1)
105 print_usage (); 105 print_usage ();
106 endif 106 endif
107 107
108 if (!ischar (str) || !ischar (formatstr)) 108 if (!ischar (str) || !ischar (format))
109 error ("strread: first and second input arguments must be strings"); 109 error ("strread: first and second input arguments must be strings");
110 endif 110 endif
111 111
112 ## Parse options 112 ## Parse options
113 comment_flag = false; 113 comment_flag = false;
148 if (isempty (delimiter_str)) 148 if (isempty (delimiter_str))
149 delimiter_str = white_spaces; 149 delimiter_str = white_spaces;
150 endif 150 endif
151 151
152 ## Parse format string 152 ## Parse format string
153 idx = strfind (formatstr, "%")'; 153 idx = strfind (format, "%")';
154 specif = formatstr ([idx, idx+1]); 154 specif = format ([idx, idx+1]);
155 nspecif = length (idx); 155 nspecif = length (idx);
156 idx_star = strfind (formatstr, "%*"); 156 idx_star = strfind (format, "%*");
157 nfields = length (idx) - length (idx_star); 157 nfields = length (idx) - length (idx_star);
158 158
159 if (max (nargout, 1) != nfields) 159 if (max (nargout, 1) != nfields)
160 error ("strread: the number of output variables must match that of format specifiers"); 160 error ("strread: the number of output variables must match that of format specifiers");
161 endif 161 endif
185 str = cellslices (str, [1, cstop + c2len], [cstart - 1, len]); 185 str = cellslices (str, [1, cstop + c2len], [cstart - 1, len]);
186 str = [str{:}]; 186 str = [str{:}];
187 endif 187 endif
188 188
189 ## Determine the number of words per line 189 ## Determine the number of words per line
190 formatstr = strrep (formatstr, "%", " %"); 190 format = strrep (format, "%", " %");
191 [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+"); 191 [~, ~, ~, fmt_words] = regexp (format, "[^\\s]+");
192 192
193 num_words_per_line = numel (fmt_words); 193 num_words_per_line = numel (fmt_words);
194 for m = 1:numel(fmt_words) 194 for m = 1:numel(fmt_words)
195 ## Convert formats such as "%Ns" to "%s" (see the FIXME below) 195 ## Convert formats such as "%Ns" to "%s" (see the FIXME below)
196 if (length (fmt_words{m}) > 2) 196 if (length (fmt_words{m}) > 2)