diff scripts/io/textread.m @ 20038:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children e51473fdb622
line wrap: on
line diff
--- a/scripts/io/textread.m
+++ b/scripts/io/textread.m
@@ -118,7 +118,8 @@
       error ("character value required for EndOfLine");
     endif
   else
-    ## Determine EOL from file.  Search for EOL candidates in first BUFLENGTH chars
+    ## Determine EOL from file.
+    ## Search for EOL candidates in the first BUFLENGTH chars
     eol_srch_len = min (length (str), BUFLENGTH);
     ## First try DOS (CRLF)
     if (! isempty (strfind (str(1 : eol_srch_len), "\r\n")))
@@ -158,7 +159,7 @@
     endwhile
     ## Found EOL delimiting last requested line. Compute ptr (incl. EOL)
     if (isempty (eoi))
-      printf ("textread: format repeat count specified but no endofline found\n");
+      disp ("textread: format repeat count specified but no endofline found");
       eoi_pos = nblks * BUFLENGTH + count;
     else
       eoi_pos = (nblks * BUFLENGTH) + eoi(end + min (nlines, n_eoi) - n_eoi);
@@ -177,7 +178,7 @@
   endif
 
   ## Call strread to make it do the real work
-  [varargout{1:max (nargout, 1)}] = strread (str, format, varargin {:});
+  [varargout{1:max (nargout, 1)}] = strread (str, format, varargin{:});
 
   ## Hack to concatenate/reshape numeric output into 2D array (undocumented ML)
   ## In ML this only works in case of an empty format string
@@ -202,7 +203,7 @@
       ncols = numel (strfind (str, " ")) + 1;
     else
       ## 3B. Just count delimiters. FIXME: delimiters could occur in literals
-      delimiter = varargin {idelimiter+1};
+      delimiter = varargin{idelimiter+1};
       ncols = numel (regexp (str, sprintf ("[%s]", delimiter))) + 1;
     endif
     ## 6. Reshape; watch out, we need a transpose
@@ -238,7 +239,7 @@
 %! unlink (f);
 %! assert (a, d(2:7, 1), 1e-2);
 
-%% Test reading 2D matrix with empty format
+## Test reading 2D matrix with empty format
 %!test
 %! f = tempname ();
 %! d = rand (5, 2);
@@ -247,7 +248,7 @@
 %! unlink (f);
 %! assert (A, d(4:5, :), 1e-2);
 
-%% Read multiple lines using empty format string
+## Read multiple lines using empty format string
 %!test
 %! f = tempname ();
 %! unlink (f);
@@ -259,7 +260,7 @@
 %! unlink (f);
 %! assert (A, d, 1e-6);
 
-%% Empty format, corner case = one line w/o EOL
+## Empty format, corner case = one line w/o EOL
 %!test
 %! f = tempname ();
 %! unlink (f);
@@ -271,7 +272,7 @@
 %! unlink (f);
 %! assert (A, d, 1e-6);
 
-%% Read multiple lines using empty format string, missing data (should be 0)
+## Read multiple lines using empty format string, missing data (should be 0)
 %!test
 %! f = tempname ();
 %! unlink (f);
@@ -283,7 +284,7 @@
 %! unlink (f);
 %! assert (A, [ d(1:2) 0 d(3:4)], 1e-6);
 
-%% Test with empty positions - ML returns 0 for empty fields
+## Test with empty positions - ML returns 0 for empty fields
 %!test
 %! f = tempname ();
 %! unlink (f);
@@ -295,8 +296,8 @@
 %! unlink (f);
 %! assert (A, [0 2 0 4; 5 0 7 0], 1e-6);
 
-%% Another test with empty format + positions, now with more incomplete lower
-%% row (must be appended with zeros to get rectangular matrix)
+## Another test with empty format + positions, now with more incomplete lower
+## row (must be appended with zeros to get rectangular matrix)
 %!test
 %! f = tempname ();
 %! unlink (f);
@@ -308,7 +309,7 @@
 %! unlink (f);
 %! assert (A, [0 2 0 4; 5 0 0 0], 1e-6);
 
-%% Test input validation
+## Test input validation
 %!error textread ()
 %!error textread (1)
 %!error <arguments must be strings> textread (1, "%f")