62static int visit_link_cb(hid_t group_id,
const char *name,
const H5L_info_t *oinfo,
67visit_obj_cb(hid_t o_id,
const char *name,
const H5O_info_t *oinfo,
71static herr_t attr_info_dimscale(hid_t loc_id,
const char *name,
const H5A_info_t *ainfo,
void *opdata);
91 bool *ignore_attr_ptr)
97 *ignore_attr_ptr =
false;
99 if ((attrid = H5Aopen_by_idx(dset,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC,(hsize_t)index, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
100 string msg =
"unable to open attribute by index ";
101 throw InternalErr(__FILE__, __LINE__, msg);
105 ssize_t name_size = H5Aget_name(attrid, 0,
nullptr);
108 string msg =
"unable to obtain the size of the hdf5 attribute name ";
109 throw InternalErr(__FILE__, __LINE__, msg);
112 vector<char> attr_name;
113 attr_name.resize(name_size+1);
115 if ((H5Aget_name(attrid, name_size+1, attr_name.data())) < 0) {
117 string msg =
"unable to obtain the hdf5 attribute name ";
118 throw InternalErr(__FILE__, __LINE__, msg);
123 if ((ty_id = H5Aget_type(attrid)) < 0) {
124 string msg =
"unable to obtain hdf5 datatype for the attribute ";
125 string attrnamestr(attr_name.begin(),attr_name.end());
128 throw InternalErr(__FILE__, __LINE__, msg);
131 H5T_class_t ty_class = H5Tget_class(ty_id);
133 string msg =
"cannot get hdf5 attribute datatype class for the attribute ";
134 string attrnamestr(attr_name.begin(),attr_name.end());
137 throw InternalErr(__FILE__, __LINE__, msg);
150 if ((ty_class == H5T_TIME) || (ty_class == H5T_BITFIELD)
151 || (ty_class == H5T_OPAQUE) || (ty_class == H5T_ENUM)
152 || (ty_class == H5T_REFERENCE) ||(ty_class == H5T_COMPOUND)
153 || (ty_class == H5T_VLEN) || (ty_class == H5T_ARRAY)){
155 *ignore_attr_ptr =
true;
162 if (
false == is_dap4) {
163 if((ty_class == H5T_INTEGER) && (H5Tget_size(ty_id)== 8)) {
164 *ignore_attr_ptr =
true;
171 if (
true == is_dap4 && HDF5RequestHandler::get_default_handle_dimension() ==
true) {
173 string attr_name_str(attr_name.begin(),attr_name.end()-1);
174 if(attr_name_str ==
"CLASS" || attr_name_str ==
"NAME" || attr_name_str ==
"_Netcdf4Dimid"
175 || attr_name_str ==
"_nc3_strict" || attr_name_str==
"_NCProperties" || attr_name_str==
"_Netcdf4Coordinates") {
176 *ignore_attr_ptr =
true;
182 hid_t aspace_id = -1;
183 if ((aspace_id = H5Aget_space(attrid)) < 0) {
184 string msg =
"cannot get hdf5 dataspace id for the attribute ";
185 string attrnamestr(attr_name.begin(),attr_name.end());
188 throw InternalErr(__FILE__, __LINE__, msg);
196 int ndims = H5Sget_simple_extent_ndims(aspace_id);
198 string msg =
"cannot get hdf5 dataspace number of dimension for attribute ";
199 string attrnamestr(attr_name.begin(),attr_name.end());
203 throw InternalErr(__FILE__, __LINE__, msg);
208 string msg =
"number of dimensions exceeds allowed for attribute ";
209 string attrnamestr(attr_name.begin(),attr_name.end());
213 throw InternalErr(__FILE__, __LINE__, msg);
216 vector<hsize_t> size(ndims);
217 vector<hsize_t> maxsize(ndims);
221 if (H5Sget_simple_extent_dims(aspace_id, size.data(), maxsize.data())<0){
222 string msg =
"cannot obtain the dim. info for the attribute ";
223 string attrnamestr(attr_name.begin(),attr_name.end());
227 throw InternalErr(__FILE__, __LINE__, msg);
233 for (
int j = 0; j < ndims; j++)
237 size_t ty_size = H5Tget_size(ty_id);
239 string msg =
"cannot obtain the dtype size for the attribute ";
240 string attrnamestr(attr_name.begin(),attr_name.end());
244 throw InternalErr(__FILE__, __LINE__, msg);
247 size_t need = nelmts * H5Tget_size(ty_id);
250 hid_t memtype = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
252 string msg =
"cannot obtain the memory dtype for the attribute ";
253 string attrnamestr(attr_name.begin(),attr_name.end());
257 throw InternalErr(__FILE__, __LINE__, msg);
261 (*attr_inst_ptr).type = memtype;
262 (*attr_inst_ptr).ndims = ndims;
263 (*attr_inst_ptr).nelmts = nelmts;
264 (*attr_inst_ptr).need = need;
265 strncpy((*attr_inst_ptr).name, attr_name.data(), name_size+1);
268 for (
int j = 0; j < ndims; j++) {
269 (*attr_inst_ptr).size[j] = (
int)(size[j]);
272 if(H5Sclose(aspace_id)<0) {
274 throw InternalErr(__FILE__,__LINE__,
"Cannot close HDF5 dataspace ");
296 BESDEBUG(
"h5",
">get_dap_type(): type=" << type << endl);
297 H5T_class_t class_t = H5Tget_class(type);
298 if (H5T_NO_CLASS == class_t)
299 throw InternalErr(__FILE__, __LINE__,
300 "The HDF5 datatype doesn't belong to any Class.");
305 size = H5Tget_size(type);
307 throw InternalErr(__FILE__, __LINE__,
308 "size of datatype is invalid");
311 sign = H5Tget_sign(type);
313 throw InternalErr(__FILE__, __LINE__,
314 "sign of datatype is invalid");
317 BESDEBUG(
"h5",
"=get_dap_type(): H5T_INTEGER" <<
318 " sign = " << sign <<
319 " size = " << size <<
323 if(
true == is_dap4) {
324 if (sign == H5T_SGN_NONE)
330 if (sign == H5T_SGN_NONE)
338 if (sign == H5T_SGN_NONE)
345 if (sign == H5T_SGN_NONE)
353 if (
true == is_dap4) {
354 if (sign == H5T_SGN_NONE)
366 size = H5Tget_size(type);
368 throw InternalErr(__FILE__, __LINE__,
369 "size of the datatype is invalid");
372 BESDEBUG(
"h5",
"=get_dap_type(): FLOAT size = " << size << endl);
381 BESDEBUG(
"h5",
"<get_dap_type(): H5T_STRING" << endl);
385 BESDEBUG(
"h5",
"<get_dap_type(): H5T_REFERENCE" << endl);
391 BESDEBUG(
"h5",
"<get_dap_type(): COMPOUND" << endl);
398 BESDEBUG(
"h5",
"<get_dap_type(): Unmappable Type" << endl);
399 return "Unmappable Type";
414 hid_t fileid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
416 string msg =
"cannot open the HDF5 file ";
417 string filenamestr(filename);
419 throw InternalErr(__FILE__, __LINE__, msg);
436 if (H5Fclose(fid) < 0)
437 throw Error(unknown_error,
438 string(
"Could not close the HDF5 file."));
455 BESDEBUG(
"h5",
">get_dataset()" << endl);
459 if ((dset = H5Dopen(pid, dname.c_str(),H5P_DEFAULT)) < 0) {
460 string msg =
"cannot open the HDF5 dataset ";
462 throw InternalErr(__FILE__, __LINE__, msg);
467 if ((dtype = H5Dget_type(dset)) < 0) {
469 string msg =
"cannot get the the datatype of HDF5 dataset ";
471 throw InternalErr(__FILE__, __LINE__, msg);
475 H5T_class_t ty_class = H5Tget_class(dtype);
479 string msg =
"cannot get the datatype class of HDF5 dataset ";
481 throw InternalErr(__FILE__, __LINE__, msg);
487 if ((ty_class == H5T_TIME) || (ty_class == H5T_BITFIELD)
488 || (ty_class == H5T_OPAQUE) || (ty_class == H5T_ENUM) || (ty_class == H5T_VLEN)) {
489 string msg =
"unexpected datatype of HDF5 dataset ";
491 throw InternalErr(__FILE__, __LINE__, msg);
495 if ((dspace = H5Dget_space(dset)) < 0) {
498 string msg =
"cannot get the the dataspace of HDF5 dataset ";
500 throw InternalErr(__FILE__, __LINE__, msg);
508 int ndims = H5Sget_simple_extent_ndims(dspace);
513 string msg =
"cannot get hdf5 dataspace number of dimension for dataset ";
515 throw InternalErr(__FILE__, __LINE__, msg);
520 string msg =
"number of dimensions exceeds allowed for dataset ";
525 throw InternalErr(__FILE__, __LINE__, msg);
528 vector<hsize_t>size(ndims);
529 vector<hsize_t>maxsize(ndims);
532 if (H5Sget_simple_extent_dims(dspace, size.data(), maxsize.data())<0){
533 string msg =
"cannot obtain the dim. info for the dataset ";
538 throw InternalErr(__FILE__, __LINE__, msg);
544 for (
int j = 0; j < ndims; j++)
548 size_t dtype_size = H5Tget_size(dtype);
549 if (dtype_size == 0) {
550 string msg =
"cannot obtain the data type size for the dataset ";
555 throw InternalErr(__FILE__, __LINE__, msg);
558 size_t need = nelmts * dtype_size;
560 hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
562 string msg =
"cannot obtain the memory data type for the dataset ";
567 throw InternalErr(__FILE__, __LINE__, msg);
570 (*dt_inst_ptr).type = memtype;
571 (*dt_inst_ptr).ndims = ndims;
572 (*dt_inst_ptr).nelmts = nelmts;
573 (*dt_inst_ptr).need = need;
574 strncpy((*dt_inst_ptr).name, dname.c_str(), dname.length());
575 (*dt_inst_ptr).name[dname.length()] =
'\0';
576 for (
int j = 0; j < ndims; j++)
577 (*dt_inst_ptr).size[j] = (
int)(size[j]);
579 if(H5Tclose(dtype)<0) {
582 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 datatype.");
585 if(H5Sclose(dspace)<0) {
587 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 dataspace.");
590 if(H5Dclose(dset)<0) {
591 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 dataset.");
610void get_dataset_dmr(
const hid_t file_id, hid_t pid,
const string &dname,
DS_t * dt_inst_ptr,
bool use_dimscale,
bool &is_pure_dim, vector<link_info_t> &hdf5_hls)
613 BESDEBUG(
"h5",
">get_dataset()" << endl);
617 if ((dset = H5Dopen(pid, dname.c_str(),H5P_DEFAULT)) < 0) {
618 string msg =
"cannot open the HDF5 dataset ";
620 throw InternalErr(__FILE__, __LINE__, msg);
625 if ((dtype = H5Dget_type(dset)) < 0) {
627 string msg =
"cannot get the the datatype of HDF5 dataset ";
629 throw InternalErr(__FILE__, __LINE__, msg);
633 H5T_class_t ty_class = H5Tget_class(dtype);
637 string msg =
"cannot get the datatype class of HDF5 dataset ";
639 throw InternalErr(__FILE__, __LINE__, msg);
645 if ((ty_class == H5T_TIME) || (ty_class == H5T_BITFIELD)
646 || (ty_class == H5T_OPAQUE) || (ty_class == H5T_ENUM) || (ty_class == H5T_VLEN)) {
647 string msg =
"unexpected datatype of HDF5 dataset ";
649 throw InternalErr(__FILE__, __LINE__, msg);
653 if ((dspace = H5Dget_space(dset)) < 0) {
656 string msg =
"cannot get the the dataspace of HDF5 dataset ";
658 throw InternalErr(__FILE__, __LINE__, msg);
666 int ndims = H5Sget_simple_extent_ndims(dspace);
671 string msg =
"cannot get hdf5 dataspace number of dimension for dataset ";
673 throw InternalErr(__FILE__, __LINE__, msg);
678 string msg =
"number of dimensions exceeds allowed for dataset ";
683 throw InternalErr(__FILE__, __LINE__, msg);
686 vector<hsize_t>size(ndims);
687 vector<hsize_t>maxsize(ndims);
690 if (H5Sget_simple_extent_dims(dspace, size.data(), maxsize.data())<0){
691 string msg =
"cannot obtain the dim. info for the dataset ";
696 throw InternalErr(__FILE__, __LINE__, msg);
702 for (
int j = 0; j < ndims; j++)
706 size_t dtype_size = H5Tget_size(dtype);
707 if (dtype_size == 0) {
708 string msg =
"cannot obtain the data type size for the dataset ";
713 throw InternalErr(__FILE__, __LINE__, msg);
716 size_t need = nelmts * dtype_size;
718 hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
720 string msg =
"cannot obtain the memory data type for the dataset ";
725 throw InternalErr(__FILE__, __LINE__, msg);
728 (*dt_inst_ptr).type = memtype;
729 (*dt_inst_ptr).ndims = ndims;
730 (*dt_inst_ptr).nelmts = nelmts;
731 (*dt_inst_ptr).need = need;
732 strncpy((*dt_inst_ptr).name, dname.c_str(), dname.length());
733 (*dt_inst_ptr).name[dname.length()] =
'\0';
734 for (
int j = 0; j < ndims; j++)
735 (*dt_inst_ptr).size[j] = (
int)(size[j]);
738 if(
true == use_dimscale) {
739 BESDEBUG(
"h5",
"<h5get.cc: get_dataset() use dim scale is true." << endl);
742 bool is_dimscale =
false;
747 bool has_ds_attr =
false;
750 has_ds_attr = has_dimscale_attr(dset);
756 throw InternalErr(__FILE__, __LINE__,
"Fail to check dim. scale.");
759 if(
true == has_ds_attr) {
767 int dim_attr_mark[3];
768 for(
int i = 0;i<3;i++)
769 dim_attr_mark[i] = 0;
773 herr_t ret = H5Aiterate2(dset, H5_INDEX_NAME, H5_ITER_INC,
nullptr, attr_info_dimscale, dim_attr_mark);
775 string msg =
"cannot interate the attributes of the dataset ";
780 throw InternalErr(__FILE__, __LINE__, msg);
783 for (
int i = 0; i<3;i++)
784 BESDEBUG(
"h5",
"dim_attr_mark is "<<dim_attr_mark[i] <<endl);
792 if ((dim_attr_mark[0] && !dim_attr_mark[1]) || dim_attr_mark[2])
794 else if(dim_attr_mark[1])
799 if (
true == is_dimscale) {
800 BESDEBUG(
"h5",
"<h5get.cc: dname is " << dname << endl);
801 BESDEBUG(
"h5",
"<h5get.cc: get_dataset() this is dim scale." << endl);
802 BESDEBUG(
"h5",
"<h5get.cc: dataset storage size is: " <<H5Dget_storage_size(dset)<< endl);
810 (*dt_inst_ptr).dimnames.push_back(dname.substr(dname.find_last_of(
"/")+1));
811 (*dt_inst_ptr).dimnames_path.push_back(dname);
820 else if(
false == is_pure_dim)
821 obtain_dimnames(file_id,dset,ndims,dt_inst_ptr,hdf5_hls);
824 if(H5Tclose(dtype)<0) {
827 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 datatype.");
830 if(H5Sclose(dspace)<0) {
832 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 dataspace.");
835 if(H5Dclose(dset)<0) {
836 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 dataset.");
851 if (H5Tget_class(h5type) == H5T_STRING)
873 unsigned short *tusp;
884 switch (H5Tget_class(type)) {
888 size_t size = H5Tget_size(type);
890 throw InternalErr(__FILE__, __LINE__,
891 "size of datatype is invalid");
894 H5T_sign_t sign = H5Tget_sign(type);
896 throw InternalErr(__FILE__, __LINE__,
897 "sign of datatype is invalid");
900 BESDEBUG(
"h5",
"=get_dap_type(): H5T_INTEGER" <<
901 " sign = " << sign <<
902 " size = " << size <<
912 if(sign == H5T_SGN_NONE) {
913 gp.ucp = (
unsigned char *) sm_buf;
914 unsigned char tuchar = *(gp.ucp + loc);
915 snprintf(rep.data(), 32,
"%u", tuchar);
919 gp.tcp = (
char *) sm_buf;
920 snprintf(rep.data(), 32,
"%d", *(gp.tcp + loc));
924 else if (size == 2) {
926 if(sign == H5T_SGN_NONE) {
927 gp.tusp = (
unsigned short *) sm_buf;
928 snprintf(rep.data(), 32,
"%hu", *(gp.tusp + loc));
932 gp.tsp = (
short *) sm_buf;
933 snprintf(rep.data(), 32,
"%hd", *(gp.tsp + loc));
938 else if (size == 4) {
940 if(sign == H5T_SGN_NONE) {
941 gp.tuip = (
unsigned int *) sm_buf;
942 snprintf(rep.data(), 32,
"%u", *(gp.tuip + loc));
946 gp.tip = (
int *) sm_buf;
947 snprintf(rep.data(), 32,
"%d", *(gp.tip + loc));
950 else if (size == 8) {
952 if(sign == H5T_SGN_NONE) {
953 gp.tulp = (
unsigned long *) sm_buf;
954 snprintf(rep.data(), 32,
"%lu", *(gp.tulp + loc));
957 gp.tlp = (
long *) sm_buf;
958 snprintf(rep.data(), 32,
"%ld", *(gp.tlp + loc));
962 throw InternalErr(__FILE__, __LINE__,
"Unsupported integer type, check the size of datatype.");
971 if (H5Tget_size(type) == 4) {
973 float attr_val = *(
float*)sm_buf;
974 bool is_a_fin = isfinite(attr_val);
977 gp.tfp = (
float *) sm_buf;
978 int ll = snprintf(gps, 30,
"%.10g", *(gp.tfp + loc));
983 if (!strchr(gps,
'.') && !strchr(gps,
'e') && !strchr(gps,
'E')
984 && (
true == is_a_fin)){
989 snprintf(rep.data(), 32,
"%s", gps);
991 else if (H5Tget_size(type) == 8) {
993 double attr_val = *(
double*)sm_buf;
994 bool is_a_fin = isfinite(attr_val);
995 gp.tdp = (
double *) sm_buf;
996 int ll = snprintf(gps, 30,
"%.17g", *(gp.tdp + loc));
1000 if (!strchr(gps,
'.') && !strchr(gps,
'e')&& !strchr(gps,
'E')
1001 && (
true == is_a_fin)) {
1005 snprintf(rep.data(), 32,
"%s", gps);
1007 else if (H5Tget_size(type) == 0){
1008 throw InternalErr(__FILE__, __LINE__,
"H5Tget_size() failed.");
1014 size_t str_size = H5Tget_size(type);
1015 if(H5Tis_variable_str(type)>0) {
1016 throw InternalErr(__FILE__, __LINE__,
1017 "print_attr function doesn't handle variable length string, variable length string should be handled separately.");
1020 throw InternalErr(__FILE__, __LINE__,
"H5Tget_size() failed.");
1022 BESDEBUG(
"h5",
"=print_attr(): H5T_STRING sm_buf=" << (
char *) sm_buf
1023 <<
" size=" << str_size << endl);
1028 rep.resize(str_size);
1029 strncpy(rep.data(), (
char *) sm_buf, str_size);
1036 char *buf =
nullptr;
1041 buf =
new char[str_size + 1];
1042 strncpy(buf.data(), (
char *) sm_buf, str_size);
1043 buf[str_size] =
'\0';
1045 rep.resize(str_size+3);
1046 snprintf(rep.data(), str_size + 3,
"%s", buf);
1047 rep[str_size + 2] =
'\0';
1048 delete[] buf; buf = 0;
1051 if( buf )
delete[] buf;
1062 string rep_str(rep.begin(),rep.end());
1066D4AttributeType daptype_strrep_to_dap4_attrtype(
const string & s){
1070 else if (s ==
"Int8")
1072 else if (s ==
"UInt8")
1073 return attr_uint8_c;
1074 else if (s ==
"Int16")
1075 return attr_int16_c;
1076 else if (s ==
"UInt16")
1077 return attr_uint16_c;
1078 else if (s ==
"Int32")
1079 return attr_int32_c;
1080 else if (s ==
"UInt32")
1081 return attr_uint32_c;
1082 else if (s ==
"Int64")
1083 return attr_int64_c;
1084 else if (s ==
"UInt64")
1085 return attr_uint64_c;
1086 else if (s ==
"Float32")
1087 return attr_float32_c;
1088 else if (s ==
"Float64")
1089 return attr_float64_c;
1090 else if (s ==
"String")
1092 else if (s ==
"Url")
1115BaseType *Get_bt(
const string &vname,
1116 const string &vpath,
1117 const string &dataset,
1118 hid_t datatype,
bool is_dap4)
1120 BaseType *btp =
nullptr;
1124 BESDEBUG(
"h5",
">Get_bt varname=" << vname <<
" datatype=" << datatype
1128 H5T_sign_t sign = H5T_SGN_ERROR;
1129 switch (H5Tget_class(datatype)) {
1133 size = H5Tget_size(datatype);
1134 sign = H5Tget_sign(datatype);
1135 BESDEBUG(
"h5",
"=Get_bt() H5T_INTEGER size = " << size <<
" sign = "
1138 if (sign == H5T_SGN_ERROR) {
1139 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the sign type of the integer");
1142 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
1144 else if (size == 1) {
1146 if (sign == H5T_SGN_2) {
1147 if (
false == is_dap4)
1148 btp =
new HDF5Int16(vname, vpath, dataset);
1150 btp =
new HDF5Int8(vname,vpath,dataset);
1153 btp =
new HDF5Byte(vname, vpath,dataset);
1155 else if (size == 2) {
1156 if (sign == H5T_SGN_2)
1157 btp =
new HDF5Int16(vname, vpath,dataset);
1161 else if (size == 4) {
1162 if (sign == H5T_SGN_2){
1163 btp =
new HDF5Int32(vname, vpath,dataset);
1168 else if (size == 8) {
1169 if(
true == is_dap4) {
1170 if(sign == H5T_SGN_2)
1171 btp =
new HDF5Int64(vname,vpath, dataset);
1177 InternalErr(__FILE__, __LINE__,
1178 string(
"Unsupported HDF5 64-bit Integer type:")
1187 size = H5Tget_size(datatype);
1188 BESDEBUG(
"h5",
"=Get_bt() H5T_FLOAT size = " << size << endl);
1191 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
1193 else if (size == 4) {
1196 else if (size == 8) {
1203 btp =
new HDF5Str(vname, vpath,dataset);
1210 BaseType *ar_bt = 0;
1213 "=Get_bt() H5T_ARRAY datatype = " << datatype
1217 hid_t dtype_base = H5Tget_super(datatype);
1218 ar_bt = Get_bt(vname, dataset, dtype_base);
1219 btp =
new HDF5Array(vname, dataset, ar_bt);
1220 delete ar_bt; ar_bt = 0;
1223 int ndim = H5Tget_array_ndims(datatype);
1224 size = H5Tget_size(datatype);
1227 if (dtype_base < 0) {
1228 throw InternalErr(__FILE__, __LINE__,
"cannot return the base datatype");
1231 throw InternalErr(__FILE__, __LINE__,
"cannot return the rank of the array datatype");
1234 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
1237 <<
"=Get_bt()" <<
" Dim = " << ndim
1238 <<
" Size = " << size
1242 if(H5Tget_array_dims(datatype, size2) < 0){
1244 InternalErr(__FILE__, __LINE__,
1245 string(
"Could not get array dims for: ")
1251 for (
int dim_index = 0; dim_index < ndim; dim_index++) {
1252 h5_ar.append_dim(size2[dim_index]);
1253 BESDEBUG(
"h5",
"=Get_bt() " << size2[dim_index] << endl);
1254 nelement = nelement * size2[dim_index];
1257 h5_ar.set_did(dt_inst.dset);
1259 h5_ar.set_tid(datatype);
1263 h5_ar.set_length(nelement);
1264 h5_ar.d_type = H5Tget_class(dtype_base);
1265 if (h5_ar.d_type == H5T_NO_CLASS){
1266 throw InternalErr(__FILE__, __LINE__,
"cannot return the datatype class identifier");
1270 if( ar_bt )
delete ar_bt;
1271 if( btp )
delete btp;
1280 btp =
new HDF5Url(vname, vpath,dataset);
1284 throw InternalErr(__FILE__, __LINE__,
1285 string(
"Unsupported HDF5 type: ") + vname);
1289 if( btp )
delete btp;
1294 throw InternalErr(__FILE__, __LINE__,
1295 string(
"Could not make a DAP variable for: ")
1298 BESDEBUG(
"h5",
"<Get_bt()" << endl);
1320Structure *Get_structure(
const string &varname,
const string &vpath,
1321 const string &dataset,
1322 hid_t datatype,
bool is_dap4)
1325 char* memb_name =
nullptr;
1326 hid_t memb_type = -1;
1328 BESDEBUG(
"h5",
">Get_structure()" << datatype << endl);
1330 if (H5Tget_class(datatype) != H5T_COMPOUND)
1331 throw InternalErr(__FILE__, __LINE__,
1332 string(
"Compound-to-structure mapping error for ")
1339 int nmembs = H5Tget_nmembers(datatype);
1340 BESDEBUG(
"h5",
"=Get_structure() has " << nmembs << endl);
1342 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the number of elements");
1344 for (
int i = 0; i < nmembs; i++) {
1345 memb_name = H5Tget_member_name(datatype, i);
1346 H5T_class_t memb_cls = H5Tget_member_class(datatype, i);
1347 memb_type = H5Tget_member_type(datatype, i);
1348 if (memb_name ==
nullptr){
1349 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the name of the member");
1351 if ((memb_cls < 0) || (memb_type < 0)) {
1352 throw InternalErr(__FILE__, __LINE__,
1353 string(
"Type mapping error for ")
1354 +
string(memb_name) );
1357 if (memb_cls == H5T_COMPOUND) {
1358 Structure *s = Get_structure(memb_name, memb_name, dataset, memb_type,is_dap4);
1359 structure_ptr->add_var(s);
1362 else if(memb_cls == H5T_ARRAY) {
1364 BaseType *ar_bt = 0;
1367 hid_t dtype_base = 0;
1372 dtype_base = H5Tget_super(memb_type);
1375 int ndim = H5Tget_array_ndims(memb_type);
1376 size_t size = H5Tget_size(memb_type);
1379 if (dtype_base < 0) {
1380 throw InternalErr(__FILE__, __LINE__,
"cannot return the base memb_type");
1383 throw InternalErr(__FILE__, __LINE__,
"cannot return the rank of the array memb_type");
1386 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the memb_type");
1390 if(H5Tget_array_dims(memb_type, size2) < 0){
1392 InternalErr(__FILE__, __LINE__,
1393 string(
"Could not get array dims for: ")
1394 +
string(memb_name));
1397 H5T_class_t array_memb_cls = H5Tget_class(dtype_base);
1398 if(array_memb_cls == H5T_NO_CLASS) {
1399 throw InternalErr(__FILE__, __LINE__,
1400 string(
"cannot get the correct class for compound type member")
1401 +
string(memb_name));
1403 if(H5T_COMPOUND == array_memb_cls) {
1405 s = Get_structure(memb_name, memb_name,dataset, dtype_base,is_dap4);
1408 for (
int dim_index = 0; dim_index < ndim; dim_index++) {
1409 h5_ar->append_dim(size2[dim_index]);
1410 nelement = nelement * size2[dim_index];
1416 h5_ar->set_length(nelement);
1418 structure_ptr->add_var(h5_ar);
1422 else if (H5T_INTEGER == array_memb_cls || H5T_FLOAT == array_memb_cls || H5T_STRING == array_memb_cls) {
1423 ar_bt = Get_bt(memb_name, memb_name,dataset, dtype_base,is_dap4);
1426 for (
int dim_index = 0; dim_index < ndim; dim_index++) {
1427 h5_ar->append_dim(size2[dim_index]);
1428 nelement = nelement * size2[dim_index];
1434 h5_ar->set_length(nelement);
1436 structure_ptr->add_var(h5_ar);
1439 if( ar_bt )
delete ar_bt;
1440 if( btp )
delete btp;
1442 H5Tclose(dtype_base);
1446 if( ar_bt )
delete ar_bt;
1447 if( btp )
delete btp;
1449 H5Tclose(dtype_base);
1454 else if (memb_cls == H5T_INTEGER || memb_cls == H5T_FLOAT || memb_cls == H5T_STRING) {
1455 BaseType *bt = Get_bt(memb_name, memb_name,dataset, memb_type,is_dap4);
1456 structure_ptr->add_var(bt);
1461 memb_name =
nullptr;
1462 throw InternalErr(__FILE__, __LINE__,
"unsupported field datatype inside a compound datatype");
1465 if(memb_name !=
nullptr)
1471 delete structure_ptr;
1472 if(memb_name!=
nullptr)
1475 H5Tclose(memb_type);
1479 BESDEBUG(
"h5",
"<Get_structure()" << endl);
1481 return structure_ptr;
1502bool check_dimscale(hid_t fileid) {
1504 bool ret_value =
false;
1505 herr_t ret_o= H5OVISIT(fileid, H5_INDEX_NAME, H5_ITER_INC, visit_obj_cb,
nullptr);
1507 throw InternalErr(__FILE__, __LINE__,
"H5OVISIT fails");
1509 ret_value =(ret_o >0)?
true:
false;
1515visit_obj_cb(hid_t group_id,
const char *name,
const H5O_info_t *oinfo,
1520 if(oinfo->type == H5O_TYPE_DATASET) {
1523 dataset = H5Dopen2(group_id,name,H5P_DEFAULT);
1525 throw InternalErr(__FILE__, __LINE__,
"H5Dopen2 fails in the H5OVISIT call back function.");
1528 dspace = H5Dget_space(dataset);
1531 throw InternalErr(__FILE__, __LINE__,
"H5Dget_space fails in the H5OVISIT call back function.");
1535 if(H5Sget_simple_extent_ndims(dspace) == 1) {
1537 if(
true == has_dimscale_attr(dataset))
1550 int dim_attr_mark[4];
1551 for(
int i =0;i<4;i++)
1552 dim_attr_mark[i] = 0;
1557 herr_t ret = H5Aiterate2(dataset, H5_INDEX_NAME, H5_ITER_INC,
nullptr, attr_info, dim_attr_mark);
1561 throw InternalErr(__FILE__, __LINE__,
"H5Aiterate2 fails in the H5OVISIT call back function.");
1564 BESDEBUG(
"h5",
"<dset name is " << name <<endl);
1567 if (dim_attr_mark[0] && dim_attr_mark[1]){
1586bool has_dimscale_attr(hid_t dataset) {
1588 bool ret_value =
false;
1589 string dimscale_attr_name=
"CLASS";
1590 string dimscale_attr_value=
"DIMENSION_SCALE";
1591 htri_t dimscale_attr_exist = H5Aexists_by_name(dataset,
".",dimscale_attr_name.c_str(),H5P_DEFAULT);
1592 if(dimscale_attr_exist <0)
1593 throw InternalErr(__FILE__, __LINE__,
"H5Aexists_by_name fails when checking the CLASS attribute.");
1594 else if(dimscale_attr_exist > 0) {
1597 hid_t atype_id = -1;
1600 attr_id = H5Aopen(dataset,dimscale_attr_name.c_str(), H5P_DEFAULT);
1602 throw InternalErr(__FILE__, __LINE__,
"H5Aopen fails in the attr_info call back function.");
1605 atype_id = H5Aget_type(attr_id);
1608 throw InternalErr(__FILE__, __LINE__,
"H5Aget_type fails in the attr_info call back function.");
1613 if (H5T_STRING == H5Tget_class(atype_id))
1614 ret_value = check_str_attr_value(attr_id,atype_id,dimscale_attr_value,
false);
1647attr_info_dimscale(hid_t loc_id,
const char *name,
const H5A_info_t *ainfo,
void *opdata)
1649 int *countp = (
int*)opdata;
1652 hid_t atype_id = -1;
1655 attr_id = H5Aopen(loc_id, name, H5P_DEFAULT);
1657 throw InternalErr(__FILE__, __LINE__,
"H5Aopen fails in the attr_info call back function.");
1660 atype_id = H5Aget_type(attr_id);
1663 throw InternalErr(__FILE__, __LINE__,
"H5Aget_type fails in the attr_info call back function.");
1670 if ((H5T_COMPOUND == H5Tget_class(atype_id)) && (strcmp(name,
"REFERENCE_LIST")==0)) {
1677 if (H5T_STRING == H5Tget_class(atype_id)) {
1678 if (strcmp(name,
"CLASS") == 0) {
1679 string dim_scale_mark =
"DIMENSION_SCALE";
1680 bool is_dim_scale = check_str_attr_value(attr_id,atype_id,dim_scale_mark,
false);
1681 if(
true == is_dim_scale)
1718attr_info_dimscale(hid_t loc_id,
const char *name,
const H5A_info_t *ainfo,
void *opdata)
1722 int *dimattr_p = (
int*)opdata;
1725 bool has_reference_list =
false;
1726 bool has_dimscale =
false;
1727 bool has_name_as_var =
false;
1728 bool has_name_as_nc4_purdim =
false;
1733 hid_t atype_id = -1;
1736 attr_id = H5Aopen(loc_id, name, H5P_DEFAULT);
1738 throw InternalErr(__FILE__, __LINE__,
"H5Aopen fails in the attr_info call back function.");
1741 atype_id = H5Aget_type(attr_id);
1744 throw InternalErr(__FILE__, __LINE__,
"H5Aget_type fails in the attr_info call back function.");
1751 if ((H5T_COMPOUND == H5Tget_class(atype_id)) && (strcmp(name,
"REFERENCE_LIST")==0)) {
1758 if (H5T_STRING == H5Tget_class(atype_id)) {
1759 if (strcmp(name,
"NAME") == 0) {
1761 string pure_dimname_mark =
"This is a netCDF dimension but not a netCDF variable";
1762 bool is_pure_dim = check_str_attr_value(attr_id,atype_id,pure_dimname_mark,
true);
1764 BESDEBUG(
"h5",
"pure dimension name yes" << is_pure_dim <<endl);
1765 if(
true == is_pure_dim)
1771 ssize_t objnamelen = -1;
1772 if ((objnamelen= H5Iget_name(loc_id,
nullptr,0))<=0) {
1773 string msg =
"Cannot obtain the variable name length." ;
1774 throw InternalErr(__FILE__,__LINE__,msg);
1776 vector<char> objname;
1777 objname.resize(objnamelen+1);
1778 if ((objnamelen= H5Iget_name(loc_id,objname.data(),objnamelen+1))<=0) {
1779 string msg =
"Cannot obtain the variable name." ;
1780 throw InternalErr(__FILE__,__LINE__,msg);
1783 string objname_str = string(objname.begin(),objname.end());
1786 objname_str = objname_str.substr(0,objnamelen);
1788 string normal_dimname_mark = objname_str.substr(objname_str.find_last_of(
"/")+1);
1789 bool is_normal_dim = check_str_attr_value(attr_id,atype_id,normal_dimname_mark,
false);
1790 if(
true == is_normal_dim)
1798 H5T_str_t str_pad = H5Tget_strpad(atype_id);
1800 hid_t aspace_id = -1;
1801 aspace_id = H5Aget_space(attr_id);
1803 throw InternalErr(__FILE__, __LINE__,
"H5Aget_space fails in the attr_info call back function.");
1806 int ndims = H5Sget_simple_extent_ndims(aspace_id);
1812 vector<hsize_t> asize;
1813 vector<hsize_t> maxsize;
1814 asize.resize(ndims);
1815 maxsize.resize(ndims);
1821 if (H5Sget_simple_extent_dims(aspace_id, asize.data(), maxsize.data())<0) {
1822 H5Sclose(aspace_id);
1823 throw InternalErr(__FILE__, __LINE__,
"Cannot obtain the dim. info in the H5Aiterate2 call back function.");
1827 for (
int j = 0; j < ndims; j++)
1831 size_t ty_size = H5Tget_size(atype_id);
1833 H5Sclose(aspace_id);
1834 throw InternalErr(__FILE__, __LINE__,
"Cannot obtain the type size in the H5Aiterate2 call back function.");
1837 size_t total_bytes = nelmts * ty_size;
1838 string total_vstring =
"";
1839 if(H5Tis_variable_str(atype_id) > 0) {
1842 vector<char> temp_buf;
1843 temp_buf.resize(total_bytes);
1845 if (H5Aread(attr_id, atype_id, temp_buf.data()) < 0){
1846 H5Sclose(aspace_id);
1847 throw InternalErr(__FILE__,__LINE__,
"Cannot read the attribute in the H5Aiterate2 call back function");
1850 char *temp_bp =
nullptr;
1851 temp_bp = temp_buf.data();
1852 char* onestring =
nullptr;
1854 for (
unsigned int temp_i = 0; temp_i <nelmts; temp_i++) {
1857 onestring =*(
char **)temp_bp;
1859 if(onestring!=
nullptr)
1860 total_vstring +=string(onestring);
1866 if ((temp_buf.data()) !=
nullptr) {
1868 if (H5Dvlen_reclaim(atype_id,aspace_id,H5P_DEFAULT,temp_buf.data()) < 0) {
1869 H5Sclose(aspace_id);
1870 throw InternalErr(__FILE__,__LINE__,
"Cannot reclaim VL memory in the H5Aiterate2 call back function.");
1878 vector<char> temp_buf;
1879 temp_buf.resize(total_bytes);
1880 if (H5Aread(attr_id, atype_id, temp_buf.data()) < 0){
1881 H5Sclose(aspace_id);
1882 throw InternalErr(__FILE__,__LINE__,
"Cannot read the attribute in the H5Aiterate2 call back function");
1884 string temp_buf_string(temp_buf.begin(),temp_buf.end());
1885 total_vstring = temp_buf_string.substr(0,total_bytes);
1888 if(str_pad != H5T_STR_ERROR)
1889 total_vstring = total_vstring.substr(0,total_vstring.size()-1);
1894 H5Sclose(aspace_id);
1895 if(total_vstring ==
"DIMENSION_SCALE"){
1928void obtain_dimnames(
const hid_t file_id,hid_t dset,
int ndims,
DS_t *dt_inst_ptr,vector<link_info_t> & hdf5_hls) {
1930 htri_t has_dimension_list = -1;
1932 string dimlist_name =
"DIMENSION_LIST";
1933 has_dimension_list = H5Aexists(dset,dimlist_name.c_str());
1935 if(has_dimension_list > 0 && ndims > 0) {
1938 vector<hvl_t> vlbuf;
1939 vlbuf.resize(ndims);
1942 hid_t atype_id = -1;
1943 hid_t amemtype_id = -1;
1944 hid_t aspace_id = -1;
1945 hid_t ref_dset = -1;
1948 attr_id = H5Aopen(dset,dimlist_name.c_str(),H5P_DEFAULT);
1950 string msg =
"Cannot open the attribute " + dimlist_name +
" of HDF5 dataset "+ string(dt_inst_ptr->
name);
1951 throw InternalErr(__FILE__, __LINE__, msg);
1954 atype_id = H5Aget_type(attr_id);
1956 string msg =
"Cannot get the datatype of the attribute " + dimlist_name +
" of HDF5 dataset "+ string(dt_inst_ptr->
name);
1957 throw InternalErr(__FILE__, __LINE__, msg);
1960 amemtype_id = H5Tget_native_type(atype_id, H5T_DIR_ASCEND);
1961 if (amemtype_id < 0) {
1962 string msg =
"Cannot get the memory datatype of the attribute " + dimlist_name +
" of HDF5 dataset "+ string(dt_inst_ptr->
name);
1963 throw InternalErr(__FILE__, __LINE__, msg);
1967 if (H5Aread(attr_id,amemtype_id,vlbuf.data()) <0) {
1968 string msg =
"Cannot obtain the referenced object for the variable " + string(dt_inst_ptr->
name);
1969 throw InternalErr(__FILE__, __LINE__, msg);
1972 vector<char> objname;
1975 for (
int i = 0; i < ndims; i++) {
1977 if(vlbuf[i].p ==
nullptr) {
1978 stringstream sindex ;
1980 string msg =
"For variable " + string(dt_inst_ptr->
name) +
"; ";
1981 msg = msg +
"the dimension of which the index is "+ sindex.str() +
" doesn't exist. ";
1982 throw InternalErr(__FILE__, __LINE__, msg);
1985 rbuf =((hobj_ref_t*)vlbuf[i].p)[0];
1987 if ((ref_dset = H5RDEREFERENCE(attr_id, H5R_OBJECT, &rbuf)) < 0) {
1988 string msg =
"Cannot dereference from the DIMENSION_LIST attribute for the variable " + string(dt_inst_ptr->
name);
1989 throw InternalErr(__FILE__, __LINE__, msg);
1992 ssize_t objnamelen = -1;
1993 if ((objnamelen= H5Iget_name(ref_dset,
nullptr,0))<=0) {
1994 string msg =
"Cannot obtain the dimension name length for the variable " + string(dt_inst_ptr->
name);
1995 throw InternalErr(__FILE__,__LINE__,msg);
1998 objname.resize(objnamelen+1);
1999 if ((objnamelen= H5Iget_name(ref_dset,objname.data(),objnamelen+1))<=0) {
2001 string msg =
"Cannot obtain the dimension name for the variable " + string(dt_inst_ptr->
name);
2002 throw InternalErr(__FILE__,__LINE__,msg);
2005 auto objname_str = string(objname.begin(),objname.end());
2008 string trim_objname = objname_str.substr(0,objnamelen);
2013 H5O_info_t obj_info;
2014 if(H5OGET_INFO(ref_dset,&obj_info)<0) {
2016 string msg =
"Cannot obtain the object info for the dimension variable " + objname_str;
2017 throw InternalErr(__FILE__,__LINE__,msg);
2021 if(obj_info.rc > 1) {
2030 bool link_find =
false;
2033 for (
unsigned int i = 0; i <hdf5_hls.size();i++) {
2034#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2036 if(H5Otoken_cmp(ref_dset,&(obj_info.token),&(hdf5_hls[i].link_addr),&token_cmp) <0)
2037 throw InternalErr(__FILE__,__LINE__,
"H5Otoken_cmp failed");
2040 if(obj_info.addr == hdf5_hls[i].link_addr) {
2042 trim_objname =
'/'+hdf5_hls[i].slink_path;
2049 if(link_find ==
false) {
2051#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2053 unsigned link_unvisited;
2054 H5O_token_t link_addr;
2055 vector<string> hl_names;
2059 unsigned link_unvisited;
2061 vector<string> hl_names;
2065 t_link_info_t t_li_info;
2066 t_li_info.link_unvisited = obj_info.rc;
2068#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2069 memcpy(&t_li_info.link_addr,&obj_info.token,
sizeof(H5O_token_t));
2071 t_li_info.link_addr = obj_info.addr;
2074 if(H5Lvisit(file_id, H5_INDEX_NAME, H5_ITER_NATIVE, visit_link_cb, (
void*)&t_li_info) < 0) {
2077 err_msg =
"Find all hardlinks: H5Lvisit failed to iterate all the objects";
2078 throw InternalErr(__FILE__,__LINE__,err_msg);
2081for(
int i = 0; i<t_li_info.hl_names.size();i++)
2082 cerr<<
"hl name is "<<t_li_info.hl_names[i] <<endl;
2085 string shortest_hl = obtain_shortest_ancestor_path(t_li_info.hl_names);
2087 if(shortest_hl ==
"") {
2090 err_msg =
"The shortest hardlink is not located under an ancestor group of all links.";
2091 err_msg +=
"This is not supported by netCDF4 data model and the current Hyrax DAP4 implementation.";
2092 throw InternalErr(__FILE__,__LINE__,err_msg);
2097#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2098 memcpy(&new_hdf5_hl.link_addr,&obj_info.token,
sizeof(H5O_token_t));
2100 new_hdf5_hl.link_addr = obj_info.addr;
2102 new_hdf5_hl.slink_path = shortest_hl;
2103 hdf5_hls.push_back(new_hdf5_hl);
2104 trim_objname =
'/'+shortest_hl;
2110 dt_inst_ptr->dimnames.push_back(trim_objname.substr(trim_objname.find_last_of(
"/")+1));
2111 dt_inst_ptr->dimnames_path.push_back(trim_objname);
2113 if(H5Dclose(ref_dset)<0) {
2114 throw InternalErr(__FILE__,__LINE__,
"Cannot close the HDF5 dataset in the function obtain_dimnames().");
2118 if(vlbuf.empty()==
false) {
2120 if ((aspace_id = H5Aget_space(attr_id)) < 0) {
2121 string msg =
"Cannot close the HDF5 attribute space successfully for <DIMENSION_LIST> of the variable "+string(dt_inst_ptr->
name);
2122 throw InternalErr(__FILE__,__LINE__,msg);
2125 if (H5Dvlen_reclaim(amemtype_id,aspace_id,H5P_DEFAULT,(
void*)vlbuf.data())<0) {
2126 throw InternalErr(__FILE__,__LINE__,
"Cannot reclaim the variable length memory in the function obtain_dimnames()");
2129 H5Sclose(aspace_id);
2134 H5Tclose(amemtype_id);
2144 if(amemtype_id != -1)
2145 H5Tclose(amemtype_id);
2148 H5Sclose(aspace_id);
2160void write_vlen_str_attrs(hid_t attr_id,hid_t ty_id,
const DSattr_t * attr_inst_ptr,D4Attribute *d4_attr, AttrTable* d2_attr,
bool is_dap4){
2162 BESDEBUG(
"h5",
"attribute name " << attr_inst_ptr->
name <<endl);
2163 BESDEBUG(
"h5",
"attribute size " <<attr_inst_ptr->
need <<endl);
2164 BESDEBUG(
"h5",
"attribute type size " <<(
int)(H5Tget_size(ty_id))<<endl);
2166 hid_t temp_space_id = H5Aget_space(attr_id);
2167 BESDEBUG(
"h5",
"attribute calculated size "<<(
int)(H5Tget_size(ty_id)) *(
int)(H5Sget_simple_extent_npoints(temp_space_id)) <<endl);
2168 if(temp_space_id <0) {
2173 throw InternalErr(__FILE__, __LINE__,
"unable to read HDF5 attribute data");
2176 vector<char> temp_buf;
2178 temp_buf.resize((
size_t)attr_inst_ptr->
need);
2180 if (H5Aread(attr_id, ty_id, temp_buf.data()) < 0) {
2183 H5Sclose(temp_space_id);
2186 throw InternalErr(__FILE__, __LINE__,
"unable to read HDF5 attribute data");
2190 temp_bp = temp_buf.data();
2191 for (
unsigned int temp_i = 0; temp_i <attr_inst_ptr->
nelmts; temp_i++) {
2194 char* onestring =*(
char **)temp_bp;
2197 if (onestring !=
nullptr) {
2198 string tempstring(onestring);
2200 d4_attr->add_value(tempstring);
2202 d2_attr->append_attr(attr_inst_ptr->
name,
"String",tempstring);
2205 temp_bp +=H5Tget_size(ty_id);
2207 if (temp_buf.empty() !=
true) {
2210 herr_t ret_vlen_claim;
2211 ret_vlen_claim = H5Dvlen_reclaim(ty_id,temp_space_id,H5P_DEFAULT,temp_buf.data());
2212 if(ret_vlen_claim < 0){
2215 H5Sclose(temp_space_id);
2218 throw InternalErr(__FILE__, __LINE__,
"Cannot reclaim the memory buffer of the HDF5 variable length string.");
2223 H5Sclose(temp_space_id);
2226bool check_str_attr_value(hid_t attr_id,hid_t atype_id,
const string & value_to_compare,
bool check_substr) {
2228 bool ret_value =
false;
2230 H5T_str_t str_pad = H5Tget_strpad(atype_id);
2231 if(str_pad == H5T_STR_ERROR)
2232 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain string pad.");
2234 hid_t aspace_id = -1;
2235 aspace_id = H5Aget_space(attr_id);
2237 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain attribute space.");
2239 int ndims = H5Sget_simple_extent_ndims(aspace_id);
2241 H5Sclose(aspace_id);
2242 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain number of dimensions.");
2250 vector<hsize_t> asize;
2251 asize.resize(ndims);
2252 if (H5Sget_simple_extent_dims(aspace_id, asize.data(),
nullptr)<0) {
2253 H5Sclose(aspace_id);
2254 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the dimension info.");
2258 for (
int j = 0; j < ndims; j++)
2262 size_t ty_size = H5Tget_size(atype_id);
2264 H5Sclose(aspace_id);
2265 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the type size.");
2268 size_t total_bytes = nelmts * ty_size;
2269 string total_vstring =
"";
2270 if(H5Tis_variable_str(atype_id) > 0) {
2273 vector<char> temp_buf;
2274 temp_buf.resize(total_bytes);
2276 if (H5Aread(attr_id, atype_id, temp_buf.data()) < 0){
2277 H5Sclose(aspace_id);
2278 throw InternalErr(__FILE__,__LINE__,
"Fail to read the attribute.");
2281 char *temp_bp =
nullptr;
2282 temp_bp = temp_buf.data();
2284 for (
unsigned int temp_i = 0; temp_i <nelmts; temp_i++) {
2287 char* onestring =*(
char **)temp_bp;
2289 if(onestring!=
nullptr)
2290 total_vstring +=string(onestring);
2296 if ((temp_buf.data()) !=
nullptr) {
2298 if (H5Dvlen_reclaim(atype_id,aspace_id,H5P_DEFAULT,temp_buf.data()) < 0) {
2299 H5Sclose(aspace_id);
2300 throw InternalErr(__FILE__,__LINE__,
"Fail to reclaim VL memory.");
2308 vector<char> temp_buf;
2309 temp_buf.resize(total_bytes);
2310 if (H5Aread(attr_id, atype_id, temp_buf.data()) < 0){
2311 H5Sclose(aspace_id);
2312 throw InternalErr(__FILE__,__LINE__,
"Fail to read the attribute.");
2314 string temp_buf_string(temp_buf.begin(),temp_buf.end());
2315 total_vstring = temp_buf_string.substr(0,total_bytes);
2318 if(str_pad != H5T_STR_ERROR)
2319 total_vstring = total_vstring.substr(0,total_vstring.size()-1);
2324 H5Sclose(aspace_id);
2326 if(
false == check_substr) {
2327 if(total_vstring == value_to_compare)
2331 if(total_vstring.size()>=value_to_compare.size()) {
2332 if( 0 == total_vstring.compare(0,value_to_compare.size(),value_to_compare))
2341visit_link_cb(hid_t group_id,
const char *name,
const H5L_info_t *linfo,
2344#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2346 unsigned link_unvisited;
2347 H5O_token_t link_addr;
2348 vector<string> hl_names;
2352 unsigned link_unvisited;
2354 vector<string> hl_names;
2358 t_link_info_t *op_data = (t_link_info_t *)_op_data;
2362 if(linfo->type == H5L_TYPE_HARD) {
2363#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2365 if(H5Otoken_cmp(group_id,&(op_data->link_addr),&(linfo->u.token),&token_cmp) <0)
2366 throw InternalErr(__FILE__,__LINE__,
"H5Otoken_cmp failed");
2369 if(op_data->link_addr == linfo->u.address) {
2371 op_data->link_unvisited = op_data->link_unvisited -1;
2372 string tmp_str(name,name+strlen(name));
2373 op_data->hl_names.push_back(tmp_str);
2375 if(op_data->link_unvisited == 0)
2385std::string obtain_shortest_ancestor_path(
const std::vector<std::string> & hls) {
2387 vector<string> hls_path;
2389 bool hl_under_root =
false;
2393 for (i= 0; i<hls.size(); i++) {
2395 size_t path_pos = hls[i].find_last_of(slash);
2399 if(path_pos == std::string::npos) {
2401 hl_under_root =
true;
2405 string tmp_str = hls[i].substr(0,path_pos+1);
2406 hls_path.push_back(tmp_str);
2415 unsigned short_path_index = 0;
2416 unsigned min_path_size = hls_path[0].size();
2419 for(
unsigned j = 1; j <hls_path.size();j++) {
2420 if(min_path_size>hls_path[j].size()) {
2421 min_path_size = hls_path[j].size();
2422 short_path_index = j;
2425 string tmp_sp = hls_path[short_path_index];
2426 ret_str = hls[short_path_index];
2430 for(
unsigned j = 0; j <hls_path.size();j++) {
2431 if(hls_path[j].find(tmp_sp)!=0) {
A class for handling all types of array in HDF5 for the default option.
This class provides a way to map HDF5 byte to DAP Byte for the default option.
A class for mapping HDF5 32-bit float to DAP for the default option.
A class for mapping HDF5 64-bit float to DAP for the default option.
A class for HDF5 signed 16 bit integer type.
This class provides a way to map HDF5 32 bit integer to DAP Int32 for the default option.
This class provides a way to map HDF5 Int64 to DAP Int64 for the default option.
This class provides a way to map HDF5 int8 to DAP Int8 for the default option.
include the entry functions to execute the handlers
This class that translates HDF5 string into DAP string for the default option.
This class converts HDF5 compound type into DAP structure for the default option.
This class provides a way to map unsigned HDF5 16 bit integer to DAP UInt16 for the default option.
This class provides a way to map unsigned HDF5 32 bit integer to DAP UInt32.
This class provides a way to map HDF5 uint64 to DAP UInt64 for the default option.
This class generates DAP URL type for the default option.
void set_numdim(int ndims)
remembers number of dimensions of this array.
void set_numelm(int nelms)
remembers number of elements in this array.
void set_memneed(size_t need)
remembers memory size needed.
string print_attr(hid_t type, int loc, void *sm_buf)
bool check_h5str(hid_t h5type)
hid_t get_fileid(const char *filename)
string get_dap_type(hid_t type, bool is_dap4)
void close_fileid(hid_t fid)
void get_dataset(hid_t pid, const string &dname, DS_t *dt_inst_ptr)
hid_t get_attr_info(hid_t dset, int index, bool is_dap4, DSattr_t *attr_inst_ptr, bool *ignore_attr_ptr)
const int DODS_MAX_RANK
Maximum number of dimensions in an array(default option only).
A structure for DDS generation.
char name[DODS_NAMELEN]
Name of HDF5 group or dataset.
A structure for DAS generation.
char name[DODS_NAMELEN]
Name of HDF5 group or dataset.
hsize_t nelmts
Number of elements.
hsize_t need
Memory space needed to hold nelmts type.