comparison src/load-save.cc @ 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 958713bc465e
comparison
equal deleted inserted replaced
6759:dd8cef76043d 6760:301885c9d265
1 /* 1 `</*
2 2
3 Copyright (C) 1996, 1997 John W. Eaton 3 Copyright (C) 1996, 1997 John W. Eaton
4 4
5 This file is part of Octave. 5 This file is part of Octave.
6 6
1416 mode |= append ? std::ios::ate : std::ios::trunc; 1416 mode |= append ? std::ios::ate : std::ios::trunc;
1417 1417
1418 #ifdef HAVE_HDF5 1418 #ifdef HAVE_HDF5
1419 if (format == LS_HDF5) 1419 if (format == LS_HDF5)
1420 { 1420 {
1421 hdf5_ofstream file (fname); 1421 hdf5_ofstream file (fname, mode);
1422 1422
1423 if (file.file_id >= 0) 1423 if (file.file_id >= 0)
1424 { 1424 {
1425 dump_octave_core (file, fname, format, save_as_floats); 1425 dump_octave_core (file, fname, format, save_as_floats);
1426 1426
1686 || format == LS_MAT_BINARY 1686 || format == LS_MAT_BINARY
1687 || format == LS_MAT5_BINARY 1687 || format == LS_MAT5_BINARY
1688 || format == LS_MAT7_BINARY) 1688 || format == LS_MAT7_BINARY)
1689 mode |= std::ios::binary; 1689 mode |= std::ios::binary;
1690 1690
1691 bool write_header_info = ! append;
1692
1693 #ifdef HAVE_HDF5 1691 #ifdef HAVE_HDF5
1694 if (format == LS_HDF5) 1692 if (format == LS_HDF5)
1695 { 1693 {
1694 // FIXME. It should be possible to append to HDF5 files.
1696 if (append) 1695 if (append)
1697 { 1696 {
1698 error ("save: appending to HDF5 files is not implemented"); 1697 error ("save: appending to HDF5 files is not implemented");
1699 return retval; 1698 return retval;
1700 } 1699 }
1701 1700
1702 hdf5_ofstream hdf5_file (fname.c_str ()); 1701 bool write_header_info = ! (append &&
1703 1702 H5Fis_hdf5 (fname.c_str ()) > 0);
1704 if (hdf5_file.file_id >= 0) 1703
1704 hdf5_ofstream hdf5_file (fname.c_str (), mode);
1705
1706 if (hdf5_file.file_id != -1)
1705 { 1707 {
1706 save_vars (argv, i, argc, hdf5_file, format, 1708 save_vars (argv, i, argc, hdf5_file, format,
1707 save_as_floats, true); 1709 save_as_floats, write_header_info);
1708 1710
1709 hdf5_file.close (); 1711 hdf5_file.close ();
1710 } 1712 }
1711 else 1713 else
1712 { 1714 {
1724 { 1726 {
1725 gzofstream file (fname.c_str (), mode); 1727 gzofstream file (fname.c_str (), mode);
1726 1728
1727 if (file) 1729 if (file)
1728 { 1730 {
1731 bool write_header_info = ! file.tellp ();
1732
1729 save_vars (argv, i, argc, file, format, 1733 save_vars (argv, i, argc, file, format,
1730 save_as_floats, write_header_info); 1734 save_as_floats, write_header_info);
1731 1735
1732 file.close (); 1736 file.close ();
1733 } 1737 }
1742 { 1746 {
1743 std::ofstream file (fname.c_str (), mode); 1747 std::ofstream file (fname.c_str (), mode);
1744 1748
1745 if (file) 1749 if (file)
1746 { 1750 {
1751 bool write_header_info = ! file.tellp ();
1752
1747 save_vars (argv, i, argc, file, format, 1753 save_vars (argv, i, argc, file, format,
1748 save_as_floats, write_header_info); 1754 save_as_floats, write_header_info);
1749 1755
1750 file.close (); 1756 file.close ();
1751 } 1757 }