changeset 10936:1d761a30c3fb

support file IDs in dlmwrite
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 01 Sep 2010 08:49:57 +0200
parents 3cb4889dd6f7
children f42e8c6196c3
files scripts/ChangeLog scripts/io/dlmwrite.m
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed Sep 01 08:43:23 2010 +0200
+++ b/scripts/ChangeLog	Wed Sep 01 08:49:57 2010 +0200
@@ -1,3 +1,7 @@
+2010-09-01  Jaroslav Hajek  <highegg@gmail.com>
+
+	* io/dlmwrite.m: Support file IDs.
+
 2010-07-07  David Bateman  <dbateman@free.fr>
 
 	* miscellaneous/what.m: Off by one error.
--- a/scripts/io/dlmwrite.m	Wed Sep 01 08:43:23 2010 +0200
+++ b/scripts/io/dlmwrite.m	Wed Sep 01 08:49:57 2010 +0200
@@ -23,6 +23,8 @@
 ## @deftypefnx {Function File} {} dlmwrite (@var{file}, @var{a}, "-append", @dots{})
 ## Write the matrix @var{a} to the named file using delimiters.
 ##
+## @var{file} should be a file name or writable file ID given by @code{fopen}.
+##
 ## The parameter @var{delim} specifies the delimiter to use to separate
 ## values on a row.
 ##
@@ -153,7 +155,15 @@
     endif
   endwhile
 
-  [fid, msg] = fopen (file, opentype);
+  if (ischar (file))
+    [fid, msg] = fopen (file, opentype);
+  elseif (isscalar (file) && isnumeric (file))
+    fid = file;
+    msg = "invalid file number";
+  else
+    error ("dlmwrite: file must be a string file ID");
+  endif
+
   if (fid < 0)
     error (msg);
   else