help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does save support append


From: John W. Eaton
Subject: Does save support append
Date: Tue, 26 Jun 2007 11:31:01 -0400

On 25-Jun-2007, Kristjan Onu wrote:

| Hi,
| 
| I am seeking clarification regarding whether the save command supports
| the append option.
| 
| The file NEWS.2 states:
| 
|   * The save command now accepts the option -append to save the
|     variables at the end of the file, leaving the existing contents.
| 
| When I run the attached test file however, the error 'x not found' is
| triggered.
| 
| I have tried this using Debian's Octave2.9.9-8etch1 as well as the
| CVS version updated a couple of hours ago.
| 
| Best,
| 
| K
| function append_test
| 
| x = 1;
| save("at_file","x")
| 
| y = 2;
| 
| save("-append","at_file","y")
| 
| clear
| 
| load("at_file")
| 
| if ~exist("y")
|   error("y not found")
| end
| 
| if ~exist("x")
|   error("x not found")
| end

Please try the following patch.

It's best to report bugs to the address@hidden list.

Thanks,

jwe


src/ChangeLog:

2007-06-26  John W. Eaton  <address@hidden>

        * src/load-save.cc (Fsave): Open files correctly for -append.
        Don't write file headers if appending.  Error for -append -hdf5.


Index: src/load-save.cc
===================================================================
RCS file: /cvs/octave/src/load-save.cc,v
retrieving revision 1.224
diff -u -u -r1.224 load-save.cc
--- src/load-save.cc    22 May 2007 15:36:10 -0000      1.224
+++ src/load-save.cc    26 Jun 2007 15:30:36 -0000
@@ -1648,6 +1648,9 @@
        // don't insert any commands here!  the brace below must go
        // with the "else" above!
        {
+         if (append)
+           warning ("save: ignoring -append option for output to stdout");
+
          // FIXME -- should things intended for the screen end up
          // in a octave_value (string)?
          
@@ -1669,12 +1672,13 @@
 
       i++;
 
-      std::ios::openmode mode = std::ios::out;
-
       // Matlab v7 files are always compressed
       if (format == LS_MAT7_BINARY)
        use_zlib = false;
 
+      std::ios::openmode mode
+       = append ? (std::ios::app | std::ios::ate) : std::ios::out;
+
       if (format == LS_BINARY
 #ifdef HAVE_HDF5
          || format == LS_HDF5
@@ -1684,11 +1688,17 @@
          || format == LS_MAT7_BINARY)
        mode |= std::ios::binary;
 
-      mode |= append ? std::ios::ate : std::ios::trunc;
-
+      bool write_header_info = ! append;
+             
 #ifdef HAVE_HDF5
       if (format == LS_HDF5)
        {
+         if (append)
+           {
+             error ("save: appending to HDF5 files is not implemented");
+             return retval;
+           }
+
          hdf5_ofstream hdf5_file (fname.c_str ());
 
          if (hdf5_file.file_id >= 0)
@@ -1716,8 +1726,6 @@
 
              if (file)
                {
-                 bool write_header_info = ! file.tellp ();
-             
                  save_vars (argv, i, argc, file, format,
                             save_as_floats, write_header_info);
 
@@ -1736,8 +1744,6 @@
          
              if (file)
                {
-                 bool write_header_info = ! file.tellp ();
-             
                  save_vars (argv, i, argc, file, format,
                             save_as_floats, write_header_info);
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]