diff --git a/libinterp/corefcn/ls-hdf5.cc b/libinterp/corefcn/ls-hdf5.cc --- a/libinterp/corefcn/ls-hdf5.cc +++ b/libinterp/corefcn/ls-hdf5.cc @@ -55,6 +55,7 @@ along with Octave; see the file COPYING. #include "error.h" #include "gripes.h" #include "load-save.h" +#include "oct-hdf5-id.h" #include "oct-obj.h" #include "oct-map.h" #include "ov-cell.h" @@ -587,6 +588,8 @@ read_hdf5_data (std::istream& is, const bool& global, octave_value& tc, std::string& doc, const string_vector& argv, int argv_idx, int argc) { + check_hdf5_id_type (); + std::string retval; doc.resize (0); @@ -952,6 +955,8 @@ save_hdf5_data (std::ostream& os, const const std::string& name, const std::string& doc, bool mark_as_global, bool save_as_floats) { + check_hdf5_id_type (); + hdf5_ofstream& hs = dynamic_cast (os); return add_hdf5_data (hs.file_id, tc, name, doc, diff --git a/libinterp/corefcn/module.mk b/libinterp/corefcn/module.mk --- a/libinterp/corefcn/module.mk +++ b/libinterp/corefcn/module.mk @@ -82,6 +82,7 @@ COREFCN_INC = \ corefcn/oct-fstrm.h \ corefcn/oct-handle.h \ corefcn/oct-hdf5.h \ + corefcn/oct-hdf5-id.h \ corefcn/oct-hist.h \ corefcn/oct-iostrm.h \ corefcn/oct-lvalue.h \ @@ -212,6 +213,7 @@ COREFCN_SRC = \ corefcn/mgorth.cc \ corefcn/nproc.cc \ corefcn/oct-fstrm.cc \ + corefcn/oct-hdf5-id.cc \ corefcn/oct-hist.cc \ corefcn/oct-iostrm.cc \ corefcn/oct-lvalue.cc \ diff --git a/libinterp/corefcn/oct-hdf5.h b/libinterp/corefcn/oct-hdf5.h --- a/libinterp/corefcn/oct-hdf5.h +++ b/libinterp/corefcn/oct-hdf5.h @@ -24,7 +24,11 @@ along with Octave; see the file COPYING. #define octave_hdf5_h 1 #if defined (HAVE_HDF5_H) + #include + +#define HDF5_SAVE_TYPE H5T_NATIVE_UINT8 + #endif #endif diff --git a/libinterp/octave-value/ov-base-int.cc b/libinterp/octave-value/ov-base-int.cc --- a/libinterp/octave-value/ov-base-int.cc +++ b/libinterp/octave-value/ov-base-int.cc @@ -38,6 +38,7 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ops.h" #include "ov-base.h" @@ -333,14 +334,15 @@ octave_base_int_matrix::load_binary ( return true; } +template +bool +octave_base_int_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool) +{ + bool retval = true; + #if defined (HAVE_HDF5) -template -bool -octave_base_int_matrix::save_hdf5 (hid_t loc_id, const char *name, bool) -{ hid_t save_type_hid = HDF5_SAVE_TYPE; - bool retval = true; dim_vector dv = this->dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -377,15 +379,22 @@ octave_base_int_matrix::save_hdf5 (hi H5Dclose (data_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } template bool -octave_base_int_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_base_int_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { + bool retval = false; + +#if defined (HAVE_HDF5) + hid_t save_type_hid = HDF5_SAVE_TYPE; - bool retval = false; dim_vector dv; int empty = load_hdf5_empty (loc_id, name, dv); if (empty > 0) @@ -439,11 +448,13 @@ octave_base_int_matrix::load_hdf5 (hi H5Sclose (space_id); H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - template void octave_base_int_matrix::print_raw (std::ostream& os, @@ -546,7 +557,7 @@ octave_base_int_scalar::load_binary ( template bool -octave_base_int_scalar::save_hdf5 (hid_t loc_id, const char *name, bool) +octave_base_int_scalar::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool) { hid_t save_type_hid = HDF5_SAVE_TYPE; bool retval = true; @@ -581,7 +592,7 @@ octave_base_int_scalar::save_hdf5 (hi template bool -octave_base_int_scalar::load_hdf5 (hid_t loc_id, const char *name) +octave_base_int_scalar::load_hdf5 (octave_hdf5_id loc_id, const char *name) { hid_t save_type_hid = HDF5_SAVE_TYPE; #if HAVE_HDF5_18 diff --git a/libinterp/octave-value/ov-base-int.h b/libinterp/octave-value/ov-base-int.h --- a/libinterp/octave-value/ov-base-int.h +++ b/libinterp/octave-value/ov-base-int.h @@ -78,11 +78,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); }; // base int scalar values. @@ -124,9 +122,9 @@ public: oct_mach_info::float_format); #if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool); - bool load_hdf5 (hid_t loc_id, const char *name); + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); #endif }; diff --git a/libinterp/octave-value/ov-base.cc b/libinterp/octave-value/ov-base.cc --- a/libinterp/octave-value/ov-base.cc +++ b/libinterp/octave-value/ov-base.cc @@ -36,6 +36,7 @@ along with Octave; see the file COPYING. #include "mxarray.h" #include "oct-map.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "oct-lvalue.h" #include "oct-stream.h" #include "ops.h" @@ -1257,6 +1258,24 @@ octave_base_value::get_umap_name (unary_ return names[umap]; } +void +octave_base_value::gripe_load (const char *type) const +{ + warning_with_id + ("Octave:load-save-unavailable", + "%s: loading %s files not available in this version of Octave", + t_name.c_str (), type); +} + +void +octave_base_value::gripe_save (const char *type) const +{ + warning_with_id + ("Octave:load-save-unavailable", + "%s: saving %s files not available in this version of Octave", + t_name.c_str (), type); +} + octave_value octave_base_value::map (unary_mapper_t umap) const { diff --git a/libinterp/octave-value/ov-base.h b/libinterp/octave-value/ov-base.h --- a/libinterp/octave-value/ov-base.h +++ b/libinterp/octave-value/ov-base.h @@ -36,7 +36,7 @@ along with Octave; see the file COPYING. #include "str-vec.h" #include "error.h" -#include "oct-hdf5.h" +#include "oct-hdf5-id.h" class Cell; class mxArray; @@ -636,13 +636,11 @@ public: virtual bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) virtual bool - save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); virtual bool - load_hdf5 (hid_t loc_id, const char *name); -#endif + load_hdf5 (octave_hdf5_id loc_id, const char *name); virtual int write (octave_stream& os, int block_size, @@ -821,6 +819,9 @@ protected: static const char *get_umap_name (unary_mapper_t); + void gripe_load (const char *type) const; + void gripe_save (const char *type) const; + private: static int curr_print_indent_level; diff --git a/libinterp/octave-value/ov-bool-mat.cc b/libinterp/octave-value/ov-bool-mat.cc --- a/libinterp/octave-value/ov-bool-mat.cc +++ b/libinterp/octave-value/ov-bool-mat.cc @@ -36,6 +36,7 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "mxarray.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" #include "ov-base-mat.h" @@ -408,12 +409,14 @@ octave_bool_matrix::load_binary (std::is return true; } +bool +octave_bool_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool /* save_as_floats */) +{ + bool retval = true; + #if defined (HAVE_HDF5) -bool -octave_bool_matrix::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -422,7 +425,6 @@ octave_bool_matrix::save_hdf5 (hid_t loc int rank = dv.length (); hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; boolNDArray m = bool_array_value (); OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); @@ -459,14 +461,20 @@ octave_bool_matrix::save_hdf5 (hid_t loc H5Dclose (data_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_bool_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_bool_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + dim_vector dv; int empty = load_hdf5_empty (loc_id, name, dv); if (empty > 0) @@ -524,11 +532,13 @@ octave_bool_matrix::load_hdf5 (hid_t loc H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_bool_matrix::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-bool-mat.h b/libinterp/octave-value/ov-bool-mat.h --- a/libinterp/octave-value/ov-bool-mat.h +++ b/libinterp/octave-value/ov-bool-mat.h @@ -205,11 +205,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-bool-sparse.cc b/libinterp/octave-value/ov-bool-sparse.cc --- a/libinterp/octave-value/ov-bool-sparse.cc +++ b/libinterp/octave-value/ov-bool-sparse.cc @@ -40,6 +40,8 @@ along with Octave; see the file COPYING. #include "ops.h" #include "oct-locbuf.h" +#include "oct-hdf5.h" + #include "ov-re-sparse.h" #include "ov-cx-sparse.h" #include "ov-bool-sparse.h" @@ -336,11 +338,13 @@ octave_sparse_bool_matrix::load_binary ( return true; } +bool +octave_sparse_bool_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_sparse_bool_matrix::save_hdf5 (hid_t loc_id, const char *name, bool) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -359,7 +363,6 @@ octave_sparse_bool_matrix::save_hdf5 (hi hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; SparseBoolMatrix m = sparse_bool_matrix_value (); octave_idx_type tmp; hsize_t hdims[2]; @@ -545,12 +548,20 @@ octave_sparse_bool_matrix::save_hdf5 (hi H5Sclose (space_hid); H5Gclose (group_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_sparse_bool_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_sparse_bool_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { + bool retval = false; + +#if defined (HAVE_HDF5) + octave_idx_type nr, nc, nz; hid_t group_hid, data_hid, space_hid; hsize_t rank; @@ -759,7 +770,7 @@ octave_sparse_bool_matrix::load_hdf5 (hi } OCTAVE_LOCAL_BUFFER (hbool_t, htmp, nz); - bool retval = false; + if (H5Dread (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, H5P_DEFAULT, htmp) >= 0 && m.indices_ok ()) @@ -776,11 +787,13 @@ octave_sparse_bool_matrix::load_hdf5 (hi H5Dclose (data_hid); H5Gclose (group_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_sparse_bool_matrix::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-bool-sparse.h b/libinterp/octave-value/ov-bool-sparse.h --- a/libinterp/octave-value/ov-bool-sparse.h +++ b/libinterp/octave-value/ov-bool-sparse.h @@ -135,11 +135,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); mxArray *as_mxArray (void) const; diff --git a/libinterp/octave-value/ov-bool.cc b/libinterp/octave-value/ov-bool.cc --- a/libinterp/octave-value/ov-bool.cc +++ b/libinterp/octave-value/ov-bool.cc @@ -30,6 +30,7 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "mxarray.h" +#include "oct-hdf5.h" #include "oct-obj.h" #include "ops.h" #include "ov-bool.h" @@ -157,16 +158,17 @@ octave_bool::load_binary (std::istream& return true; } +bool +octave_bool::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool /* save_as_floats */) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_bool::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) -{ hsize_t dimens[3]; hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; space_hid = H5Screate_simple (0, dimens, 0); if (space_hid < 0) return false; @@ -190,12 +192,18 @@ octave_bool::save_hdf5 (hid_t loc_id, co H5Dclose (data_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_bool::load_hdf5 (hid_t loc_id, const char *name) +octave_bool::load_hdf5 (octave_hdf5_id loc_id, const char *name) { +#if defined (HAVE_HDF5) + #if HAVE_HDF5_18 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); #else @@ -223,11 +231,13 @@ octave_bool::load_hdf5 (hid_t loc_id, co H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return true; } -#endif - mxArray * octave_bool::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-bool.h b/libinterp/octave-value/ov-bool.h --- a/libinterp/octave-value/ov-bool.h +++ b/libinterp/octave-value/ov-bool.h @@ -218,11 +218,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-cell.cc b/libinterp/octave-value/ov-cell.cc --- a/libinterp/octave-value/ov-cell.cc +++ b/libinterp/octave-value/ov-cell.cc @@ -42,6 +42,7 @@ along with Octave; see the file COPYING. #include "mxarray.h" #include "ov-cell.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "unwind-prot.h" #include "utils.h" #include "ov-base-mat.h" @@ -1065,11 +1066,11 @@ octave_cell::mex_get_data (void) const return matrix.mex_get_data (); } +bool +octave_cell::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) +{ #if defined (HAVE_HDF5) -bool -octave_cell::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -1156,15 +1157,22 @@ octave_cell::save_hdf5 (hid_t loc_id, co H5Gclose (data_hid); return true; + +#else + gripe_save ("hdf5"); + return false; +#endif } bool -octave_cell::load_hdf5 (hid_t loc_id, const char *name) +octave_cell::load_hdf5 (octave_hdf5_id loc_id, const char *name) { + bool retval = false; + +#if defined (HAVE_HDF5) + clear_cellstr_cache (); - bool retval = false; - dim_vector dv; int empty = load_hdf5_empty (loc_id, name, dv); if (empty > 0) @@ -1260,11 +1268,13 @@ octave_cell::load_hdf5 (hid_t loc_id, co retval = true; } +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - DEFUN (iscell, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} iscell (@var{x})\n\ diff --git a/libinterp/octave-value/ov-cell.h b/libinterp/octave-value/ov-cell.h --- a/libinterp/octave-value/ov-cell.h +++ b/libinterp/octave-value/ov-cell.h @@ -161,11 +161,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); octave_value map (unary_mapper_t umap) const; diff --git a/libinterp/octave-value/ov-class.cc b/libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc +++ b/libinterp/octave-value/ov-class.cc @@ -44,6 +44,7 @@ along with Octave; see the file COPYING. #include "ls-utils.h" #include "mxarray.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ov-class.h" #ifdef HAVE_JAVA #include "ov-java.h" @@ -1505,11 +1506,11 @@ octave_class::load_binary (std::istream& return success; } +bool +octave_class::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) +{ #if defined (HAVE_HDF5) -bool -octave_class::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) -{ hsize_t hdims[3]; hid_t group_hid = -1; hid_t type_hid = -1; @@ -1601,13 +1602,20 @@ error_cleanup: H5Gclose (group_hid); return true; + +#else + gripe_save ("hdf5"); + return false; +#endif } bool -octave_class::load_hdf5 (hid_t loc_id, const char *name) +octave_class::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + hid_t group_hid = -1; hid_t data_hid = -1; hid_t type_hid = -1; @@ -1741,11 +1749,13 @@ error_cleanup: if (data_hid > 0) H5Gclose (group_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_class::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-class.h b/libinterp/octave-value/ov-class.h --- a/libinterp/octave-value/ov-class.h +++ b/libinterp/octave-value/ov-class.h @@ -194,11 +194,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); mxArray *as_mxArray (void) const; diff --git a/libinterp/octave-value/ov-complex.cc b/libinterp/octave-value/ov-complex.cc --- a/libinterp/octave-value/ov-complex.cc +++ b/libinterp/octave-value/ov-complex.cc @@ -32,6 +32,7 @@ along with Octave; see the file COPYING. #include "mxarray.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ops.h" #include "ov-complex.h" @@ -307,16 +308,17 @@ octave_complex::load_binary (std::istrea return true; } +bool +octave_complex::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool /* save_as_floats */) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_complex::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) -{ hsize_t dimens[3]; hid_t space_hid, type_hid, data_hid; space_hid = type_hid = data_hid = -1; - bool retval = true; space_hid = H5Screate_simple (0, dimens, 0); if (space_hid < 0) @@ -349,13 +351,20 @@ octave_complex::save_hdf5 (hid_t loc_id, H5Tclose (type_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_complex::load_hdf5 (hid_t loc_id, const char *name) +octave_complex::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; + +#if defined (HAVE_HDF5) + #if HAVE_HDF5_18 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); #else @@ -396,11 +405,13 @@ octave_complex::load_hdf5 (hid_t loc_id, H5Sclose (space_id); H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_complex::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-complex.h b/libinterp/octave-value/ov-complex.h --- a/libinterp/octave-value/ov-complex.h +++ b/libinterp/octave-value/ov-complex.h @@ -176,11 +176,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-cx-mat.cc b/libinterp/octave-value/ov-cx-mat.cc --- a/libinterp/octave-value/ov-cx-mat.cc +++ b/libinterp/octave-value/ov-cx-mat.cc @@ -39,6 +39,7 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "mxarray.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ops.h" #include "ov-base.h" @@ -562,12 +563,12 @@ octave_complex_matrix::load_binary (std: return true; } +bool +octave_complex_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool save_as_floats) +{ #if defined (HAVE_HDF5) -bool -octave_complex_matrix::save_hdf5 (hid_t loc_id, const char *name, - bool save_as_floats) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -651,13 +652,20 @@ octave_complex_matrix::save_hdf5 (hid_t H5Sclose (space_hid); return retval; + +#else + gripe_save ("hdf5"); + return false; +#endif } bool -octave_complex_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_complex_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + dim_vector dv; int empty = load_hdf5_empty (loc_id, name, dv); if (empty > 0) @@ -725,11 +733,13 @@ octave_complex_matrix::load_hdf5 (hid_t H5Sclose (space_id); H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - void octave_complex_matrix::print_raw (std::ostream& os, bool pr_as_read_syntax) const diff --git a/libinterp/octave-value/ov-cx-mat.h b/libinterp/octave-value/ov-cx-mat.h --- a/libinterp/octave-value/ov-cx-mat.h +++ b/libinterp/octave-value/ov-cx-mat.h @@ -155,11 +155,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-cx-sparse.cc b/libinterp/octave-value/ov-cx-sparse.cc --- a/libinterp/octave-value/ov-cx-sparse.cc +++ b/libinterp/octave-value/ov-cx-sparse.cc @@ -39,6 +39,8 @@ along with Octave; see the file COPYING. #include "ov-complex.h" #include "gripes.h" +#include "oct-hdf5.h" + #include "ov-re-sparse.h" #include "ov-cx-sparse.h" @@ -366,12 +368,14 @@ octave_sparse_complex_matrix::load_binar return true; } +bool +octave_sparse_complex_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool save_as_floats) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_sparse_complex_matrix::save_hdf5 (hid_t loc_id, const char *name, - bool save_as_floats) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -391,7 +395,6 @@ octave_sparse_complex_matrix::save_hdf5 hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; SparseComplexMatrix m = sparse_complex_matrix_value (); octave_idx_type tmp; hsize_t hdims[2]; @@ -614,12 +617,20 @@ octave_sparse_complex_matrix::save_hdf5 H5Tclose (type_hid); H5Gclose (group_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_sparse_complex_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_sparse_complex_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { + bool retval = false; + +#if defined (HAVE_HDF5) + octave_idx_type nr, nc, nz; hid_t group_hid, data_hid, space_hid; hsize_t rank; @@ -840,7 +851,7 @@ octave_sparse_complex_matrix::load_hdf5 } Complex *ctmp = m.xdata (); - bool retval = false; + if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, ctmp) >= 0 && m.indices_ok ()) @@ -854,11 +865,13 @@ octave_sparse_complex_matrix::load_hdf5 H5Dclose (data_hid); H5Gclose (group_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_sparse_complex_matrix::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-cx-sparse.h b/libinterp/octave-value/ov-cx-sparse.h --- a/libinterp/octave-value/ov-cx-sparse.h +++ b/libinterp/octave-value/ov-cx-sparse.h @@ -141,11 +141,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); mxArray *as_mxArray (void) const; diff --git a/libinterp/octave-value/ov-fcn-handle.cc b/libinterp/octave-value/ov-fcn-handle.cc --- a/libinterp/octave-value/ov-fcn-handle.cc +++ b/libinterp/octave-value/ov-fcn-handle.cc @@ -37,6 +37,7 @@ along with Octave; see the file COPYING. #include "error.h" #include "gripes.h" #include "input.h" +#include "oct-hdf5.h" #include "oct-map.h" #include "ov-base.h" #include "ov-fcn-handle.h" @@ -704,11 +705,12 @@ octave_fcn_handle::load_binary (std::ist return success; } -#if defined (HAVE_HDF5) bool -octave_fcn_handle::save_hdf5 (hid_t loc_id, const char *name, +octave_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) { +#if defined (HAVE_HDF5) + bool retval = true; hid_t group_hid = -1; @@ -931,11 +933,18 @@ octave_fcn_handle::save_hdf5 (hid_t loc_ H5Gclose (group_hid); return retval; + +#else + gripe_save ("hdf5"); + return false; +#endif } bool -octave_fcn_handle::load_hdf5 (hid_t loc_id, const char *name) +octave_fcn_handle::load_hdf5 (octave_hdf5_id loc_id, const char *name) { +#if defined (HAVE_HDF5) + bool success = true; hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; @@ -1291,10 +1300,13 @@ octave_fcn_handle::load_hdf5 (hid_t loc_ H5Gclose (group_hid); return success; + +#else + gripe_load ("hdf5"); + return false; +#endif } -#endif - /* %!test %! a = 2; diff --git a/libinterp/octave-value/ov-fcn-handle.h b/libinterp/octave-value/ov-fcn-handle.h --- a/libinterp/octave-value/ov-fcn-handle.h +++ b/libinterp/octave-value/ov-fcn-handle.h @@ -146,11 +146,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); void print (std::ostream& os, bool pr_as_read_syntax = false); diff --git a/libinterp/octave-value/ov-fcn-inline.cc b/libinterp/octave-value/ov-fcn-inline.cc --- a/libinterp/octave-value/ov-fcn-inline.cc +++ b/libinterp/octave-value/ov-fcn-inline.cc @@ -38,6 +38,7 @@ Open Source Initiative (www.opensource.o #include "defun.h" #include "error.h" #include "gripes.h" +#include "oct-hdf5.h" #include "oct-map.h" #include "ov-base.h" #include "ov-fcn-inline.h" @@ -272,12 +273,16 @@ octave_fcn_inline::load_binary (std::ist return true; } -#if defined (HAVE_HDF5) bool -octave_fcn_inline::save_hdf5 (hid_t loc_id, const char *name, +octave_fcn_inline::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool /* save_as_floats */) { + bool retval = false; + +#if defined (HAVE_HDF5) + hid_t group_hid = -1; + #if HAVE_HDF5_18 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else @@ -292,7 +297,6 @@ octave_fcn_inline::save_hdf5 (hid_t loc_ hid_t space_hid, data_hid, type_hid; space_hid = data_hid = type_hid = -1; - bool retval = true; // FIXME: Is there a better way of saving string vectors, // than a null padded matrix? @@ -408,12 +412,18 @@ octave_fcn_inline::save_hdf5 (hid_t loc_ H5Tclose (type_hid); H5Gclose (group_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_fcn_inline::load_hdf5 (hid_t loc_id, const char *name) +octave_fcn_inline::load_hdf5 (octave_hdf5_id loc_id, const char *name) { +#if defined (HAVE_HDF5) + hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; hsize_t rank; int slen; @@ -593,8 +603,12 @@ octave_fcn_inline::load_hdf5 (hid_t loc_ fcn = ftmp.fcn; return true; + +#else + gripe_load ("hdf5"); + return false; +#endif } -#endif void octave_fcn_inline::print (std::ostream& os, bool pr_as_read_syntax) diff --git a/libinterp/octave-value/ov-fcn-inline.h b/libinterp/octave-value/ov-fcn-inline.h --- a/libinterp/octave-value/ov-fcn-inline.h +++ b/libinterp/octave-value/ov-fcn-inline.h @@ -79,11 +79,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); void print (std::ostream& os, bool pr_as_read_syntax = false); diff --git a/libinterp/octave-value/ov-float.cc b/libinterp/octave-value/ov-float.cc --- a/libinterp/octave-value/ov-float.cc +++ b/libinterp/octave-value/ov-float.cc @@ -35,6 +35,7 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "mxarray.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ov-scalar.h" #include "ov-float.h" @@ -183,12 +184,12 @@ octave_float_scalar::load_binary (std::i return true; } +bool +octave_float_scalar::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool /* save_as_floats */) +{ #if defined (HAVE_HDF5) -bool -octave_float_scalar::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) -{ hsize_t dimens[3]; hid_t space_hid, data_hid; space_hid = data_hid = -1; @@ -216,12 +217,18 @@ octave_float_scalar::save_hdf5 (hid_t lo H5Dclose (data_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_float_scalar::load_hdf5 (hid_t loc_id, const char *name) +octave_float_scalar::load_hdf5 (octave_hdf5_id loc_id, const char *name) { +#if defined (HAVE_HDF5) + #if HAVE_HDF5_18 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); #else @@ -250,10 +257,13 @@ octave_float_scalar::load_hdf5 (hid_t lo H5Dclose (data_hid); return true; + +#else + gripe_load ("hdf5"); + return false; +#endif } -#endif - mxArray * octave_float_scalar::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-float.h b/libinterp/octave-value/ov-float.h --- a/libinterp/octave-value/ov-float.h +++ b/libinterp/octave-value/ov-float.h @@ -231,11 +231,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-flt-complex.cc b/libinterp/octave-value/ov-flt-complex.cc --- a/libinterp/octave-value/ov-flt-complex.cc +++ b/libinterp/octave-value/ov-flt-complex.cc @@ -32,6 +32,7 @@ along with Octave; see the file COPYING. #include "mxarray.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ops.h" #include "ov-complex.h" @@ -292,16 +293,17 @@ octave_float_complex::load_binary (std:: return true; } +bool +octave_float_complex::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool /* save_as_floats */) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_float_complex::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) -{ hsize_t dimens[3]; hid_t space_hid, type_hid, data_hid; space_hid = type_hid = data_hid = -1; - bool retval = true; space_hid = H5Screate_simple (0, dimens, 0); if (space_hid < 0) @@ -334,13 +336,20 @@ octave_float_complex::save_hdf5 (hid_t l H5Tclose (type_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_float_complex::load_hdf5 (hid_t loc_id, const char *name) +octave_float_complex::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; + +#if defined (HAVE_HDF5) + #if HAVE_HDF5_18 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); #else @@ -381,11 +390,13 @@ octave_float_complex::load_hdf5 (hid_t l H5Sclose (space_id); H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_float_complex::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-flt-complex.h b/libinterp/octave-value/ov-flt-complex.h --- a/libinterp/octave-value/ov-flt-complex.h +++ b/libinterp/octave-value/ov-flt-complex.h @@ -167,11 +167,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-flt-cx-mat.cc b/libinterp/octave-value/ov-flt-cx-mat.cc --- a/libinterp/octave-value/ov-flt-cx-mat.cc +++ b/libinterp/octave-value/ov-flt-cx-mat.cc @@ -39,6 +39,7 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "mxarray.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ops.h" #include "ov-base.h" @@ -524,11 +525,13 @@ octave_float_complex_matrix::load_binary return true; } +bool +octave_float_complex_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_float_complex_matrix::save_hdf5 (hid_t loc_id, const char *name, bool) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -537,7 +540,6 @@ octave_float_complex_matrix::save_hdf5 ( int rank = dv.length (); hid_t space_hid, data_hid, type_hid; space_hid = data_hid = type_hid = -1; - bool retval = true; FloatComplexNDArray m = complex_array_value (); OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); @@ -601,14 +603,20 @@ octave_float_complex_matrix::save_hdf5 ( H5Tclose (type_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_float_complex_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_float_complex_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + dim_vector dv; int empty = load_hdf5_empty (loc_id, name, dv); if (empty > 0) @@ -676,11 +684,13 @@ octave_float_complex_matrix::load_hdf5 ( H5Sclose (space_id); H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - void octave_float_complex_matrix::print_raw (std::ostream& os, bool pr_as_read_syntax) const diff --git a/libinterp/octave-value/ov-flt-cx-mat.h b/libinterp/octave-value/ov-flt-cx-mat.h --- a/libinterp/octave-value/ov-flt-cx-mat.h +++ b/libinterp/octave-value/ov-flt-cx-mat.h @@ -151,11 +151,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-flt-re-mat.cc b/libinterp/octave-value/ov-flt-re-mat.cc --- a/libinterp/octave-value/ov-flt-re-mat.cc +++ b/libinterp/octave-value/ov-flt-re-mat.cc @@ -44,6 +44,7 @@ along with Octave; see the file COPYING. #include "mxarray.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ops.h" #include "ov-base.h" @@ -551,11 +552,13 @@ octave_float_matrix::load_binary (std::i return true; } +bool +octave_float_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_float_matrix::save_hdf5 (hid_t loc_id, const char *name, bool) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -564,7 +567,6 @@ octave_float_matrix::save_hdf5 (hid_t lo int rank = dv.length (); hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; FloatNDArray m = array_value (); OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); @@ -610,14 +612,20 @@ octave_float_matrix::save_hdf5 (hid_t lo H5Dclose (data_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_float_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_float_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + dim_vector dv; int empty = load_hdf5_empty (loc_id, name, dv); if (empty > 0) @@ -672,11 +680,13 @@ octave_float_matrix::load_hdf5 (hid_t lo H5Sclose (space_id); H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - void octave_float_matrix::print_raw (std::ostream& os, bool pr_as_read_syntax) const diff --git a/libinterp/octave-value/ov-flt-re-mat.h b/libinterp/octave-value/ov-flt-re-mat.h --- a/libinterp/octave-value/ov-flt-re-mat.h +++ b/libinterp/octave-value/ov-flt-re-mat.h @@ -189,11 +189,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-int16.cc b/libinterp/octave-value/ov-int16.cc --- a/libinterp/octave-value/ov-int16.cc +++ b/libinterp/octave-value/ov-int16.cc @@ -36,13 +36,10 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" -#ifdef HAVE_HDF5 -#define HDF5_SAVE_TYPE H5T_NATIVE_INT16 -#endif - #include "ov-base-int.h" #include "ov-base-int.cc" #include "ov-int16.h" diff --git a/libinterp/octave-value/ov-int32.cc b/libinterp/octave-value/ov-int32.cc --- a/libinterp/octave-value/ov-int32.cc +++ b/libinterp/octave-value/ov-int32.cc @@ -36,13 +36,10 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" -#ifdef HAVE_HDF5 -#define HDF5_SAVE_TYPE H5T_NATIVE_INT32 -#endif - #include "ov-base-int.h" #include "ov-base-int.cc" #include "ov-int32.h" diff --git a/libinterp/octave-value/ov-int64.cc b/libinterp/octave-value/ov-int64.cc --- a/libinterp/octave-value/ov-int64.cc +++ b/libinterp/octave-value/ov-int64.cc @@ -36,13 +36,10 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" -#ifdef HAVE_HDF5 -#define HDF5_SAVE_TYPE H5T_NATIVE_INT64 -#endif - #include "ov-base-int.h" #include "ov-base-int.cc" #include "ov-int64.h" diff --git a/libinterp/octave-value/ov-int8.cc b/libinterp/octave-value/ov-int8.cc --- a/libinterp/octave-value/ov-int8.cc +++ b/libinterp/octave-value/ov-int8.cc @@ -36,13 +36,10 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" -#ifdef HAVE_HDF5 -#define HDF5_SAVE_TYPE H5T_NATIVE_INT8 -#endif - #include "ov-base-int.h" #include "ov-base-int.cc" #include "ov-int8.h" diff --git a/libinterp/octave-value/ov-lazy-idx.h b/libinterp/octave-value/ov-lazy-idx.h --- a/libinterp/octave-value/ov-lazy-idx.h +++ b/libinterp/octave-value/ov-lazy-idx.h @@ -203,7 +203,6 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); - // HDF5 functions not defined. int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, @@ -248,4 +247,3 @@ private: }; #endif - diff --git a/libinterp/octave-value/ov-oncleanup.cc b/libinterp/octave-value/ov-oncleanup.cc --- a/libinterp/octave-value/ov-oncleanup.cc +++ b/libinterp/octave-value/ov-oncleanup.cc @@ -147,9 +147,9 @@ octave_oncleanup::load_binary (std::istr return true; } -#if defined (HAVE_HDF5) bool -octave_oncleanup::save_hdf5 (hid_t /* loc_id */, const char * /* name */, +octave_oncleanup::save_hdf5 (octave_hdf5_id /* loc_id */, + const char * /* name */, bool /* save_as_floats */) { warn_save_load (); @@ -157,12 +157,12 @@ octave_oncleanup::save_hdf5 (hid_t /* lo } bool -octave_oncleanup::load_hdf5 (hid_t /* loc_id */, const char * /* name */) +octave_oncleanup::load_hdf5 (octave_hdf5_id /* loc_id */, + const char * /* name */) { warn_save_load (); return true; } -#endif void octave_oncleanup::print (std::ostream& os, bool pr_as_read_syntax) diff --git a/libinterp/octave-value/ov-oncleanup.h b/libinterp/octave-value/ov-oncleanup.h --- a/libinterp/octave-value/ov-oncleanup.h +++ b/libinterp/octave-value/ov-oncleanup.h @@ -81,11 +81,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); void print (std::ostream& os, bool pr_as_read_syntax = false); diff --git a/libinterp/octave-value/ov-range.cc b/libinterp/octave-value/ov-range.cc --- a/libinterp/octave-value/ov-range.cc +++ b/libinterp/octave-value/ov-range.cc @@ -35,6 +35,7 @@ along with Octave; see the file COPYING. #include "mxarray.h" #include "ops.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "ov-range.h" #include "ov-re-mat.h" #include "ov-scalar.h" @@ -543,14 +544,19 @@ hdf5_make_range_type (hid_t num_type) return type_id; } +#endif + bool -octave_range::save_hdf5 (hid_t loc_id, const char *name, +octave_range::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool /* save_as_floats */) { + bool retval = false; + +#if defined (HAVE_HDF5) + hsize_t dimens[3]; hid_t space_hid, type_hid, data_hid; space_hid = type_hid = data_hid = -1; - bool retval = true; space_hid = H5Screate_simple (0, dimens, 0); if (space_hid < 0) return false; @@ -594,14 +600,20 @@ octave_range::save_hdf5 (hid_t loc_id, c H5Tclose (type_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_range::load_hdf5 (hid_t loc_id, const char *name) +octave_range::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + #if HAVE_HDF5_18 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); #else @@ -652,11 +664,13 @@ octave_range::load_hdf5 (hid_t loc_id, c H5Sclose (space_hid); H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_range::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-range.h b/libinterp/octave-value/ov-range.h --- a/libinterp/octave-value/ov-range.h +++ b/libinterp/octave-value/ov-range.h @@ -265,11 +265,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-re-mat.cc b/libinterp/octave-value/ov-re-mat.cc --- a/libinterp/octave-value/ov-re-mat.cc +++ b/libinterp/octave-value/ov-re-mat.cc @@ -44,6 +44,7 @@ along with Octave; see the file COPYING. #include "mxarray.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ops.h" #include "ov-base.h" @@ -663,11 +664,13 @@ octave_matrix::load_binary (std::istream return true; } +bool +octave_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_matrix::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -676,7 +679,6 @@ octave_matrix::save_hdf5 (hid_t loc_id, int rank = dv.length (); hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; NDArray m = array_value (); OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); @@ -733,14 +735,20 @@ octave_matrix::save_hdf5 (hid_t loc_id, H5Dclose (data_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + dim_vector dv; int empty = load_hdf5_empty (loc_id, name, dv); if (empty > 0) @@ -795,11 +803,13 @@ octave_matrix::load_hdf5 (hid_t loc_id, H5Sclose (space_id); H5Dclose (data_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - void octave_matrix::print_raw (std::ostream& os, bool pr_as_read_syntax) const diff --git a/libinterp/octave-value/ov-re-mat.h b/libinterp/octave-value/ov-re-mat.h --- a/libinterp/octave-value/ov-re-mat.h +++ b/libinterp/octave-value/ov-re-mat.h @@ -213,11 +213,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-re-sparse.cc b/libinterp/octave-value/ov-re-sparse.cc --- a/libinterp/octave-value/ov-re-sparse.cc +++ b/libinterp/octave-value/ov-re-sparse.cc @@ -38,6 +38,7 @@ along with Octave; see the file COPYING. #include "ov-scalar.h" #include "gripes.h" +#include "oct-hdf5.h" #include "ls-hdf5.h" #include "ov-re-sparse.h" @@ -397,12 +398,14 @@ octave_sparse_matrix::load_binary (std:: return true; } +bool +octave_sparse_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool save_as_floats) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_sparse_matrix::save_hdf5 (hid_t loc_id, const char *name, - bool save_as_floats) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -422,7 +425,6 @@ octave_sparse_matrix::save_hdf5 (hid_t l hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; SparseMatrix m = sparse_matrix_value (); octave_idx_type tmp; hsize_t hdims[2]; @@ -627,12 +629,20 @@ octave_sparse_matrix::save_hdf5 (hid_t l H5Sclose (space_hid); H5Gclose (group_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_sparse_matrix::load_hdf5 (hid_t loc_id, const char *name) +octave_sparse_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) { + bool retval = false; + +#if defined (HAVE_HDF5) + octave_idx_type nr, nc, nz; hid_t group_hid, data_hid, space_hid; hsize_t rank; @@ -839,7 +849,7 @@ octave_sparse_matrix::load_hdf5 (hid_t l } double *dtmp = m.xdata (); - bool retval = false; + if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dtmp) >= 0 && m.indices_ok ()) @@ -852,11 +862,13 @@ octave_sparse_matrix::load_hdf5 (hid_t l H5Dclose (data_hid); H5Gclose (group_hid); +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_sparse_matrix::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-re-sparse.h b/libinterp/octave-value/ov-re-sparse.h --- a/libinterp/octave-value/ov-re-sparse.h +++ b/libinterp/octave-value/ov-re-sparse.h @@ -144,11 +144,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); mxArray *as_mxArray (void) const; diff --git a/libinterp/octave-value/ov-scalar.cc b/libinterp/octave-value/ov-scalar.cc --- a/libinterp/octave-value/ov-scalar.cc +++ b/libinterp/octave-value/ov-scalar.cc @@ -35,6 +35,7 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "mxarray.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ov-scalar.h" #include "ov-float.h" @@ -198,16 +199,17 @@ octave_scalar::load_binary (std::istream return true; } +bool +octave_scalar::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool /* save_as_floats */) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_scalar::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) -{ hsize_t dimens[3]; hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; space_hid = H5Screate_simple (0, dimens, 0); if (space_hid < 0) return false; @@ -232,12 +234,18 @@ octave_scalar::save_hdf5 (hid_t loc_id, H5Dclose (data_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_scalar::load_hdf5 (hid_t loc_id, const char *name) +octave_scalar::load_hdf5 (octave_hdf5_id loc_id, const char *name) { +#if defined (HAVE_HDF5) + #if HAVE_HDF5_18 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); #else @@ -266,10 +274,13 @@ octave_scalar::load_hdf5 (hid_t loc_id, H5Dclose (data_hid); return true; + +#else + gripe_load ("hdf5"); + return false; +#endif } -#endif - mxArray * octave_scalar::as_mxArray (void) const { diff --git a/libinterp/octave-value/ov-scalar.h b/libinterp/octave-value/ov-scalar.h --- a/libinterp/octave-value/ov-scalar.h +++ b/libinterp/octave-value/ov-scalar.h @@ -230,11 +230,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-str-mat.cc b/libinterp/octave-value/ov-str-mat.cc --- a/libinterp/octave-value/ov-str-mat.cc +++ b/libinterp/octave-value/ov-str-mat.cc @@ -44,6 +44,7 @@ along with Octave; see the file COPYING. #include "ls-oct-ascii.h" #include "ls-utils.h" #include "oct-obj.h" +#include "oct-hdf5.h" #include "oct-stream.h" #include "ops.h" #include "ov-scalar.h" @@ -569,12 +570,14 @@ octave_char_matrix_str::load_binary (std return true; } +bool +octave_char_matrix_str::save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool /* save_as_floats */) +{ + bool retval = false; + #if defined (HAVE_HDF5) -bool -octave_char_matrix_str::save_hdf5 (hid_t loc_id, const char *name, - bool /* save_as_floats */) -{ dim_vector dv = dims (); int empty = save_hdf5_empty (loc_id, name, dv); if (empty) @@ -583,7 +586,6 @@ octave_char_matrix_str::save_hdf5 (hid_t int rank = dv.length (); hid_t space_hid, data_hid; space_hid = data_hid = -1; - bool retval = true; charNDArray m = char_array_value (); OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); @@ -619,14 +621,20 @@ octave_char_matrix_str::save_hdf5 (hid_t H5Dclose (data_hid); H5Sclose (space_hid); +#else + gripe_save ("hdf5"); +#endif + return retval; } bool -octave_char_matrix_str::load_hdf5 (hid_t loc_id, const char *name) +octave_char_matrix_str::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + dim_vector dv; int empty = load_hdf5_empty (loc_id, name, dv); if (empty > 0) @@ -788,7 +796,9 @@ octave_char_matrix_str::load_hdf5 (hid_t } } +#else + gripe_load ("hdf5"); +#endif + return retval; } - -#endif diff --git a/libinterp/octave-value/ov-str-mat.h b/libinterp/octave-value/ov-str-mat.h --- a/libinterp/octave-value/ov-str-mat.h +++ b/libinterp/octave-value/ov-str-mat.h @@ -153,11 +153,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, diff --git a/libinterp/octave-value/ov-struct.cc b/libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc +++ b/libinterp/octave-value/ov-struct.cc @@ -32,6 +32,7 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "mxarray.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ov-struct.h" #include "unwind-prot.h" #include "utils.h" @@ -979,11 +980,11 @@ octave_struct::load_binary (std::istream return success; } +bool +octave_struct::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) +{ #if defined (HAVE_HDF5) -bool -octave_struct::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) -{ hid_t data_hid = -1; #if HAVE_HDF5_18 @@ -1018,13 +1019,20 @@ octave_struct::save_hdf5 (hid_t loc_id, H5Gclose (data_hid); return true; + +#else + gripe_save ("hdf5"); + return false; +#endif } bool -octave_struct::load_hdf5 (hid_t loc_id, const char *name) +octave_struct::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; +#if defined (HAVE_HDF5) + hdf5_callback_data dsub; herr_t retval2 = 0; @@ -1066,11 +1074,13 @@ octave_struct::load_hdf5 (hid_t loc_id, retval = true; } +#else + gripe_load ("hdf5"); +#endif + return retval; } -#endif - mxArray * octave_struct::as_mxArray (void) const { @@ -1617,7 +1627,7 @@ octave_scalar_struct::load_binary (std:: #if defined (HAVE_HDF5) bool -octave_scalar_struct::save_hdf5 (hid_t loc_id, const char *name, +octave_scalar_struct::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) { hid_t data_hid = -1; @@ -1657,7 +1667,7 @@ octave_scalar_struct::save_hdf5 (hid_t l } bool -octave_scalar_struct::load_hdf5 (hid_t loc_id, const char *name) +octave_scalar_struct::load_hdf5 (octave_hdf5_id loc_id, const char *name) { bool retval = false; diff --git a/libinterp/octave-value/ov-struct.h b/libinterp/octave-value/ov-struct.h --- a/libinterp/octave-value/ov-struct.h +++ b/libinterp/octave-value/ov-struct.h @@ -140,11 +140,9 @@ public: bool load_binary (std::istream& is, bool swap, oct_mach_info::float_format fmt); -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); -#endif + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); mxArray *as_mxArray (void) const; @@ -263,9 +261,9 @@ public: oct_mach_info::float_format fmt); #if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats); - bool load_hdf5 (hid_t loc_id, const char *name); + bool load_hdf5 (octave_hdf5_id loc_id, const char *name); #endif mxArray *as_mxArray (void) const; diff --git a/libinterp/octave-value/ov-uint16.cc b/libinterp/octave-value/ov-uint16.cc --- a/libinterp/octave-value/ov-uint16.cc +++ b/libinterp/octave-value/ov-uint16.cc @@ -36,13 +36,10 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" -#ifdef HAVE_HDF5 -#define HDF5_SAVE_TYPE H5T_NATIVE_UINT16 -#endif - #include "ov-base-int.h" #include "ov-base-int.cc" #include "ov-uint16.h" diff --git a/libinterp/octave-value/ov-uint32.cc b/libinterp/octave-value/ov-uint32.cc --- a/libinterp/octave-value/ov-uint32.cc +++ b/libinterp/octave-value/ov-uint32.cc @@ -36,13 +36,10 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" -#ifdef HAVE_HDF5 -#define HDF5_SAVE_TYPE H5T_NATIVE_UINT32 -#endif - #include "ov-base-int.h" #include "ov-base-int.cc" #include "ov-uint32.h" diff --git a/libinterp/octave-value/ov-uint64.cc b/libinterp/octave-value/ov-uint64.cc --- a/libinterp/octave-value/ov-uint64.cc +++ b/libinterp/octave-value/ov-uint64.cc @@ -36,13 +36,10 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" -#ifdef HAVE_HDF5 -#define HDF5_SAVE_TYPE H5T_NATIVE_UINT64 -#endif - #include "ov-base-int.h" #include "ov-base-int.cc" #include "ov-uint64.h" diff --git a/libinterp/octave-value/ov-uint8.cc b/libinterp/octave-value/ov-uint8.cc --- a/libinterp/octave-value/ov-uint8.cc +++ b/libinterp/octave-value/ov-uint8.cc @@ -36,13 +36,10 @@ along with Octave; see the file COPYING. #include "gripes.h" #include "oct-obj.h" #include "oct-lvalue.h" +#include "oct-hdf5.h" #include "ops.h" #include "ov-base.h" -#ifdef HAVE_HDF5 -#define HDF5_SAVE_TYPE H5T_NATIVE_UINT8 -#endif - #include "ov-base-int.h" #include "ov-base-int.cc" #include "ov-uint8.h" diff --git a/libinterp/octave-value/ov.h b/libinterp/octave-value/ov.h --- a/libinterp/octave-value/ov.h +++ b/libinterp/octave-value/ov.h @@ -38,7 +38,6 @@ along with Octave; see the file COPYING. #include "oct-time.h" #include "str-vec.h" -#include "oct-hdf5.h" #include "oct-sort.h" class Cell; @@ -57,8 +56,6 @@ class octave_lvalue; // Constants. -class octave_value; - class OCTINTERP_API octave_value @@ -1094,13 +1091,12 @@ public: oct_mach_info::float_format fmt) { return rep->load_binary (is, swap, fmt); } -#if defined (HAVE_HDF5) - bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) + bool save_hdf5 (octave_hdf5_id loc_id, const char *name, + bool save_as_floats) { return rep->save_hdf5 (loc_id, name, save_as_floats); } - bool load_hdf5 (hid_t loc_id, const char *name) + bool load_hdf5 (octave_hdf5_id loc_id, const char *name) { return rep->load_hdf5 (loc_id, name); } -#endif int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip,