Mercurial > hg > octave-avbm
changeset 6760:301885c9d265
[project @ 2007-06-27 02:27:51 by dbateman]
author | dbateman |
---|---|
date | Wed, 27 Jun 2007 02:27:51 +0000 |
parents | dd8cef76043d |
children | 813172f035de |
files | src/ChangeLog src/load-save.cc src/ls-hdf5.h |
diffstat | 3 files changed, 35 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2007-06-27 David Bateman <dbateman@free.fr> + + * src/load-save.cc (Fsave): Ensure header is written for non + existent file with "-append". + * src/ls-hdf5.h: First steps towards having append work for hdf5. + 2007-06-26 John W. Eaton <jwe@octave.org> * src/load-save.cc (Fsave): Open files correctly for -append.
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -1,4 +1,4 @@ -/* +`</* Copyright (C) 1996, 1997 John W. Eaton @@ -1418,7 +1418,7 @@ #ifdef HAVE_HDF5 if (format == LS_HDF5) { - hdf5_ofstream file (fname); + hdf5_ofstream file (fname, mode); if (file.file_id >= 0) { @@ -1688,23 +1688,25 @@ || format == LS_MAT7_BINARY) mode |= std::ios::binary; - bool write_header_info = ! append; - #ifdef HAVE_HDF5 if (format == LS_HDF5) { + // FIXME. It should be possible to append to HDF5 files. if (append) { error ("save: appending to HDF5 files is not implemented"); return retval; } - hdf5_ofstream hdf5_file (fname.c_str ()); + bool write_header_info = ! (append && + H5Fis_hdf5 (fname.c_str ()) > 0); - if (hdf5_file.file_id >= 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, true); + save_as_floats, write_header_info); hdf5_file.close (); } @@ -1726,6 +1728,8 @@ if (file) { + bool write_header_info = ! file.tellp (); + save_vars (argv, i, argc, file, format, save_as_floats, write_header_info); @@ -1744,6 +1748,8 @@ if (file) { + bool write_header_info = ! file.tellp (); + save_vars (argv, i, argc, file, format, save_as_floats, write_header_info);
--- a/src/ls-hdf5.h +++ b/src/ls-hdf5.h @@ -44,13 +44,20 @@ 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) - file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - + { + 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,8 +81,13 @@ 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 (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);