25 #if defined (HAVE_CONFIG_H)
29 #if defined (HAVE_HDF5)
76 #if defined (HAVE_HDF5)
82 error (
"%s: internal error: ID too large for hid_t", who);
84 return static_cast<hid_t
> (
id);
90 : file_id (-1), current_item (-1)
92 #if defined (HAVE_HDF5)
94 if (mode & std::ios::in)
96 else if (mode & std::ios::out)
98 if (mode & std::ios::app && H5Fis_hdf5 (name) > 0)
105 std::ios::setstate (std::ios::badbit);
117 #if defined (HAVE_HDF5)
122 std::ios::setstate (std::ios::badbit);
137 #if defined (HAVE_HDF5)
141 if (mode & std::ios::in)
143 else if (mode & std::ios::out)
145 if (mode & std::ios::app && H5Fis_hdf5 (name) > 0)
152 std::ios::setstate (std::ios::badbit);
169 size_t nm_len = nm.
length ();
173 if (! isalpha (nm[0]))
176 for (
size_t i = 0;
i < nm_len;
i++)
179 retval += (isalnum (c) || c ==
'_') ? c :
'_';
194 #if defined (HAVE_HDF5)
197 if ((n = H5Tget_nmembers (t1)) != H5Tget_nmembers (t2))
200 for (
int i = 0;
i < n; ++
i)
202 hid_t mt1 = H5Tget_member_type (t1,
i);
203 hid_t mt2 = H5Tget_member_type (t2,
i);
205 if (H5Tget_class (mt1) != H5Tget_class (mt2))
225 #if defined (HAVE_HDF5)
239 #if defined (HAVE_HDF5_18)
243 H5Eget_auto (&err_func, &err_func_data);
247 hid_t attr_id = H5Aopen_name (loc_id, attr_name);
257 #if defined (HAVE_HDF5_18)
260 H5Eset_auto (err_func, err_func_data);
271 const char *attr_name,
void *buf)
273 #if defined (HAVE_HDF5)
287 #if defined (HAVE_HDF5_18)
291 H5Eget_auto (&err_func, &err_func_data);
295 hid_t attr_id = H5Aopen_name (loc_id, attr_name);
299 hid_t space_id = H5Aget_space (attr_id);
301 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
304 retval = H5Aread (attr_id, type_id, buf) >= 0;
309 #if defined (HAVE_HDF5_18)
312 H5Eset_auto (err_func, err_func_data);
330 #if defined (HAVE_HDF5)
332 hid_t type_id = H5Tcreate (H5T_COMPOUND,
sizeof (
double) * 2);
334 H5Tinsert (type_id,
"real", 0 *
sizeof (
double), num_type);
335 H5Tinsert (type_id,
"imag", 1 *
sizeof (
double), num_type);
344 #if defined (HAVE_HDF5)
361 hid_t type_class_id = -1;
363 hid_t subgroup_id = -1;
364 hid_t space_id = -1;;
384 H5Gget_objinfo (group_id, name, 1, &info);
386 if (info.type == H5G_GROUP && ident_valid)
388 #if defined (HAVE_HDF5_18)
391 subgroup_id = H5Gopen (group_id, name);
396 retval = subgroup_id;
402 #if defined (HAVE_HDF5_18)
405 data_id = H5Dopen (subgroup_id,
"type");
414 type_id = H5Dget_type (data_id);
416 type_class_id = H5Tget_class (type_id);
418 if (type_class_id != H5T_STRING)
421 space_id = H5Dget_space (data_id);
422 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
427 int slen = H5Tget_size (type_id);
434 hid_t st_id = H5Tcopy (H5T_C_S1);
435 H5Tset_size (st_id, slen);
446 retval = (d->
tc.
load_hdf5 (subgroup_id,
"value") ? 1 : -1);
451 H5Gclose (subgroup_id);
467 H5Gclose (subgroup_id);
469 retval = (d->
tc.
load_hdf5 (group_id, name) ? 1 : -1);
473 else if (info.type == H5G_DATASET && ident_valid)
476 #if defined (HAVE_HDF5_18)
479 data_id = H5Dopen (group_id, name);
488 type_id = H5Dget_type (data_id);
490 type_class_id = H5Tget_class (type_id);
492 if (type_class_id == H5T_FLOAT)
494 space_id = H5Dget_space (data_id);
496 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
505 else if (type_class_id == H5T_INTEGER)
509 #if defined (HAVE_H5T_GET_NATIVE_TYPE)
513 switch (H5Tget_native_type (type_id, H5T_DIR_ASCEND))
515 case H5T_NATIVE_CHAR:
519 case H5T_NATIVE_SHORT:
524 case H5T_NATIVE_LONG:
528 case H5T_NATIVE_LLONG:
532 case H5T_NATIVE_UCHAR:
536 case H5T_NATIVE_USHORT:
540 case H5T_NATIVE_UINT:
541 case H5T_NATIVE_ULONG:
545 case H5T_NATIVE_ULLONG:
550 hid_t int_sign = H5Tget_sign (type_id);
552 if (int_sign == H5T_SGN_ERROR)
553 warning (
"load: can't read '%s' (unknown datatype)", name);
556 if (int_sign == H5T_SGN_NONE)
557 int_typ.append (
"u");
558 int_typ.append (
"int");
560 int slen = H5Tget_size (type_id);
562 warning (
"load: can't read '%s' (unknown datatype)", name);
568 int_typ.append (
"8 ");
572 int_typ.append (
"16 ");
576 int_typ.append (
"32 ");
580 int_typ.append (
"64 ");
584 warning (
"load: can't read '%s' (unknown datatype)",
593 warning (
"load: can't read '%s' (unknown datatype)", name);
597 space_id = H5Dget_space (data_id);
599 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
602 int_typ.append (
"scalar");
604 int_typ.append (
"matrix");
610 else if (type_class_id == H5T_STRING)
612 else if (type_class_id == H5T_COMPOUND)
619 space_id = H5Dget_space (data_id);
620 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
634 H5Tclose (complex_type);
638 warning (
"load: can't read '%s' (unknown datatype)", name);
649 retval = (d->
tc.
load_hdf5 (group_id, name) ? 1 : -1);
656 warning (
"load: skipping invalid identifier '%s' in hdf5 file",
662 error (
"load: error while reading hdf5 item %s", name);
667 int comment_length = H5Gget_comment (group_id, name, 0, 0);
669 if (comment_length > 1)
672 H5Gget_comment (group_id, name, comment_length, tdoc);
675 else if (vname != name)
694 #if defined (HAVE_HDF5)
709 #if defined (HAVE_HDF5)
731 #if defined (HAVE_HDF5)
742 herr_t H5Giterate_retval = -1;
745 #if defined (HAVE_HDF5_18)
748 hid_t group_id = H5Gopen (hs.
file_id,
"/");
750 H5Gget_num_objs (group_id, &num_obj);
755 bool load_named_vars = argv_idx <
argc;
756 while (load_named_vars && hs.
current_item < static_cast<int> (num_obj))
758 std::vector<char> var_name;
763 var_name.resize (len+1);
766 for (
int i = argv_idx;
i <
argc;
i++)
786 if (H5Giterate_retval > 0)
799 if (! d.
name.empty ())
814 #if defined (HAVE_HDF5)
818 hid_t as_id = H5Screate (H5S_SCALAR);
822 #if defined (HAVE_HDF5_18)
823 hid_t a_id = H5Acreate (loc_id, attr_name, H5T_NATIVE_UCHAR,
826 hid_t a_id = H5Acreate (loc_id, attr_name,
831 unsigned char attr_val = 1;
833 retval = H5Awrite (a_id, H5T_NATIVE_UCHAR, &attr_val);
854 const char *attr_name,
void *buf)
856 #if defined (HAVE_HDF5)
860 hid_t as_id = H5Screate (H5S_SCALAR);
864 #if defined (HAVE_HDF5_18)
865 hid_t a_id = H5Acreate (loc_id, attr_name, type_id,
868 hid_t a_id = H5Acreate (loc_id, attr_name,
873 retval = H5Awrite (a_id, type_id, buf);
899 #if defined (HAVE_HDF5)
904 hid_t space_hid = -1;
907 for (hsize_t
i = 0;
i <
sz;
i++)
917 space_hid = H5Screate_simple (1, &sz, 0);
918 if (space_hid < 0)
return space_hid;
919 #if defined (HAVE_HDF5_18)
928 H5Sclose (space_hid);
936 H5Sclose (space_hid);
941 return (retval == 0 ? 1 : retval);
955 #if defined (HAVE_HDF5)
960 hsize_t hdims, maxdims;
961 #if defined (HAVE_HDF5_18)
964 hid_t data_hid = H5Dopen (loc_id, name);
966 hid_t space_id = H5Dget_space (data_hid);
967 H5Sget_simple_extent_dims (space_id, &hdims, &maxdims);
977 for (hsize_t
i = 0;
i < hdims;
i++)
984 return (retval == 0 ? hdims : retval);
999 #if defined (HAVE_HDF5)
1000 # if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
1005 return H5T_NATIVE_UCHAR;
1008 return H5T_NATIVE_USHORT;
1011 return H5T_NATIVE_UINT;
1014 return H5T_NATIVE_CHAR;
1017 return H5T_NATIVE_SHORT;
1020 return H5T_NATIVE_INT;
1023 return H5T_NATIVE_FLOAT;
1027 return H5T_NATIVE_DOUBLE;
1032 octave_unused_parameter (st);
1040 octave_unused_parameter (st);
1057 #if defined (HAVE_HDF5)
1060 hid_t type_id, space_id, data_id, data_type_id;
1061 type_id = space_id = data_id = data_type_id = -1;
1073 #if defined (HAVE_HDF5_18)
1077 data_id = H5Gcreate (loc_id, name.c_str (), 0);
1083 type_id = H5Tcopy (H5T_C_S1); H5Tset_size (type_id, t.length () + 1);
1088 space_id = H5Screate_simple (0 , dims, 0);
1091 #if defined (HAVE_HDF5_18)
1092 data_type_id = H5Dcreate (data_id,
"type", type_id, space_id,
1093 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
1094 octave_H5P_DEFAULT);
1096 data_type_id = H5Dcreate (data_id,
"type", type_id, space_id,
1097 octave_H5P_DEFAULT);
1099 if (data_type_id < 0
1101 octave_H5P_DEFAULT, t.c_str ()) < 0)
1105 retval = val.
save_hdf5 (data_id,
"value", save_as_floats);
1108 if (retval && doc.length () > 0
1109 && H5Gset_comment (loc_id, name.c_str (), doc.c_str ()) < 0)
1113 if (retval && mark_as_global)
1122 if (data_type_id >= 0)
1123 H5Dclose (data_type_id);
1129 H5Sclose (space_id);
1135 error (
"save: error while writing '%s' to hdf5 file", name.c_str ());
1152 #if defined (HAVE_HDF5)
1159 mark_as_global, save_as_floats);
octave_hdf5_err hdf5_add_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
static int static_type_id(void)
octave_value full_value(void) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
std::string read_hdf5_data(std::istream &is, const std::string &, bool &global, octave_value &tc, std::string &doc, const string_vector &argv, int argv_idx, int argc)
identity matrix If supplied two scalar respectively For allows like xample val
const octave_hdf5_id octave_H5S_ALL
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector d)
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
const octave_hdf5_id octave_H5E_DEFAULT
void resize(int n, int fill_value=0)
void error(const char *fmt,...)
bool is_perm_matrix(void) const
octave_value resize(const dim_vector &dv, bool fill=false) const
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
bool hdf5_get_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
OCTAVE_EXPORT octave_value_list search each directory of the loadpath for element of the cell array and return the first that matches If the second optional argument return a cell array containing the list of all files that have the same name in the path If no files are found
static octave_value lookup_type(const std::string &nm)
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are empty
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
bool valid_identifier(const char *s)
bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_hdf5_id save_type_to_hdf5(save_type st)
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
#define panic_impossible()
bool hdf5_check_attr(octave_hdf5_id loc_id, const char *attr_name)
bool match(const std::string &str) const
octave_hdf5_err hdf5_read_next_data(octave_hdf5_id group_id, const char *name, void *dv)
octave_idx_type length(void) const
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
static hid_t check_hdf5_id_value(octave_hdf5_id id, const char *who)
octave_hdf5_err hdf5_add_attr(octave_hdf5_id loc_id, const char *attr_name)
bool save_hdf5_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
void warning(const char *fmt,...)
std::string type_name(void) const
charNDArray max(char d, const charNDArray &m)
static herr_t hdf5_read_next_data_internal(hid_t group_id, const char *name, void *dv)
bool check_hdf5_types(bool warn)
=val(i)}if ode{val(i)}occurs in table i
is longer than or if then or only for unique occurrences of the complete pattern(false).The default is true.If a cell array of strings ar
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
const octave_hdf5_id octave_H5P_DEFAULT
write the output to stdout if nargout is
Vector representing the dimensions (size) of an Array.
octave_hdf5_id hdf5_make_complex_type(octave_hdf5_id num_type)
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
void open(const char *name, int mode, int)
static std::string make_valid_identifier(const std::string &nm)
static void clear(octave::dynamic_library &oct_file)
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
int length(void) const
Number of dimensions.
bool is_diag_matrix(void) const