help-octave
[Top][All Lists]
Advanced

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

Re: Does save support append


From: David Bateman
Subject: Re: Does save support append
Date: Tue, 26 Jun 2007 22:59:02 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

John W. Eaton wrote:
> Please try the following patch.
> 
> It's best to report bugs to the address@hidden list.
> 
> Thanks,
> 
> jwe
> 

It should be possible to have hdf5 files append as well, I can't get it
to work, but the attached patch should be a step in the right direction.

You also can't have

      bool write_header_info = ! append;

As if you do then if the file doesn't exist, the header won't be written..

D.

*** ./src/load-save.cc.orig     2007-06-26 17:56:56.774304390 +0200
--- ./src/load-save.cc  2007-06-26 22:55:43.245718119 +0200
***************
*** 1418,1424 ****
  #ifdef HAVE_HDF5
        if (format == LS_HDF5)
        {
!         hdf5_ofstream file (fname);
  
          if (file.file_id >= 0)
            {
--- 1418,1424 ----
  #ifdef HAVE_HDF5
        if (format == LS_HDF5)
        {
!         hdf5_ofstream file (fname, mode);
  
          if (file.file_id >= 0)
            {
***************
*** 1688,1710 ****
          || format == LS_MAT7_BINARY)
        mode |= std::ios::binary;
  
-       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)
            {
              save_vars (argv, i, argc, hdf5_file, format,
!                        save_as_floats, true);
  
              hdf5_file.close ();
          }
--- 1688,1705 ----
          || format == LS_MAT7_BINARY)
        mode |= std::ios::binary;
  
  #ifdef HAVE_HDF5
        if (format == LS_HDF5)
        {
!         bool write_header_info = ! (append && 
!                                     H5Fis_hdf5 (fname.c_str ()) > 0);
  
!         hdf5_ofstream hdf5_file (fname.c_str (), mode);
  
!         if (hdf5_file.file_id != -1)
            {
              save_vars (argv, i, argc, hdf5_file, format,
!                        save_as_floats, write_header_info);
  
              hdf5_file.close ();
          }
***************
*** 1726,1731 ****
--- 1721,1728 ----
  
              if (file)
                {
+                 bool write_header_info = ! file.tellp ();
+ 
                  save_vars (argv, i, argc, file, format,
                             save_as_floats, write_header_info);
  
***************
*** 1744,1749 ****
--- 1741,1748 ----
          
              if (file)
                {
+                 bool write_header_info = ! file.tellp ();
+ 
                  save_vars (argv, i, argc, file, format,
                             save_as_floats, write_header_info);
  
*** ./src/ls-hdf5.h.orig        2007-06-26 17:58:47.930649492 +0200
--- ./src/ls-hdf5.h     2007-06-26 22:55:33.066242367 +0200
***************
*** 44,56 ****
  
    hdf5_fstreambase () { file_id = -1; }
  
    hdf5_fstreambase (const char *name, int mode, int /* prot */ = 0)
      {
        if (mode & std::ios::in)
        file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT);
        else if (mode & std::ios::out)
!       file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
! 
        if (file_id < 0)
        std::ios::setstate (std::ios::badbit);
  
--- 44,63 ----
  
    hdf5_fstreambase () { file_id = -1; }
  
+   ~hdf5_fstreambase () { close (); }
+ 
    hdf5_fstreambase (const char *name, int mode, int /* prot */ = 0)
      {
        if (mode & std::ios::in)
        file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT);
        else if (mode & std::ios::out)
!       {
!         if (mode & std::ios::app && H5Fis_hdf5 (name) > 0)
!           file_id = H5Fopen (name, H5F_ACC_RDWR, H5P_DEFAULT);
!         else
!           file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, 
!                                H5P_DEFAULT);
!       }
        if (file_id < 0)
        std::ios::setstate (std::ios::badbit);
  
***************
*** 74,81 ****
        if (mode & std::ios::in)
        file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT);
        else if (mode & std::ios::out)
!       file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
! 
        if (file_id < 0)
        std::ios::setstate (std::ios::badbit);
  
--- 81,93 ----
        if (mode & std::ios::in)
        file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT);
        else if (mode & std::ios::out)
!       {
!         if (mode & std::ios::app && H5Fis_hdf5 (name) > 0)
!           file_id = H5Fopen (name, H5F_ACC_RDWR, H5P_DEFAULT);
!         else
!           file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, 
!                                H5P_DEFAULT);
!       }
        if (file_id < 0)
        std::ios::setstate (std::ios::badbit);
  

reply via email to

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