25 #if defined (HAVE_CONFIG_H) 29 #if defined (HAVE_HDF5) 74 #if defined (HAVE_HDF5) 80 error (
"%s: internal error: ID too large for hid_t", who);
82 return static_cast<hid_t
> (
id);
88 : file_id (-1), current_item (-1)
90 #if defined (HAVE_HDF5) 92 if (
mode & std::ios::in)
94 else if (
mode & std::ios::out)
96 if (
mode & std::ios::app && H5Fis_hdf5 (
name) > 0)
103 std::ios::setstate (std::ios::badbit);
115 #if defined (HAVE_HDF5) 120 std::ios::setstate (std::ios::badbit);
135 #if defined (HAVE_HDF5) 139 if (
mode & std::ios::in)
141 else if (
mode & std::ios::out)
143 if (
mode & std::ios::app && H5Fis_hdf5 (
name) > 0)
150 std::ios::setstate (std::ios::badbit);
171 if (! isalpha (
nm[0]))
174 for (
size_t i = 0;
i < nm_len;
i++)
177 retval += (isalnum (
c) ||
c ==
'_') ?
c :
'_';
192 #if defined (HAVE_HDF5) 195 if ((n = H5Tget_nmembers (t1)) != H5Tget_nmembers (t2))
198 for (
int i = 0;
i < n; ++
i)
200 hid_t mt1 = H5Tget_member_type (t1,
i);
201 hid_t mt2 = H5Tget_member_type (t2,
i);
203 if (H5Tget_class (mt1) != H5Tget_class (mt2))
223 #if defined (HAVE_HDF5) 237 #if defined (HAVE_HDF5_18) 241 H5Eget_auto (&err_func, &err_func_data);
242 H5Eset_auto (
nullptr,
nullptr);
245 hid_t attr_id = H5Aopen_name (loc_id, attr_name);
255 #if defined (HAVE_HDF5_18) 258 H5Eset_auto (err_func, err_func_data);
269 const char *attr_name,
void *buf)
271 #if defined (HAVE_HDF5) 285 #if defined (HAVE_HDF5_18) 289 H5Eget_auto (&err_func, &err_func_data);
290 H5Eset_auto (
nullptr,
nullptr);
293 hid_t attr_id = H5Aopen_name (loc_id, attr_name);
297 hid_t space_id = H5Aget_space (attr_id);
299 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
302 retval = H5Aread (attr_id, type_id, buf) >= 0;
307 #if defined (HAVE_HDF5_18) 310 H5Eset_auto (err_func, err_func_data);
328 #if defined (HAVE_HDF5) 330 hid_t type_id = H5Tcreate (H5T_COMPOUND,
sizeof (
double) * 2);
332 H5Tinsert (type_id,
"real", 0 *
sizeof (
double), num_type);
333 H5Tinsert (type_id,
"imag", 1 *
sizeof (
double), num_type);
342 #if defined (HAVE_HDF5) 359 hid_t type_class_id = -1;
361 hid_t subgroup_id = -1;
362 hid_t space_id = -1;;
385 H5Gget_objinfo (group_id,
name, 1, &info);
387 if (info.type == H5G_GROUP && ident_valid)
389 #if defined (HAVE_HDF5_18) 392 subgroup_id = H5Gopen (group_id,
name);
403 #if defined (HAVE_HDF5_18) 406 data_id = H5Dopen (subgroup_id,
"type");
415 type_id = H5Dget_type (data_id);
417 type_class_id = H5Tget_class (type_id);
419 if (type_class_id != H5T_STRING)
422 space_id = H5Dget_space (data_id);
423 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
428 int slen = H5Tget_size (type_id);
435 hid_t st_id = H5Tcopy (H5T_C_S1);
436 H5Tset_size (st_id, slen);
447 retval = (
d->tc.load_hdf5 (subgroup_id,
"value") ? 1 : -1);
452 H5Gclose (subgroup_id);
468 H5Gclose (subgroup_id);
470 retval = (
d->tc.load_hdf5 (group_id,
name) ? 1 : -1);
474 else if (info.type == H5G_DATASET && ident_valid)
477 #if defined (HAVE_HDF5_18) 480 data_id = H5Dopen (group_id,
name);
489 type_id = H5Dget_type (data_id);
491 type_class_id = H5Tget_class (type_id);
493 if (type_class_id == H5T_FLOAT)
495 space_id = H5Dget_space (data_id);
497 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
506 else if (type_class_id == H5T_INTEGER)
510 #if defined (HAVE_H5T_GET_NATIVE_TYPE) 514 switch (H5Tget_native_type (type_id, H5T_DIR_ASCEND))
516 case H5T_NATIVE_CHAR:
520 case H5T_NATIVE_SHORT:
525 case H5T_NATIVE_LONG:
529 case H5T_NATIVE_LLONG:
533 case H5T_NATIVE_UCHAR:
537 case H5T_NATIVE_USHORT:
541 case H5T_NATIVE_UINT:
542 case H5T_NATIVE_ULONG:
546 case H5T_NATIVE_ULLONG:
551 hid_t int_sign = H5Tget_sign (type_id);
553 if (int_sign == H5T_SGN_ERROR)
554 warning (
"load: can't read '%s' (unknown datatype)",
name);
557 if (int_sign == H5T_SGN_NONE)
558 int_typ.push_back (
'u');
559 int_typ.append (
"int");
561 int slen = H5Tget_size (type_id);
563 warning (
"load: can't read '%s' (unknown datatype)",
name);
569 int_typ.append (
"8 ");
573 int_typ.append (
"16 ");
577 int_typ.append (
"32 ");
581 int_typ.append (
"64 ");
585 warning (
"load: can't read '%s' (unknown datatype)",
594 warning (
"load: can't read '%s' (unknown datatype)",
name);
598 space_id = H5Dget_space (data_id);
600 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
603 int_typ.append (
"scalar");
605 int_typ.append (
"matrix");
611 else if (type_class_id == H5T_STRING)
613 else if (type_class_id == H5T_COMPOUND)
620 space_id = H5Dget_space (data_id);
621 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
635 H5Tclose (complex_type);
639 warning (
"load: can't read '%s' (unknown datatype)",
name);
650 retval = (
d->tc.load_hdf5 (group_id,
name) ? 1 : -1);
657 warning (
"load: skipping invalid identifier '%s' in hdf5 file",
663 error (
"load: error while reading hdf5 item %s",
name);
668 int comment_length = H5Gget_comment (group_id,
name, 0,
nullptr);
670 if (comment_length > 1)
673 H5Gget_comment (group_id,
name, comment_length, tdoc);
676 else if (vname !=
name)
695 #if defined (HAVE_HDF5) 710 #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) 901 hsize_t
sz =
d.length ();
904 hid_t space_hid = -1;
907 for (hsize_t
i = 0;
i <
sz;
i++)
917 space_hid = H5Screate_simple (1, &
sz,
nullptr);
918 if (space_hid < 0)
return space_hid;
919 #if defined (HAVE_HDF5_18) 928 H5Sclose (space_hid);
936 H5Sclose (space_hid);
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++)
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;
1068 if (
val.is_diag_matrix () ||
val.is_perm_matrix ()
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,
nullptr);
1091 #if defined (HAVE_HDF5_18) 1092 data_type_id = H5Dcreate (data_id,
"type", type_id, space_id,
1096 data_type_id = H5Dcreate (data_id,
"type", type_id, space_id,
1099 if (data_type_id < 0
1109 && H5Gset_comment (loc_id,
name.c_str (), doc.c_str ()) < 0)
1113 if (
retval && mark_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)
octave_value lookup_type(const std::string &nm)
octave_hdf5_err hdf5_add_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
is already an absolute the name is checked against the file system instead of Octave s loadpath In this if otherwise an empty string is returned If the first argument is a cell array of 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 int static_type_id(void)
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
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 error(const char *fmt,...)
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
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &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)
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
nd deftypefn *std::string name
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
type_info & __get_type_info__(const std::string &who)
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
bool valid_identifier(const char *s)
bool save_hdf5_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
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)
octave_hdf5_err hdf5_read_next_data(octave_hdf5_id group_id, const char *name, void *dv)
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
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)
void warning(const char *fmt,...)
charNDArray max(char d, const charNDArray &m)
static herr_t hdf5_read_next_data_internal(hid_t group_id, const char *name, void *dv)
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
bool check_hdf5_types(bool warn)
octave_idx_type length(void) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
const octave_hdf5_id octave_H5P_DEFAULT
octave_idx_type length(void) const
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)
void open(const char *name, int mode, int)
static std::string make_valid_identifier(const std::string &nm)
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