# HG changeset patch # User Jaroslav Hajek # Date 1283323403 -7200 # Node ID 3cb4889dd6f7a7fd4eed61ebe3050a8d83f82801 # Parent f6294203286e10f53a39a0a9550c795c5bcd2ea7 support specific empty value in dlmread diff -r f6294203286e -r 3cb4889dd6f7 src/ChangeLog --- a/src/ChangeLog Tue Aug 31 23:27:18 2010 +0200 +++ b/src/ChangeLog Wed Sep 01 08:43:23 2010 +0200 @@ -1,3 +1,8 @@ +2010-09-01 Jaroslav Hajek + + * DLD-FUNCTIONS/dlmread.cc (Fdlmread): Support "emptyvalue" option. + Fix condition for terminating read. + 2010-08-31 Jaroslav Hajek * DLD-FUNCTIONS/dlmread.cc (Fdlmread): Support reading from a file ID. diff -r f6294203286e -r 3cb4889dd6f7 src/DLD-FUNCTIONS/dlmread.cc --- a/src/DLD-FUNCTIONS/dlmread.cc Tue Aug 31 23:27:18 2010 +0200 +++ b/src/DLD-FUNCTIONS/dlmread.cc Wed Sep 01 08:43:23 2010 +0200 @@ -161,6 +161,7 @@ @deftypefnx {Loadable Function} {@var{data} =} dlmread (@var{file}, @var{sep})\n\ @deftypefnx {Loadable Function} {@var{data} =} dlmread (@var{file}, @var{sep}, @var{r0}, @var{c0})\n\ @deftypefnx {Loadable Function} {@var{data} =} dlmread (@var{file}, @var{sep}, @var{range})\n\ +@deftypefnx {Loadable Function} {@var{data} =} dlmread (@dots{}, \"emptyvalue\", @var{EMPTYVAL})\n\ Read the matrix @var{data} from a text file. If not defined the separator\n\ between fields is determined from the file itself. Otherwise the\n\ separation character is defined by @var{sep}.\n\ @@ -177,6 +178,9 @@ \n\ @var{file} should be a file name or file id given by @code{fopen}. In the\n\ latter case, the file is read until end of file is reached.\n\ +\n\ +The \"emptyvalue\" option may be used to specify the value used to fill empty\n\ +fields. Default is zero.\n\ @seealso{csvread,dlmwrite,fopen}\n\ @end deftypefn") { @@ -184,6 +188,17 @@ int nargin = args.length (); + double empty_value = 0.0; + + if (nargin > 2 && args(nargin-2).is_string () + && args(nargin-2).string_value () == "emptyvalue") + { + empty_value = args(nargin-1).double_value (); + if (error_state) + return retval; + nargin -= 2; + } + if (nargin < 1 || nargin > 4) { print_usage (); @@ -276,8 +291,6 @@ bool iscmplx = false; bool sepflag = false; - octave_idx_type maxrows = r1 - r0; - std::string line; // Skip the r0 leading lines as these might be a header. @@ -424,9 +437,9 @@ } } else if (iscmplx) - cdata(i,j++) = 0.; + cdata(i,j++) = empty_value; else - rdata(i,j++) = 0.; + rdata(i,j++) = empty_value; if (pos2 != std::string::npos) pos1 = pos2 + 1; @@ -436,7 +449,7 @@ } while (pos1 != std::string::npos); - if (nargin == 3 && i == maxrows) + if (i == r1) break; i++;