30 unsigned int open_opt, opt_sel[2] = {H5F_ACC_RDONLY, H5F_ACC_RDWR};
33 void *old_client_data;
37 if ((opt != 0) && (opt != 1)) {
38 printf(
"%s: Inproper open option selected\n", __FILE__);
45 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
46 H5Eset_auto(H5E_DEFAULT,
NULL,
NULL);
48 h5ret = H5Fis_hdf5(
file);
50 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
54 open_opt = opt_sel[ opt ];
55 if ((
id->file_id = H5Fopen(
file, open_opt, H5P_DEFAULT))
60 if ((
id->grp_id = H5Gopen1(
id->file_id,
"/")) < 0)
return 1;
93 unsigned int open_opt, opt_sel[2] = {H5F_ACC_EXCL, H5F_ACC_TRUNC};
97 if ((opt != 0) && (opt != 1)) {
98 printf(
"%s: Improper open option selected\n", __FILE__);
101 open_opt = opt_sel[ opt ];
102 if ((
id->file_id = H5Fcreate(
file, open_opt, H5P_DEFAULT, H5P_DEFAULT))
107 if ((
id->grp_id = H5Gopen1(
id->file_id,
"/")) < 0)
return 1;
143 if (H5Fclose(
id->file_id) < 0)
return 1;
144 if (H5Gclose(
id->grp_id) < 0)
return 1;
147 if (H5Gclose(
id->grp_id) < 0)
return 1;
150 if (H5Dclose(
id->dat_id) < 0)
return 1;
156 if (H5Sclose(
id->fil_space_id) < 0)
return 1;
157 if (H5Sclose(
id->mem_space_id) < 0)
return 1;
158 if (H5Tclose(
id->native_typ) < 0)
return 1;
164 printf(
"%s: Unknown or un-initialized id\n", __FILE__);
173 int h5io_info(h5io_str *
id,
char *attr_name, H5T_class_t *
class,
174 hid_t *native_typ,
int* ndim,
int *dim_siz,
int *sto_len)
242 hid_t *base_grp, spaceid, attr_datyp, attr_id;
250 &(
id->dat_id) : &(
id->grp_id);
252 printf(
"%s: no attribute entered for group information query\n",
260 if ((spaceid = H5Dget_space(*base_grp)) < 0)
return 1;
261 if ((attr_datyp = H5Dget_type(*base_grp)) < 0)
return 1;
266 if ((attr_id = H5Aopen_name(*base_grp, attr_name)) < 0)
return 1;
267 if ((spaceid = H5Aget_space(attr_id)) < 0)
return 1;
268 if ((attr_datyp = H5Aget_type(attr_id)) < 0)
return 1;
273 if ((*ndim = H5Sget_simple_extent_dims(spaceid, dims, maxdims)) < 0)
276 printf(
"%s: # dimensions of attribute: %s is > software maximum of %d\n",
280 for (indx = 0; indx < *ndim; indx++)
281 dim_siz[indx] = dims[indx];
282 if ((*native_typ = H5Tget_native_type(attr_datyp, H5T_DIR_ASCEND)) < 0)
284 if ((*
class = H5Tget_class(attr_datyp)) == -1)
return 1;
285 if ((lsto_len = H5Tget_size(attr_datyp)) <= 0)
return 1;
305 printf(
"%s: Currently, classes beyond STRING, INTEGER, and FLOAT \n",
306 "may not be fully characterized here\n");
309 printf(
"%s: Unable to handle the class for attribute: %s\n",
310 __FILE__, attr_name);
317 if (H5Sclose(spaceid) < 0)
return 1;
318 if (H5Tclose(attr_datyp) < 0)
return 1;
319 if (attr_name !=
NULL)
320 if (H5Aclose(attr_id) < 0)
return 1;
354 printf(
"%s: Cannot set to a dataset under a dataset\n", __FILE__);
360 if ((ds_id->dat_id = H5Dopen1(
id->grp_id, path_name)) < 0)
return 1;
398 printf(
"%s: Cannot set group under a dataset\n", __FILE__);
404 if ((grp_id->grp_id = H5Gopen1(
id->grp_id, path_name)) < 0)
return 1;
437 hid_t *base_grp, spaceid, attr_datyp, attr_id, native_typ;
440 int ndim, nval, idim;
445 &(
id->dat_id) : &(
id->grp_id);
446 if ((attr_id = H5Aopen_name(*base_grp, attr_name)) < 0)
return 1;
450 if ((spaceid = H5Aget_space(attr_id)) < 0)
return 1;
451 if ((ndim = H5Sget_simple_extent_dims(spaceid, dims, maxdims)) < 0)
454 printf(
"%s: # dimensions of attribute: %s is > software maximum of %d\n",
458 if ((attr_datyp = H5Aget_type(attr_id)) < 0)
return 1;
459 if ((d_class = H5Tget_class(attr_datyp)) == -1)
return 1;
460 if ((native_typ = H5Tget_native_type(attr_datyp, H5T_DIR_ASCEND)) < 0)
467 nval *= dims[idim++];
474 if (H5Aread(attr_id, native_typ,
data) < 0)
return 1;
475 hsize_t length = H5Aget_storage_size(attr_id);
476 ((
char *)
data)[length] = 0;
480 if (H5Aread(attr_id, native_typ,
data) < 0)
return 1;
491 printf(
"Unable to handle the class for attribute: %s\n", attr_name);
498 if (H5Sclose(spaceid) < 0)
return 1;
499 if (H5Aclose(attr_id) < 0)
return 1;
500 if (H5Tclose(attr_datyp) < 0)
return 1;
501 if (H5Tclose(native_typ) < 0)
return 1;
528 hid_t spaceid, ds_datyp, native_typ;
531 int ndim, nval, idim;
536 printf(
"%s: A dataset id must be passed in for this routine\n", __FILE__);
543 if ((spaceid = H5Dget_space(ds_id->dat_id)) < 0)
return 1;
544 if ((ndim = H5Sget_simple_extent_dims(spaceid, dims, maxdims)) < 0)
547 printf(
"%s: # dimensions of dataset is > software maximum of %d\n",
551 if ((ds_datyp = H5Dget_type(ds_id->dat_id)) < 0)
return 1;
552 if ((d_class = H5Tget_class(ds_datyp)) == -1)
return 1;
553 if ((native_typ = H5Tget_native_type(ds_datyp, H5T_DIR_ASCEND)) < 0)
560 nval *= dims[idim++];
568 if (H5Dread(ds_id->dat_id, native_typ, H5S_ALL, H5S_ALL,
569 H5P_DEFAULT,
data) < 0)
return 1;
571 if (H5Dread(ds_id->dat_id, native_typ, H5S_ALL, H5S_ALL,
572 H5P_DEFAULT,
data) < 0)
return 1;
577 if (H5Dread(ds_id->dat_id, native_typ, H5S_ALL, H5S_ALL,
578 H5P_DEFAULT,
data) < 0)
return 1;
589 printf(
"Unable to handle the class for dataset\n");
596 if (H5Sclose(spaceid) < 0)
return 1;
597 if (H5Tclose(ds_datyp) < 0)
return 1;
598 if (H5Tclose(native_typ) < 0)
return 1;
641 int changed_count, indx;
646 printf(
"%s: A dataset id must be passed in for this routine\n", __FILE__);
658 if ((ds_id->fil_space_id = H5Dget_space(ds_id->dat_id)) < 0)
return 1;
659 if ((ds_id->prev_ndim =
660 H5Sget_simple_extent_dims(ds_id->fil_space_id, dims, maxdims)) < 0)
663 printf(
"%s: # dimensions of dataset is > software maximum of %d\n",
667 if ((ds_datyp = H5Dget_type(ds_id->dat_id)) < 0)
return 1;
668 if ((d_class = H5Tget_class(ds_datyp)) == -1)
return 1;
669 if ((ds_id->native_typ =
670 H5Tget_native_type(ds_datyp, H5T_DIR_ASCEND)) < 0)
675 if (H5Tclose(ds_datyp) < 0)
return 1;
693 printf(
"Unable to handle the class for dataset\n");
700 for (indx = 0; indx < ds_id->prev_ndim; indx++) {
701 dim_arr_mem[indx] = *(
count + indx);
702 *(ds_id->prev_count + indx) = *(
count + indx);
706 lcount[indx] = *(
count + indx);
708 if ((ds_id->mem_space_id =
709 H5Screate_simple(ds_id->prev_ndim, dim_arr_mem, dim_arr_mem)) < 0)
712 if (H5Sselect_hyperslab(ds_id->mem_space_id, H5S_SELECT_SET,
713 lstart, stride, lcount, block) < 0)
return 1;
717 if ((ds_id->fil_space_id = H5Dget_space(ds_id->dat_id)) < 0)
return 1;
729 for (indx = 0; indx < ds_id->prev_ndim; indx++)
730 if (*(
count + indx) != *(ds_id->prev_count + indx))
733 if (changed_count == 1) {
737 if (H5Sclose(ds_id->mem_space_id) < 0)
return 1;
739 for (indx = 0; indx < ds_id->prev_ndim; indx++) {
740 dim_arr_mem[indx] = *(
count + indx);
741 *(ds_id->prev_count + indx) = *(
count + indx);
745 lcount[indx] = *(
count + indx);
747 if ((ds_id->mem_space_id =
748 H5Screate_simple(ds_id->prev_ndim, dim_arr_mem, dim_arr_mem)) < 0)
751 if (H5Sselect_hyperslab(ds_id->mem_space_id, H5S_SELECT_SET,
752 lstart, stride, lcount, block) < 0)
return 1;
758 for (indx = 0; indx < ds_id->prev_ndim; indx++) {
759 lstart[indx] = *(
start + indx);
763 lcount[indx] = *(
count + indx);
765 if (H5Sselect_hyperslab(ds_id->fil_space_id, H5S_SELECT_SET,
766 lstart, stride, lcount, block) < 0)
return 1;
770 if (H5Dread(ds_id->dat_id, ds_id->native_typ, ds_id->mem_space_id,
771 ds_id->fil_space_id, H5P_DEFAULT, (
void *)
data) < 0)
return 1;
806 printf(
"%s: Cannot set group under a dataset\n", __FILE__);
812 if ((grp_id->grp_id = H5Gcreate1(
id->grp_id, grp_nam, 0)) < 0)
822 int *dim_siz, h5io_str *ds_id)
889 printf(
"%s: Cannot create a dataset under a dataset\n", __FILE__);
896 printf(
"%s: The created dataset cannot currently exceed %d dimensions\n",
900 for (idim = 0; idim < ndim; idim++)
901 ldim_siz[idim] = dim_siz[idim];
905 if ((fil_space_id = H5Screate_simple(ndim, ldim_siz, ldim_siz)) < 0)
910 if ((ds_id->dat_id = H5Dcreate1(
id->grp_id, ds_name,
type,
911 fil_space_id, H5P_DEFAULT)) < 0)
return 1;
918 if (H5Sclose(fil_space_id) < 0)
return 1;
923 int ndim,
int *dim_siz,
void *
data)
961 hid_t *base_grp, fil_spac_id, attr_id, native_type;
968 printf(
"%s: The created dataset cannot currently exceed %d dimensions\n",
976 if ((fil_spac_id = H5Screate(H5S_SCALAR)) < 0)
return 1;
978 for (idim = 0; idim < ndim; idim++)
979 ldim_siz[idim] = dim_siz[idim];
980 if ((fil_spac_id = H5Screate_simple(ndim, ldim_siz, ldim_siz)) < 0)
987 &(
id->dat_id) : &(
id->grp_id);
988 if ((attr_id = H5Acreate1(*base_grp, attr_name, out_type, fil_spac_id,
989 H5P_DEFAULT)) < 0)
return 1;
991 if ((native_type = H5Tget_native_type(out_type, H5T_DIR_ASCEND)) < 0)
996 if (H5Awrite(attr_id, native_type,
data) < 0)
return 1;
1000 if (H5Aclose(attr_id) < 0)
return 1;
1001 if (H5Sclose(fil_spac_id) < 0)
return 1;
1002 if (H5Tclose(native_type) < 0)
return 1;
1044 hid_t *base_grp, fil_spac_id, attr_id, attr_typ;
1052 printf(
"%s: The created dataset cannot currently exceed %d dimensions\n",
1060 if ((fil_spac_id = H5Screate(H5S_SCALAR)) < 0)
return 1;
1061 lstr_len = (str_len <= 0) ? strlen(
data) : str_len;
1063 for (idim = 0; idim < ndim; idim++)
1064 ldim_siz[idim] = dim_siz[idim];
1066 if ((fil_spac_id = H5Screate_simple(ndim, ldim_siz, ldim_siz)) < 0)
1073 &(
id->dat_id) : &(
id->grp_id);
1075 if ((attr_typ = H5Tcopy(H5T_C_S1)) < 0)
return 1;
1076 if (H5Tset_size(attr_typ, lstr_len) < 0)
return 1;
1077 if (H5Tset_strpad(attr_typ, H5T_STR_NULLTERM) < 0)
return 1;
1079 if ((attr_id = H5Acreate1(*base_grp, attr_name, attr_typ, fil_spac_id,
1080 H5P_DEFAULT)) < 0)
return 1;
1084 if (H5Awrite(attr_id, attr_typ, (
void *)
data) < 0)
return 1;
1088 if (H5Aclose(attr_id) < 0)
return 1;
1089 if (H5Sclose(fil_spac_id) < 0)
return 1;
1090 if (H5Tclose(attr_typ) < 0)
return 1;
1117 hid_t spaceid, ds_datyp, native_typ;
1119 H5T_class_t d_class;
1125 printf(
"%s: A dataset id must be passed in for this routine\n", __FILE__);
1131 if ((spaceid = H5Dget_space(ds_id->dat_id)) < 0)
return 1;
1132 if ((ndim = H5Sget_simple_extent_dims(spaceid, dims, maxdims)) < 0)
1135 printf(
"%s: # dimensions of dataset is > software maximum of %d\n",
1139 if ((ds_datyp = H5Dget_type(ds_id->dat_id)) < 0)
return 1;
1140 if ((d_class = H5Tget_class(ds_datyp)) == -1)
return 1;
1141 if ((native_typ = H5Tget_native_type(ds_datyp, H5T_DIR_ASCEND)) < 0)
1149 if (H5Dwrite(ds_id->dat_id, native_typ, H5S_ALL, H5S_ALL,
1150 H5P_DEFAULT,
data) < 0)
return 1;
1162 printf(
"Unable to handle the current class for dataset\n");
1169 if (H5Sclose(spaceid) < 0)
return 1;
1170 if (H5Tclose(ds_datyp) < 0)
return 1;
1171 if (H5Tclose(native_typ) < 0)
return 1;
1208 H5T_class_t d_class;
1210 int changed_count, indx;
1215 printf(
"%s: A dataset id must be passed in for this routine\n", __FILE__);
1228 if ((ds_id->fil_space_id = H5Dget_space(ds_id->dat_id)) < 0)
return 1;
1229 if ((ds_id->prev_ndim =
1230 H5Sget_simple_extent_dims(ds_id->fil_space_id, dims, maxdims)) < 0)
1233 printf(
"%s: # dimensions of dataset is > software maximum of %d\n",
1237 if ((ds_datyp = H5Dget_type(ds_id->dat_id)) < 0)
return 1;
1238 if ((d_class = H5Tget_class(ds_datyp)) == -1)
return 1;
1239 if ((ds_id->native_typ =
1240 H5Tget_native_type(ds_datyp, H5T_DIR_ASCEND)) < 0)
1245 if (H5Tclose(ds_datyp) < 0)
return 1;
1263 printf(
"Unable to handle the class for dataset\n");
1270 for (indx = 0; indx < ds_id->prev_ndim; indx++) {
1271 dim_arr_mem[indx] = *(
count + indx);
1272 *(ds_id->prev_count + indx) = *(
count + indx);
1276 lcount[indx] = *(
count + indx);
1278 if ((ds_id->mem_space_id =
1279 H5Screate_simple(ds_id->prev_ndim, dim_arr_mem, dim_arr_mem)) < 0)
1282 if (H5Sselect_hyperslab(ds_id->mem_space_id, H5S_SELECT_SET,
1283 lstart, stride, lcount, block) < 0)
return 1;
1287 if ((ds_id->fil_space_id = H5Dget_space(ds_id->dat_id)) < 0)
return 1;
1299 for (indx = 0; indx < ds_id->prev_ndim; indx++)
1300 if (*(
count + indx) != *(ds_id->prev_count + indx))
1303 if (changed_count == 1) {
1307 if (H5Sclose(ds_id->mem_space_id) < 0)
return 1;
1309 for (indx = 0; indx < ds_id->prev_ndim; indx++) {
1310 dim_arr_mem[indx] = *(
count + indx);
1311 *(ds_id->prev_count + indx) = *(
count + indx);
1315 lcount[indx] = *(
count + indx);
1317 if ((ds_id->mem_space_id =
1318 H5Screate_simple(ds_id->prev_ndim, dim_arr_mem, dim_arr_mem)) < 0)
1321 if (H5Sselect_hyperslab(ds_id->mem_space_id, H5S_SELECT_SET,
1322 lstart, stride, lcount, block) < 0)
return 1;
1327 for (indx = 0; indx < ds_id->prev_ndim; indx++) {
1328 lstart[indx] = *(
start + indx);
1332 lcount[indx] = *(
count + indx);
1334 if (H5Sselect_hyperslab(ds_id->fil_space_id, H5S_SELECT_SET,
1335 lstart, stride, lcount, block) < 0)
return 1;
1339 if (H5Dwrite(ds_id->dat_id, ds_id->native_typ, ds_id->mem_space_id,
1340 ds_id->fil_space_id, H5P_DEFAULT, (
void *)
data) < 0)
return 1;
1379 printf(
"%s:%d - failed to open the %s dataset\n", __FILE__,
1380 __LINE__, path_name);
1384 printf(
"%s:%d - failed to read the %s dataset\n", __FILE__,
1385 __LINE__, path_name);
1389 printf(
"%s:%d - failed to close the %s dataset\n", __FILE__,
1390 __LINE__, path_name);
1434 printf(
"%s:%d - failed to open the %s dataset\n", __FILE__,
1435 __LINE__, path_name);
1439 printf(
"%s:%d - failed to read the %s dataset\n", __FILE__,
1440 __LINE__, path_name);
1444 printf(
"%s:%d - failed to close the %s dataset\n", __FILE__,
1445 __LINE__, path_name);
1478 hid_t *base_grp, attr_id;
1479 H5E_auto_t old_func;
1480 void *old_client_data;
1484 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
1485 H5Eset_auto(H5E_DEFAULT,
NULL,
NULL);
1490 &(
id->dat_id) : &(
id->grp_id);
1492 if ((attr_id = H5Aopen_name(*base_grp, attr_name)) < 0) {
1499 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
1541 static char **lo_names;
1542 static int *ltypes, ln_obj = 0;
1550 printf(
"%s, %d: Error: A dataset cannot be the input id\n",
1551 __FILE__, __LINE__);
1559 for (
i = 0;
i < ln_obj;
i++)
1567 if (H5Gget_info(
id->grp_id, &g_info) < 0) {
1570 *n_obj = g_info.nlinks;
1572 lo_names = (
char **) malloc(*n_obj *
sizeof (
char *));
1573 ltypes = (
int *) malloc(*n_obj *
sizeof (
int));
1577 for (
i = 0;
i < *n_obj;
i++) {
1578 if ((len0 = H5Gget_objname_by_idx(
id->grp_id,
i,
NULL, 500))
1580 printf(
"%s, %d - H5Gget_objname_by_idx 1 failed\n",
1581 __FILE__, __LINE__);
1585 lo_names[
i] = (
char *) malloc(len0 *
sizeof (
char));
1586 if ((len = H5Gget_objname_by_idx(
id->grp_id,
i, lo_names[
i], len0))
1588 printf(
"%s, %d - H5Gget_objname_by_idx failed\n",
1589 __FILE__, __LINE__);
1592 if (H5Gget_objinfo(
id->grp_id, lo_names[
i], 0, &info) < 0) {
1593 printf(
"%s, %d - H5Gget_objinfo failed\n",
1594 __FILE__, __LINE__);
1597 *(ltypes +
i) = info.type;
1599 *o_names = lo_names;
1632 char *cptr, *tok, str_wrk[FILENAME_MAX], **grp_names;
1633 int32_t nelts, ielt, elt_num, ngid, nobj, iobj, igrp, found_elt;
1636 h5io_str *ar_gid, sgid;
1641 printf(
"%s, %d, E: h5io_inq_path, a dataset cannot be the input id\n",
1642 __FILE__, __LINE__);
1651 while ((tok = strtok(cptr,
"/")) !=
NULL) {
1661 ar_gid = (h5io_str *) malloc(ngid *
sizeof ( h5io_str));
1665 for (ielt = 0; ielt < nelts; ielt++) {
1667 if ((tok = strtok(cptr,
"/")) ==
NULL) {
1668 printf(
"%s, %d, E: h5io_inq_path, tokens exhausted unexpectedly\n",
1669 __FILE__, __LINE__);
1674 printf(
"%s, %d: h5io_inq_path problem, exiting\n", __FILE__, __LINE__);
1680 for (iobj = 0; iobj < nobj; iobj++) {
1681 if (strcmp(grp_names[iobj], tok) == 0) {
1688 if (found_elt == 0) {
1691 for (igrp = 0; igrp < (ielt - 1); igrp++)
1697 if ((ielt < (nelts - 1)) && (types[elt_num] != H5G_GROUP)) {
1698 printf(
"%s, %d, E: h5io_inq_path\n", __FILE__, __LINE__);
1699 printf(
" non-group found before the last element in the path\n");
1700 printf(
" path: %s\n",
path);
1701 printf(
" non-group element: %s\n", grp_names[elt_num]);
1707 if (ielt < (nelts - 1)) {
1709 printf(
"%s, %d: h5io_inq_path problem, exiting\n",
1710 __FILE__, __LINE__);
1714 sgid = ar_gid[ielt];
1721 for (igrp = 0; igrp < ngid; igrp++)