From 1f9409d8e7b6f057cc790d1721282e4808d29bc1 Mon Sep 17 00:00:00 2001 From: Lukas Unglehrt Date: Sun, 27 Dec 2020 12:16:07 +0100 Subject: [PATCH 1/3] Fix compilation on Fedora 33 with GCC 10.2.1 and Octave 5.2.0 --- h5read.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/h5read.cc b/h5read.cc index bb953c3..d1170e2 100644 --- a/h5read.cc +++ b/h5read.cc @@ -38,7 +38,6 @@ #include #include #include -#include "gripes.h" #include "file-stat.h" using namespace std; @@ -599,7 +598,7 @@ H5File::H5File (const char *filename, const bool create_if_nonexisting, //suppress hdf5 error output H5Eset_auto (H5E_DEFAULT,0,0); - file_stat fs (filename); + octave::sys::file_stat fs (filename); if (! fs.exists () && create_if_nonexisting) file = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); else if (! fs.exists () && ! create_if_nonexisting) From 42abdc3c030e4e0b8eb262827cedd7af5494a8d5 Mon Sep 17 00:00:00 2001 From: Lukas Unglehrt Date: Sun, 27 Dec 2020 12:21:24 +0100 Subject: [PATCH 2/3] Replace function calls deprecated in GNU Octave 4.4 --- h5read.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/h5read.cc b/h5read.cc index d1170e2..082e4b3 100644 --- a/h5read.cc +++ b/h5read.cc @@ -75,7 +75,7 @@ check_vec (const octave_value& val, Matrix& mat/*out*/, if (error_state) return 0; - if (! mat.is_vector ()) + if (! mat.isvector ()) { error ("%s must be a vector", name); return 0; @@ -754,8 +754,8 @@ H5File::read_dset_hyperslab (const char *dsetname, if (open_dset (dsetname) < 0) return octave_value (); - if (rank == 0 && ! (start.is_empty () && count.is_empty () - && stride.is_empty () && block.is_empty ())) + if (rank == 0 && ! (start.isempty () && count.isempty () + && stride.isempty () && block.isempty ())) { error ("Cannot specify hyperslab for scalar datasets (rank 0)"); return octave_value (); @@ -1018,7 +1018,7 @@ H5File::write_dset (const char *dsetname, herr_t status; // find the right type - if (ov_data.is_complex_type()) + if (ov_data.iscomplex()) { //check if the data set already exists. if it does, open it, //otherwise, create it. Furthermore check if the datatype is @@ -1044,7 +1044,7 @@ H5File::write_dset (const char *dsetname, ComplexNDArray data = ov_data.complex_array_value (); OPEN_AND_WRITE; } - else if (ov_data.is_integer_type ()) + else if (ov_data.isinteger ()) { if (ov_data.is_uint64_type ()) { @@ -1136,8 +1136,8 @@ H5File::write_dset_hyperslab (const char *dsetname, return; // check if the given hyperslab settings are reasonable - if (rank == 0 && ! (start.is_empty () && count.is_empty () - && stride.is_empty () && block.is_empty ())) + if (rank == 0 && ! (start.isempty () && count.isempty () + && stride.isempty () && block.isempty ())) { error ("Cannot specify hyperslab for scalar datasets (rank 0)"); return; @@ -1462,7 +1462,7 @@ H5File::write_att (const char *location, const char *attname, buf = (void *) attvalue.string_value ().c_str (); } - else if (attvalue.is_integer_type ()) + else if (attvalue.isinteger ()) { //type_id = H5Tcopy (H5T_STD_I64LE); //cannot read this back in then, don't know why type_id = H5Tcopy (H5T_NATIVE_INT); @@ -1470,14 +1470,14 @@ H5File::write_att (const char *location, const char *attname, attval_int = attvalue.int_value (); buf = (void *) &attval_int; } - else if (attvalue.is_real_type ()) + else if (attvalue.isreal ()) { type_id = H5Tcopy (H5T_NATIVE_DOUBLE); mem_type_id = H5Tcopy (H5T_NATIVE_DOUBLE); attval_double = attvalue.double_value (); buf = (void *) &attval_double; } - else if (attvalue.is_complex_type ()) + else if (attvalue.iscomplex ()) { error ("complex values are not supported by the HDF5 format. \ You have to save real and imag part separately."); @@ -1574,14 +1574,14 @@ H5File::create_dset (const char *location, const Matrix& size, free (dims); free (maxdims); - if (any_int_leq_zero (size) && chunksize.is_empty()) + if (any_int_leq_zero (size) && chunksize.isempty()) { error ("If the size argument contains an Inf or zero element, then ChunkSize must be specified."); return; } // get a dataset creation property list hid_t crp_list = H5Pcreate (H5P_DATASET_CREATE); - if (! chunksize.is_empty()) + if (! chunksize.isempty()) { // a dataset with an unlimited dimension must be chunked. if (chunksize(0) == 0) From 8c510c0ab09107298fd00b0c403c32b3ba58120f Mon Sep 17 00:00:00 2001 From: Lukas Unglehrt Date: Sun, 27 Dec 2020 14:59:15 +0100 Subject: [PATCH 3/3] Bugfix: Wrong usage of dim_vector.numel() to determine rank of array. From the documentation of dim_vector.numel() in GNU Octave 5.2.0: Return the number of elements that a matrix with this dimension vector would have, NOT the number of dimensions (elements in the dimension vector). The correct call is dim_vector.ndims(). Consequently, the template alloc_hsize(...) was removed and replaced by separate versions for Matrix and dim_vector data types. Now all tests pass. --- h5read.cc | 28 ++++++++++++++++++++++++---- h5read.h | 3 ++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/h5read.cc b/h5read.cc index 082e4b3..39153e6 100644 --- a/h5read.cc +++ b/h5read.cc @@ -660,10 +660,8 @@ H5File::~H5File () } } -// T will be Matrix or dim_vector -template hsize_t* -H5File::alloc_hsize (const T& dim, const int mode, const bool reverse) +H5File::alloc_hsize (const Matrix& dim, const int mode, const bool reverse) { int rank = dim.numel (); hsize_t *hsize = (hsize_t*)malloc (rank * sizeof (hsize_t)); @@ -680,6 +678,27 @@ H5File::alloc_hsize (const T& dim, const int mode, const bool reverse) return hsize; } +hsize_t* +H5File::alloc_hsize (const dim_vector& dim, const int mode, const bool reverse) +{ + // attention: + // dim.numel () gives the number of entries that a matrix with this dimension + // vector would have + int rank = dim.ndims (); + hsize_t *hsize = (hsize_t*)malloc (rank * sizeof (hsize_t)); + for (int i = 0; i < rank; i++) + { + int j = reverse ? rank-i-1 : i; + if (mode == ALLOC_HSIZE_INFZERO_TO_UNLIMITED && (dim(i) == octave_Inf || dim(i) == 0)) + hsize[j] = H5S_UNLIMITED; + else if (mode == ALLOC_HSIZE_INF_TO_ZERO && dim(i) == octave_Inf) + hsize[j] = 0; + else + hsize[j] = dim(i); + } + return hsize; +} + int H5File::open_dset (const char *dsetname) @@ -988,7 +1007,8 @@ void H5File::write_dset (const char *dsetname, const octave_value ov_data) { - int rank = ov_data.dims ().numel (); + // the rank of the dataspace is the number of dimensions + int rank = ov_data.dims ().ndims (); hsize_t *dims = alloc_hsize (ov_data.dims(), ALLOC_HSIZE_DEFAULT, true); dspace_id = H5Screate_simple (rank, dims, NULL); diff --git a/h5read.h b/h5read.h index 813ba4d..a1935aa 100644 --- a/h5read.h +++ b/h5read.h @@ -92,7 +92,8 @@ class H5File octave_value read_dset (); Matrix get_auto_chunksize (const Matrix& size, int typesize); - template hsize_t* alloc_hsize (const T& dim, const int mode, const bool reverse); + hsize_t* alloc_hsize (const Matrix& dim, const int mode, const bool reverse); + hsize_t* alloc_hsize (const dim_vector& dim, const int mode, const bool reverse); };