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, NULL);
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[0])) < 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);
221 if (H5Sget_simple_extent_dims(aspace_id, size, maxsize)<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[0], name_size+1);
267 for (
int j = 0; j < ndims; j++) {
268 (*attr_inst_ptr).size[j] = size[j];
271 if(H5Sclose(aspace_id)<0) {
273 throw InternalErr(__FILE__,__LINE__,
"Cannot close HDF5 dataspace ");
295 BESDEBUG(
"h5",
">get_dap_type(): type=" << type << endl);
296 H5T_class_t class_t = H5Tget_class(type);
297 if (H5T_NO_CLASS == class_t)
298 throw InternalErr(__FILE__, __LINE__,
299 "The HDF5 datatype doesn't belong to any Class.");
304 size = H5Tget_size(type);
306 throw InternalErr(__FILE__, __LINE__,
307 "size of datatype is invalid");
310 sign = H5Tget_sign(type);
312 throw InternalErr(__FILE__, __LINE__,
313 "sign of datatype is invalid");
316 BESDEBUG(
"h5",
"=get_dap_type(): H5T_INTEGER" <<
317 " sign = " << sign <<
318 " size = " << size <<
322 if(
true == is_dap4) {
323 if (sign == H5T_SGN_NONE)
329 if (sign == H5T_SGN_NONE)
337 if (sign == H5T_SGN_NONE)
344 if (sign == H5T_SGN_NONE)
352 if (
true == is_dap4) {
353 if (sign == H5T_SGN_NONE)
365 size = H5Tget_size(type);
367 throw InternalErr(__FILE__, __LINE__,
368 "size of the datatype is invalid");
371 BESDEBUG(
"h5",
"=get_dap_type(): FLOAT size = " << size << endl);
380 BESDEBUG(
"h5",
"<get_dap_type(): H5T_STRING" << endl);
384 BESDEBUG(
"h5",
"<get_dap_type(): H5T_REFERENCE" << endl);
390 BESDEBUG(
"h5",
"<get_dap_type(): COMPOUND" << endl);
397 BESDEBUG(
"h5",
"<get_dap_type(): Unmappable Type" << endl);
398 return "Unmappable Type";
413 hid_t fileid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
415 string msg =
"cannot open the HDF5 file ";
416 string filenamestr(filename);
418 throw InternalErr(__FILE__, __LINE__, msg);
435 if (H5Fclose(fid) < 0)
436 throw Error(unknown_error,
437 string(
"Could not close the HDF5 file."));
454 BESDEBUG(
"h5",
">get_dataset()" << endl);
458 if ((dset = H5Dopen(pid, dname.c_str(),H5P_DEFAULT)) < 0) {
459 string msg =
"cannot open the HDF5 dataset ";
461 throw InternalErr(__FILE__, __LINE__, msg);
466 if ((dtype = H5Dget_type(dset)) < 0) {
468 string msg =
"cannot get the the datatype of HDF5 dataset ";
470 throw InternalErr(__FILE__, __LINE__, msg);
474 H5T_class_t ty_class = H5Tget_class(dtype);
478 string msg =
"cannot get the datatype class of HDF5 dataset ";
480 throw InternalErr(__FILE__, __LINE__, msg);
486 if ((ty_class == H5T_TIME) || (ty_class == H5T_BITFIELD)
487 || (ty_class == H5T_OPAQUE) || (ty_class == H5T_ENUM) || (ty_class == H5T_VLEN)) {
488 string msg =
"unexpected datatype of HDF5 dataset ";
490 throw InternalErr(__FILE__, __LINE__, msg);
494 if ((dspace = H5Dget_space(dset)) < 0) {
497 string msg =
"cannot get the the dataspace of HDF5 dataset ";
499 throw InternalErr(__FILE__, __LINE__, msg);
507 int ndims = H5Sget_simple_extent_ndims(dspace);
512 string msg =
"cannot get hdf5 dataspace number of dimension for dataset ";
514 throw InternalErr(__FILE__, __LINE__, msg);
519 string msg =
"number of dimensions exceeds allowed for dataset ";
524 throw InternalErr(__FILE__, __LINE__, msg);
531 if (H5Sget_simple_extent_dims(dspace, size, maxsize)<0){
532 string msg =
"cannot obtain the dim. info for the dataset ";
537 throw InternalErr(__FILE__, __LINE__, msg);
543 for (
int j = 0; j < ndims; j++)
547 size_t dtype_size = H5Tget_size(dtype);
548 if (dtype_size == 0) {
549 string msg =
"cannot obtain the data type size for the dataset ";
554 throw InternalErr(__FILE__, __LINE__, msg);
557 size_t need = nelmts * dtype_size;
559 hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
561 string msg =
"cannot obtain the memory data type for the dataset ";
566 throw InternalErr(__FILE__, __LINE__, msg);
569 (*dt_inst_ptr).type = memtype;
570 (*dt_inst_ptr).ndims = ndims;
571 (*dt_inst_ptr).nelmts = nelmts;
572 (*dt_inst_ptr).need = need;
573 strncpy((*dt_inst_ptr).name, dname.c_str(), dname.length());
574 (*dt_inst_ptr).name[dname.length()] =
'\0';
575 for (
int j = 0; j < ndims; j++)
576 (*dt_inst_ptr).size[j] = size[j];
578 if(H5Tclose(dtype)<0) {
581 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 datatype.");
584 if(H5Sclose(dspace)<0) {
586 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 dataspace.");
589 if(H5Dclose(dset)<0) {
590 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 dataset.");
609void 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)
612 BESDEBUG(
"h5",
">get_dataset()" << endl);
616 if ((dset = H5Dopen(pid, dname.c_str(),H5P_DEFAULT)) < 0) {
617 string msg =
"cannot open the HDF5 dataset ";
619 throw InternalErr(__FILE__, __LINE__, msg);
624 if ((dtype = H5Dget_type(dset)) < 0) {
626 string msg =
"cannot get the the datatype of HDF5 dataset ";
628 throw InternalErr(__FILE__, __LINE__, msg);
632 H5T_class_t ty_class = H5Tget_class(dtype);
636 string msg =
"cannot get the datatype class of HDF5 dataset ";
638 throw InternalErr(__FILE__, __LINE__, msg);
644 if ((ty_class == H5T_TIME) || (ty_class == H5T_BITFIELD)
645 || (ty_class == H5T_OPAQUE) || (ty_class == H5T_ENUM) || (ty_class == H5T_VLEN)) {
646 string msg =
"unexpected datatype of HDF5 dataset ";
648 throw InternalErr(__FILE__, __LINE__, msg);
652 if ((dspace = H5Dget_space(dset)) < 0) {
655 string msg =
"cannot get the the dataspace of HDF5 dataset ";
657 throw InternalErr(__FILE__, __LINE__, msg);
665 int ndims = H5Sget_simple_extent_ndims(dspace);
670 string msg =
"cannot get hdf5 dataspace number of dimension for dataset ";
672 throw InternalErr(__FILE__, __LINE__, msg);
677 string msg =
"number of dimensions exceeds allowed for dataset ";
682 throw InternalErr(__FILE__, __LINE__, msg);
689 if (H5Sget_simple_extent_dims(dspace, size, maxsize)<0){
690 string msg =
"cannot obtain the dim. info for the dataset ";
695 throw InternalErr(__FILE__, __LINE__, msg);
701 for (
int j = 0; j < ndims; j++)
705 size_t dtype_size = H5Tget_size(dtype);
706 if (dtype_size == 0) {
707 string msg =
"cannot obtain the data type size for the dataset ";
712 throw InternalErr(__FILE__, __LINE__, msg);
715 size_t need = nelmts * dtype_size;
717 hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
719 string msg =
"cannot obtain the memory data type for the dataset ";
724 throw InternalErr(__FILE__, __LINE__, msg);
727 (*dt_inst_ptr).type = memtype;
728 (*dt_inst_ptr).ndims = ndims;
729 (*dt_inst_ptr).nelmts = nelmts;
730 (*dt_inst_ptr).need = need;
731 strncpy((*dt_inst_ptr).name, dname.c_str(), dname.length());
732 (*dt_inst_ptr).name[dname.length()] =
'\0';
733 for (
int j = 0; j < ndims; j++)
734 (*dt_inst_ptr).size[j] = size[j];
737 if(
true == use_dimscale) {
738 BESDEBUG(
"h5",
"<h5get.cc: get_dataset() use dim scale is true." << endl);
741 bool is_dimscale =
false;
746 bool has_ds_attr =
false;
749 has_ds_attr = has_dimscale_attr(dset);
755 throw InternalErr(__FILE__, __LINE__,
"Fail to check dim. scale.");
758 if(
true == has_ds_attr) {
764 int dim_attr_mark[3];
765 for(
int i = 0;i<3;i++)
766 dim_attr_mark[i] = 0;
770 herr_t ret = H5Aiterate2(dset, H5_INDEX_NAME, H5_ITER_INC, NULL, attr_info_dimscale, dim_attr_mark);
772 string msg =
"cannot interate the attributes of the dataset ";
777 throw InternalErr(__FILE__, __LINE__, msg);
780 for (
int i = 0; i<3;i++)
781 BESDEBUG(
"h5",
"dim_attr_mark is "<<dim_attr_mark[i] <<endl);
789 if (((dim_attr_mark[0] && !dim_attr_mark[1]) || dim_attr_mark[2]))
791 else if(dim_attr_mark[1])
796 if(
true == is_dimscale) {
797 BESDEBUG(
"h5",
"<h5get.cc: dname is " << dname << endl);
798 BESDEBUG(
"h5",
"<h5get.cc: get_dataset() this is dim scale." << endl);
799 BESDEBUG(
"h5",
"<h5get.cc: dataset storage size is: " <<H5Dget_storage_size(dset)<< endl);
805 (*dt_inst_ptr).dimnames.push_back(dname.substr(dname.find_last_of(
"/")+1));
806 (*dt_inst_ptr).dimnames_path.push_back(dname);
813 else if(
false == is_pure_dim)
814 obtain_dimnames(file_id,dset,ndims,dt_inst_ptr,hdf5_hls);
817 if(H5Tclose(dtype)<0) {
820 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 datatype.");
823 if(H5Sclose(dspace)<0) {
825 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 dataspace.");
828 if(H5Dclose(dset)<0) {
829 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 dataset.");
844 if (H5Tget_class(h5type) == H5T_STRING)
868 unsigned short *tusp;
879 switch (H5Tget_class(type)) {
883 size_t size = H5Tget_size(type);
885 throw InternalErr(__FILE__, __LINE__,
886 "size of datatype is invalid");
889 H5T_sign_t sign = H5Tget_sign(type);
891 throw InternalErr(__FILE__, __LINE__,
892 "sign of datatype is invalid");
895 BESDEBUG(
"h5",
"=get_dap_type(): H5T_INTEGER" <<
896 " sign = " << sign <<
897 " size = " << size <<
907 if(sign == H5T_SGN_NONE) {
908 gp.ucp = (
unsigned char *) sm_buf;
909 unsigned char tuchar = *(gp.ucp + loc);
910 snprintf(&rep[0], 32,
"%u", tuchar);
914 gp.tcp = (
char *) sm_buf;
915 snprintf(&rep[0], 32,
"%d", *(gp.tcp + loc));
919 else if (size == 2) {
921 if(sign == H5T_SGN_NONE) {
922 gp.tusp = (
unsigned short *) sm_buf;
923 snprintf(&rep[0], 32,
"%hu", *(gp.tusp + loc));
927 gp.tsp = (
short *) sm_buf;
928 snprintf(&rep[0], 32,
"%hd", *(gp.tsp + loc));
933 else if (size == 4) {
935 if(sign == H5T_SGN_NONE) {
936 gp.tuip = (
unsigned int *) sm_buf;
937 snprintf(&rep[0], 32,
"%u", *(gp.tuip + loc));
941 gp.tip = (
int *) sm_buf;
942 snprintf(&rep[0], 32,
"%d", *(gp.tip + loc));
945 else if (size == 8) {
947 if(sign == H5T_SGN_NONE) {
948 gp.tulp = (
unsigned long *) sm_buf;
949 snprintf(&rep[0], 32,
"%lu", *(gp.tulp + loc));
952 gp.tlp = (
long *) sm_buf;
953 snprintf(&rep[0], 32,
"%ld", *(gp.tlp + loc));
957 throw InternalErr(__FILE__, __LINE__,
"Unsupported integer type, check the size of datatype.");
966 if (H5Tget_size(type) == 4) {
968 float attr_val = *(
float*)sm_buf;
969 bool is_a_fin = isfinite(attr_val);
972 gp.tfp = (
float *) sm_buf;
973 int ll = snprintf(gps, 30,
"%.10g", *(gp.tfp + loc));
977 if (!strchr(gps,
'.') && !strchr(gps,
'e') && !strchr(gps,
'E')
978 && (
true == is_a_fin)){
983 snprintf(&rep[0], 32,
"%s", gps);
985 else if (H5Tget_size(type) == 8) {
987 double attr_val = *(
double*)sm_buf;
988 bool is_a_fin = isfinite(attr_val);
989 gp.tdp = (
double *) sm_buf;
990 int ll = snprintf(gps, 30,
"%.17g", *(gp.tdp + loc));
994 if (!strchr(gps,
'.') && !strchr(gps,
'e')&& !strchr(gps,
'E')
995 && (
true == is_a_fin)) {
999 snprintf(&rep[0], 32,
"%s", gps);
1001 else if (H5Tget_size(type) == 0){
1002 throw InternalErr(__FILE__, __LINE__,
"H5Tget_size() failed.");
1008 int str_size = H5Tget_size(type);
1009 if(H5Tis_variable_str(type)>0) {
1010 throw InternalErr(__FILE__, __LINE__,
1011 "print_attr function doesn't handle variable length string, variable length string should be handled separately.");
1014 throw InternalErr(__FILE__, __LINE__,
"H5Tget_size() failed.");
1016 BESDEBUG(
"h5",
"=print_attr(): H5T_STRING sm_buf=" << (
char *) sm_buf
1017 <<
" size=" << str_size << endl);
1021 buf =
new char[str_size + 1];
1022 strncpy(buf, (
char *) sm_buf, str_size);
1023 buf[str_size] =
'\0';
1025 rep.resize(str_size+3);
1026 snprintf(&rep[0], str_size + 3,
"%s", buf);
1027 rep[str_size + 2] =
'\0';
1028 delete[] buf; buf = 0;
1031 if( buf )
delete[] buf;
1041 string rep_str(rep.begin(),rep.end());
1045D4AttributeType daptype_strrep_to_dap4_attrtype(std::string s){
1049 else if (s ==
"Int8")
1051 else if (s ==
"UInt8")
1052 return attr_uint8_c;
1053 else if (s ==
"Int16")
1054 return attr_int16_c;
1055 else if (s ==
"UInt16")
1056 return attr_uint16_c;
1057 else if (s ==
"Int32")
1058 return attr_int32_c;
1059 else if (s ==
"UInt32")
1060 return attr_uint32_c;
1061 else if (s ==
"Int64")
1062 return attr_int64_c;
1063 else if (s ==
"UInt64")
1064 return attr_uint64_c;
1065 else if (s ==
"Float32")
1066 return attr_float32_c;
1067 else if (s ==
"Float64")
1068 return attr_float64_c;
1069 else if (s ==
"String")
1071 else if (s ==
"Url")
1094BaseType *Get_bt(
const string &vname,
1095 const string &vpath,
1096 const string &dataset,
1097 hid_t datatype,
bool is_dap4)
1099 BaseType *btp = NULL;
1103 BESDEBUG(
"h5",
">Get_bt varname=" << vname <<
" datatype=" << datatype
1107 H5T_sign_t sign = H5T_SGN_ERROR;
1108 switch (H5Tget_class(datatype)) {
1112 size = H5Tget_size(datatype);
1113 sign = H5Tget_sign(datatype);
1114 BESDEBUG(
"h5",
"=Get_bt() H5T_INTEGER size = " << size <<
" sign = "
1117 if (sign == H5T_SGN_ERROR) {
1118 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the sign type of the integer");
1121 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
1123 else if (size == 1) {
1125 if (sign == H5T_SGN_2) {
1126 if (
false == is_dap4)
1127 btp =
new HDF5Int16(vname, vpath, dataset);
1129 btp =
new HDF5Int8(vname,vpath,dataset);
1132 btp =
new HDF5Byte(vname, vpath,dataset);
1134 else if (size == 2) {
1135 if (sign == H5T_SGN_2)
1136 btp =
new HDF5Int16(vname, vpath,dataset);
1140 else if (size == 4) {
1141 if (sign == H5T_SGN_2){
1142 btp =
new HDF5Int32(vname, vpath,dataset);
1147 else if (size == 8) {
1148 if(
true == is_dap4) {
1149 if(sign == H5T_SGN_2)
1150 btp =
new HDF5Int64(vname,vpath, dataset);
1156 InternalErr(__FILE__, __LINE__,
1157 string(
"Unsupported HDF5 64-bit Integer type:")
1166 size = H5Tget_size(datatype);
1167 BESDEBUG(
"h5",
"=Get_bt() H5T_FLOAT size = " << size << endl);
1170 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
1172 else if (size == 4) {
1175 else if (size == 8) {
1182 btp =
new HDF5Str(vname, vpath,dataset);
1189 BaseType *ar_bt = 0;
1192 "=Get_bt() H5T_ARRAY datatype = " << datatype
1196 hid_t dtype_base = H5Tget_super(datatype);
1197 ar_bt = Get_bt(vname, dataset, dtype_base);
1198 btp =
new HDF5Array(vname, dataset, ar_bt);
1199 delete ar_bt; ar_bt = 0;
1202 int ndim = H5Tget_array_ndims(datatype);
1203 size = H5Tget_size(datatype);
1206 if (dtype_base < 0) {
1207 throw InternalErr(__FILE__, __LINE__,
"cannot return the base datatype");
1210 throw InternalErr(__FILE__, __LINE__,
"cannot return the rank of the array datatype");
1213 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
1216 <<
"=Get_bt()" <<
" Dim = " << ndim
1217 <<
" Size = " << size
1221 if(H5Tget_array_dims(datatype, size2) < 0){
1223 InternalErr(__FILE__, __LINE__,
1224 string(
"Could not get array dims for: ")
1230 for (
int dim_index = 0; dim_index < ndim; dim_index++) {
1231 h5_ar.append_dim(size2[dim_index]);
1232 BESDEBUG(
"h5",
"=Get_bt() " << size2[dim_index] << endl);
1233 nelement = nelement * size2[dim_index];
1236 h5_ar.set_did(dt_inst.dset);
1238 h5_ar.set_tid(datatype);
1242 h5_ar.set_length(nelement);
1243 h5_ar.d_type = H5Tget_class(dtype_base);
1244 if (h5_ar.d_type == H5T_NO_CLASS){
1245 throw InternalErr(__FILE__, __LINE__,
"cannot return the datatype class identifier");
1249 if( ar_bt )
delete ar_bt;
1250 if( btp )
delete btp;
1259 btp =
new HDF5Url(vname, vpath,dataset);
1263 throw InternalErr(__FILE__, __LINE__,
1264 string(
"Unsupported HDF5 type: ") + vname);
1268 if( btp )
delete btp;
1273 throw InternalErr(__FILE__, __LINE__,
1274 string(
"Could not make a DAP variable for: ")
1277 BESDEBUG(
"h5",
"<Get_bt()" << endl);
1299Structure *Get_structure(
const string &varname,
const string &vpath,
1300 const string &dataset,
1301 hid_t datatype,
bool is_dap4)
1304 char* memb_name = NULL;
1305 hid_t memb_type = -1;
1307 BESDEBUG(
"h5",
">Get_structure()" << datatype << endl);
1309 if (H5Tget_class(datatype) != H5T_COMPOUND)
1310 throw InternalErr(__FILE__, __LINE__,
1311 string(
"Compound-to-structure mapping error for ")
1318 int nmembs = H5Tget_nmembers(datatype);
1319 BESDEBUG(
"h5",
"=Get_structure() has " << nmembs << endl);
1321 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the number of elements");
1323 for (
int i = 0; i < nmembs; i++) {
1324 memb_name = H5Tget_member_name(datatype, i);
1325 H5T_class_t memb_cls = H5Tget_member_class(datatype, i);
1326 memb_type = H5Tget_member_type(datatype, i);
1327 if (memb_name == NULL){
1328 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the name of the member");
1330 if ((memb_cls < 0) || (memb_type < 0)) {
1331 throw InternalErr(__FILE__, __LINE__,
1332 string(
"Type mapping error for ")
1333 +
string(memb_name) );
1336 if (memb_cls == H5T_COMPOUND) {
1337 Structure *s = Get_structure(memb_name, memb_name, dataset, memb_type,is_dap4);
1338 structure_ptr->add_var(s);
1341 else if(memb_cls == H5T_ARRAY) {
1343 BaseType *ar_bt = 0;
1346 hid_t dtype_base = 0;
1351 dtype_base = H5Tget_super(memb_type);
1354 int ndim = H5Tget_array_ndims(memb_type);
1355 size_t size = H5Tget_size(memb_type);
1358 if (dtype_base < 0) {
1359 throw InternalErr(__FILE__, __LINE__,
"cannot return the base memb_type");
1362 throw InternalErr(__FILE__, __LINE__,
"cannot return the rank of the array memb_type");
1365 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the memb_type");
1369 if(H5Tget_array_dims(memb_type, size2) < 0){
1371 InternalErr(__FILE__, __LINE__,
1372 string(
"Could not get array dims for: ")
1373 +
string(memb_name));
1376 H5T_class_t array_memb_cls = H5Tget_class(dtype_base);
1377 if(array_memb_cls == H5T_NO_CLASS) {
1378 throw InternalErr(__FILE__, __LINE__,
1379 string(
"cannot get the correct class for compound type member")
1380 +
string(memb_name));
1382 if(H5T_COMPOUND == array_memb_cls) {
1384 s = Get_structure(memb_name, memb_name,dataset, dtype_base,is_dap4);
1387 for (
int dim_index = 0; dim_index < ndim; dim_index++) {
1388 h5_ar->append_dim(size2[dim_index]);
1389 nelement = nelement * size2[dim_index];
1395 h5_ar->set_length(nelement);
1397 structure_ptr->add_var(h5_ar);
1401 else if (H5T_INTEGER == array_memb_cls || H5T_FLOAT == array_memb_cls || H5T_STRING == array_memb_cls) {
1402 ar_bt = Get_bt(memb_name, memb_name,dataset, dtype_base,is_dap4);
1405 for (
int dim_index = 0; dim_index < ndim; dim_index++) {
1406 h5_ar->append_dim(size2[dim_index]);
1407 nelement = nelement * size2[dim_index];
1413 h5_ar->set_length(nelement);
1415 structure_ptr->add_var(h5_ar);
1418 if( ar_bt )
delete ar_bt;
1419 if( btp )
delete btp;
1421 H5Tclose(dtype_base);
1425 if( ar_bt )
delete ar_bt;
1426 if( btp )
delete btp;
1428 H5Tclose(dtype_base);
1433 else if (memb_cls == H5T_INTEGER || memb_cls == H5T_FLOAT || memb_cls == H5T_STRING) {
1434 BaseType *bt = Get_bt(memb_name, memb_name,dataset, memb_type,is_dap4);
1435 structure_ptr->add_var(bt);
1441 throw InternalErr(__FILE__, __LINE__,
"unsupported field datatype inside a compound datatype");
1444 if(memb_name != NULL)
1450 delete structure_ptr;
1451 if(memb_name!= NULL)
1454 H5Tclose(memb_type);
1458 BESDEBUG(
"h5",
"<Get_structure()" << endl);
1460 return structure_ptr;
1481bool check_dimscale(hid_t fileid) {
1483 bool ret_value =
false;
1484 herr_t ret_o= H5OVISIT(fileid, H5_INDEX_NAME, H5_ITER_INC, visit_obj_cb, NULL);
1486 throw InternalErr(__FILE__, __LINE__,
"H5OVISIT fails");
1488 ret_value =(ret_o >0)?
true:
false;
1494visit_obj_cb(hid_t group_id,
const char *name,
const H5O_info_t *oinfo,
1499 if(oinfo->type == H5O_TYPE_DATASET) {
1502 dataset = H5Dopen2(group_id,name,H5P_DEFAULT);
1504 throw InternalErr(__FILE__, __LINE__,
"H5Dopen2 fails in the H5OVISIT call back function.");
1507 dspace = H5Dget_space(dataset);
1510 throw InternalErr(__FILE__, __LINE__,
"H5Dget_space fails in the H5OVISIT call back function.");
1514 if(H5Sget_simple_extent_ndims(dspace) == 1) {
1516 if(
true == has_dimscale_attr(dataset))
1529 int dim_attr_mark[4];
1530 for(
int i =0;i<4;i++)
1531 dim_attr_mark[i] = 0;
1536 herr_t ret = H5Aiterate2(dataset, H5_INDEX_NAME, H5_ITER_INC, NULL, attr_info, dim_attr_mark);
1540 throw InternalErr(__FILE__, __LINE__,
"H5Aiterate2 fails in the H5OVISIT call back function.");
1543 BESDEBUG(
"h5",
"<dset name is " << name <<endl);
1546 if (dim_attr_mark[0] && dim_attr_mark[1]){
1565bool has_dimscale_attr(hid_t dataset) {
1567 bool ret_value =
false;
1568 string dimscale_attr_name=
"CLASS";
1569 string dimscale_attr_value=
"DIMENSION_SCALE";
1570 htri_t dimscale_attr_exist = H5Aexists_by_name(dataset,
".",dimscale_attr_name.c_str(),H5P_DEFAULT);
1571 if(dimscale_attr_exist <0)
1572 throw InternalErr(__FILE__, __LINE__,
"H5Aexists_by_name fails when checking the CLASS attribute.");
1573 else if(dimscale_attr_exist > 0) {
1576 hid_t atype_id = -1;
1579 attr_id = H5Aopen(dataset,dimscale_attr_name.c_str(), H5P_DEFAULT);
1581 throw InternalErr(__FILE__, __LINE__,
"H5Aopen fails in the attr_info call back function.");
1584 atype_id = H5Aget_type(attr_id);
1587 throw InternalErr(__FILE__, __LINE__,
"H5Aget_type fails in the attr_info call back function.");
1592 if (H5T_STRING == H5Tget_class(atype_id))
1593 ret_value = check_str_attr_value(attr_id,atype_id,dimscale_attr_value,
false);
1626attr_info_dimscale(hid_t loc_id,
const char *name,
const H5A_info_t *ainfo,
void *opdata)
1628 int *countp = (
int*)opdata;
1631 hid_t atype_id = -1;
1634 attr_id = H5Aopen(loc_id, name, H5P_DEFAULT);
1636 throw InternalErr(__FILE__, __LINE__,
"H5Aopen fails in the attr_info call back function.");
1639 atype_id = H5Aget_type(attr_id);
1642 throw InternalErr(__FILE__, __LINE__,
"H5Aget_type fails in the attr_info call back function.");
1649 if ((H5T_COMPOUND == H5Tget_class(atype_id)) && (strcmp(name,
"REFERENCE_LIST")==0)) {
1656 if (H5T_STRING == H5Tget_class(atype_id)) {
1657 if (strcmp(name,
"CLASS") == 0) {
1658 string dim_scale_mark =
"DIMENSION_SCALE";
1659 bool is_dim_scale = check_str_attr_value(attr_id,atype_id,dim_scale_mark,
false);
1660 if(
true == is_dim_scale)
1697attr_info_dimscale(hid_t loc_id,
const char *name,
const H5A_info_t *ainfo,
void *opdata)
1701 int *dimattr_p = (
int*)opdata;
1704 bool has_reference_list =
false;
1705 bool has_dimscale =
false;
1706 bool has_name_as_var =
false;
1707 bool has_name_as_nc4_purdim =
false;
1712 hid_t atype_id = -1;
1715 attr_id = H5Aopen(loc_id, name, H5P_DEFAULT);
1717 throw InternalErr(__FILE__, __LINE__,
"H5Aopen fails in the attr_info call back function.");
1720 atype_id = H5Aget_type(attr_id);
1723 throw InternalErr(__FILE__, __LINE__,
"H5Aget_type fails in the attr_info call back function.");
1730 if ((H5T_COMPOUND == H5Tget_class(atype_id)) && (strcmp(name,
"REFERENCE_LIST")==0)) {
1737 if (H5T_STRING == H5Tget_class(atype_id)) {
1738 if (strcmp(name,
"NAME") == 0) {
1740 string pure_dimname_mark =
"This is a netCDF dimension but not a netCDF variable";
1741 bool is_pure_dim = check_str_attr_value(attr_id,atype_id,pure_dimname_mark,
true);
1743 BESDEBUG(
"h5",
"pure dimension name yes" << is_pure_dim <<endl);
1744 if(
true == is_pure_dim)
1750 ssize_t objnamelen = -1;
1751 if ((objnamelen= H5Iget_name(loc_id,NULL,0))<=0) {
1752 string msg =
"Cannot obtain the variable name length." ;
1753 throw InternalErr(__FILE__,__LINE__,msg);
1755 vector<char> objname;
1756 objname.resize(objnamelen+1);
1757 if ((objnamelen= H5Iget_name(loc_id,&objname[0],objnamelen+1))<=0) {
1758 string msg =
"Cannot obtain the variable name." ;
1759 throw InternalErr(__FILE__,__LINE__,msg);
1762 string objname_str = string(objname.begin(),objname.end());
1765 objname_str = objname_str.substr(0,objnamelen);
1767 string normal_dimname_mark = objname_str.substr(objname_str.find_last_of(
"/")+1);
1768 bool is_normal_dim = check_str_attr_value(attr_id,atype_id,normal_dimname_mark,
false);
1769 if(
true == is_normal_dim)
1777 H5T_str_t str_pad = H5Tget_strpad(atype_id);
1779 hid_t aspace_id = -1;
1780 aspace_id = H5Aget_space(attr_id);
1782 throw InternalErr(__FILE__, __LINE__,
"H5Aget_space fails in the attr_info call back function.");
1785 int ndims = H5Sget_simple_extent_ndims(aspace_id);
1791 vector<hsize_t> asize;
1792 vector<hsize_t> maxsize;
1793 asize.resize(ndims);
1794 maxsize.resize(ndims);
1800 if (H5Sget_simple_extent_dims(aspace_id, &asize[0], &maxsize[0])<0) {
1801 H5Sclose(aspace_id);
1802 throw InternalErr(__FILE__, __LINE__,
"Cannot obtain the dim. info in the H5Aiterate2 call back function.");
1806 for (
int j = 0; j < ndims; j++)
1810 size_t ty_size = H5Tget_size(atype_id);
1812 H5Sclose(aspace_id);
1813 throw InternalErr(__FILE__, __LINE__,
"Cannot obtain the type size in the H5Aiterate2 call back function.");
1816 size_t total_bytes = nelmts * ty_size;
1817 string total_vstring =
"";
1818 if(H5Tis_variable_str(atype_id) > 0) {
1821 vector<char> temp_buf;
1822 temp_buf.resize(total_bytes);
1824 if (H5Aread(attr_id, atype_id, &temp_buf[0]) < 0){
1825 H5Sclose(aspace_id);
1826 throw InternalErr(__FILE__,__LINE__,
"Cannot read the attribute in the H5Aiterate2 call back function");
1829 char *temp_bp = NULL;
1830 temp_bp = &temp_buf[0];
1831 char* onestring = NULL;
1833 for (
unsigned int temp_i = 0; temp_i <nelmts; temp_i++) {
1836 onestring =*(
char **)temp_bp;
1838 if(onestring!= NULL)
1839 total_vstring +=string(onestring);
1845 if ((&temp_buf[0]) != NULL) {
1847 if (H5Dvlen_reclaim(atype_id,aspace_id,H5P_DEFAULT,&temp_buf[0]) < 0) {
1848 H5Sclose(aspace_id);
1849 throw InternalErr(__FILE__,__LINE__,
"Cannot reclaim VL memory in the H5Aiterate2 call back function.");
1857 vector<char> temp_buf;
1858 temp_buf.resize(total_bytes);
1859 if (H5Aread(attr_id, atype_id, &temp_buf[0]) < 0){
1860 H5Sclose(aspace_id);
1861 throw InternalErr(__FILE__,__LINE__,
"Cannot read the attribute in the H5Aiterate2 call back function");
1863 string temp_buf_string(temp_buf.begin(),temp_buf.end());
1864 total_vstring = temp_buf_string.substr(0,total_bytes);
1867 if(str_pad != H5T_STR_ERROR)
1868 total_vstring = total_vstring.substr(0,total_vstring.size()-1);
1873 H5Sclose(aspace_id);
1874 if(total_vstring ==
"DIMENSION_SCALE"){
1907void obtain_dimnames(
const hid_t file_id,hid_t dset,
int ndims,
DS_t *dt_inst_ptr,vector<link_info_t> & hdf5_hls) {
1909 htri_t has_dimension_list = -1;
1911 string dimlist_name =
"DIMENSION_LIST";
1912 has_dimension_list = H5Aexists(dset,dimlist_name.c_str());
1914 if(has_dimension_list > 0 && ndims > 0) {
1917 vector<hvl_t> vlbuf;
1918 vlbuf.resize(ndims);
1921 hid_t atype_id = -1;
1922 hid_t amemtype_id = -1;
1923 hid_t aspace_id = -1;
1924 hid_t ref_dset = -1;
1927 attr_id = H5Aopen(dset,dimlist_name.c_str(),H5P_DEFAULT);
1929 string msg =
"Cannot open the attribute " + dimlist_name +
" of HDF5 dataset "+ string(dt_inst_ptr->
name);
1930 throw InternalErr(__FILE__, __LINE__, msg);
1933 atype_id = H5Aget_type(attr_id);
1935 string msg =
"Cannot get the datatype of the attribute " + dimlist_name +
" of HDF5 dataset "+ string(dt_inst_ptr->
name);
1936 throw InternalErr(__FILE__, __LINE__, msg);
1939 amemtype_id = H5Tget_native_type(atype_id, H5T_DIR_ASCEND);
1940 if (amemtype_id < 0) {
1941 string msg =
"Cannot get the memory datatype of the attribute " + dimlist_name +
" of HDF5 dataset "+ string(dt_inst_ptr->
name);
1942 throw InternalErr(__FILE__, __LINE__, msg);
1946 if (H5Aread(attr_id,amemtype_id,&vlbuf[0]) <0) {
1947 string msg =
"Cannot obtain the referenced object for the variable " + string(dt_inst_ptr->
name);
1948 throw InternalErr(__FILE__, __LINE__, msg);
1951 vector<char> objname;
1954 for (
int i = 0; i < ndims; i++) {
1956 if(vlbuf[i].p == NULL) {
1957 stringstream sindex ;
1959 string msg =
"For variable " + string(dt_inst_ptr->
name) +
"; ";
1960 msg = msg +
"the dimension of which the index is "+ sindex.str() +
" doesn't exist. ";
1961 throw InternalErr(__FILE__, __LINE__, msg);
1964 rbuf =((hobj_ref_t*)vlbuf[i].p)[0];
1967 if ((ref_dset = H5RDEREFERENCE(attr_id, H5R_OBJECT, &rbuf)) < 0) {
1968 string msg =
"Cannot dereference from the DIMENSION_LIST attribute for the variable " + string(dt_inst_ptr->
name);
1969 throw InternalErr(__FILE__, __LINE__, msg);
1972 ssize_t objnamelen = -1;
1973 if ((objnamelen= H5Iget_name(ref_dset,NULL,0))<=0) {
1974 string msg =
"Cannot obtain the dimension name length for the variable " + string(dt_inst_ptr->
name);
1975 throw InternalErr(__FILE__,__LINE__,msg);
1978 objname.resize(objnamelen+1);
1979 if ((objnamelen= H5Iget_name(ref_dset,&objname[0],objnamelen+1))<=0) {
1981 string msg =
"Cannot obtain the dimension name for the variable " + string(dt_inst_ptr->
name);
1982 throw InternalErr(__FILE__,__LINE__,msg);
1985 string objname_str = string(objname.begin(),objname.end());
1988 string trim_objname = objname_str.substr(0,objnamelen);
1993 H5O_info_t obj_info;
1994 if(H5OGET_INFO(ref_dset,&obj_info)<0) {
1996 string msg =
"Cannot obtain the object info for the dimension variable " + objname_str;
1997 throw InternalErr(__FILE__,__LINE__,msg);
2001 if(obj_info.rc > 1) {
2010 bool link_find =
false;
2013 for (
int i = 0; i <hdf5_hls.size();i++) {
2014#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2016 if(H5Otoken_cmp(ref_dset,&(obj_info.token),&(hdf5_hls[i].link_addr),&token_cmp) <0)
2017 throw InternalErr(__FILE__,__LINE__,
"H5Otoken_cmp failed");
2020 if(obj_info.addr == hdf5_hls[i].link_addr) {
2022 trim_objname =
'/'+hdf5_hls[i].slink_path;
2029 if(link_find ==
false) {
2031#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2033 unsigned link_unvisited;
2034 H5O_token_t link_addr;
2035 vector<string> hl_names;
2039 unsigned link_unvisited;
2041 vector<string> hl_names;
2045 t_link_info_t t_li_info;
2046 t_li_info.link_unvisited = obj_info.rc;
2048#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2049 memcpy(&t_li_info.link_addr,&obj_info.token,
sizeof(H5O_token_t));
2051 t_li_info.link_addr = obj_info.addr;
2054 if(H5Lvisit(file_id, H5_INDEX_NAME, H5_ITER_NATIVE, visit_link_cb, (
void*)&t_li_info) < 0) {
2057 err_msg =
"Find all hardlinks: H5Lvisit failed to iterate all the objects";
2058 throw InternalErr(__FILE__,__LINE__,err_msg);
2061for(
int i = 0; i<t_li_info.hl_names.size();i++)
2062 cerr<<
"hl name is "<<t_li_info.hl_names[i] <<endl;
2065 string shortest_hl = obtain_shortest_ancestor_path(t_li_info.hl_names);
2067 if(shortest_hl ==
"") {
2070 err_msg =
"The shortest hardlink is not located under an ancestor group of all links.";
2071 err_msg +=
"This is not supported by netCDF4 data model and the current Hyrax DAP4 implementation.";
2072 throw InternalErr(__FILE__,__LINE__,err_msg);
2077#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2078 memcpy(&new_hdf5_hl.link_addr,&obj_info.token,
sizeof(H5O_token_t));
2080 new_hdf5_hl.link_addr = obj_info.addr;
2082 new_hdf5_hl.slink_path = shortest_hl;
2083 hdf5_hls.push_back(new_hdf5_hl);
2084 trim_objname =
'/'+shortest_hl;
2090 dt_inst_ptr->dimnames.push_back(trim_objname.substr(trim_objname.find_last_of(
"/")+1));
2091 dt_inst_ptr->dimnames_path.push_back(trim_objname);
2093 if(H5Dclose(ref_dset)<0) {
2094 throw InternalErr(__FILE__,__LINE__,
"Cannot close the HDF5 dataset in the function obtain_dimnames().");
2098 if(vlbuf.empty()==
false) {
2100 if ((aspace_id = H5Aget_space(attr_id)) < 0) {
2101 string msg =
"Cannot close the HDF5 attribute space successfully for <DIMENSION_LIST> of the variable "+string(dt_inst_ptr->
name);
2102 throw InternalErr(__FILE__,__LINE__,msg);
2105 if (H5Dvlen_reclaim(amemtype_id,aspace_id,H5P_DEFAULT,(
void*)&vlbuf[0])<0) {
2106 throw InternalErr(__FILE__,__LINE__,
"Cannot reclaim the variable length memory in the function obtain_dimnames()");
2109 H5Sclose(aspace_id);
2114 H5Tclose(amemtype_id);
2124 if(amemtype_id != -1)
2125 H5Tclose(amemtype_id);
2128 H5Sclose(aspace_id);
2140void write_vlen_str_attrs(hid_t attr_id,hid_t ty_id,
DSattr_t * attr_inst_ptr,D4Attribute *d4_attr, AttrTable* d2_attr,
bool is_dap4){
2142 BESDEBUG(
"h5",
"attribute name " << attr_inst_ptr->
name <<endl);
2143 BESDEBUG(
"h5",
"attribute size " <<attr_inst_ptr->
need <<endl);
2144 BESDEBUG(
"h5",
"attribute type size " <<(
int)(H5Tget_size(ty_id))<<endl);
2146 hid_t temp_space_id = H5Aget_space(attr_id);
2147 BESDEBUG(
"h5",
"attribute calculated size "<<(
int)(H5Tget_size(ty_id)) *(
int)(H5Sget_simple_extent_npoints(temp_space_id)) <<endl);
2148 if(temp_space_id <0) {
2153 throw InternalErr(__FILE__, __LINE__,
"unable to read HDF5 attribute data");
2156 vector<char> temp_buf;
2158 temp_buf.resize((
size_t)attr_inst_ptr->
need);
2160 if (H5Aread(attr_id, ty_id, &temp_buf[0]) < 0) {
2163 H5Sclose(temp_space_id);
2166 throw InternalErr(__FILE__, __LINE__,
"unable to read HDF5 attribute data");
2170 temp_bp = &temp_buf[0];
2172 for (
unsigned int temp_i = 0; temp_i <attr_inst_ptr->
nelmts; temp_i++) {
2175 onestring =*(
char **)temp_bp;
2178 if (onestring !=NULL) {
2179 string tempstring(onestring);
2181 d4_attr->add_value(tempstring);
2183 d2_attr->append_attr(attr_inst_ptr->
name,
"String",tempstring);
2186 temp_bp +=H5Tget_size(ty_id);
2188 if (temp_buf.empty() !=
true) {
2191 herr_t ret_vlen_claim;
2192 ret_vlen_claim = H5Dvlen_reclaim(ty_id,temp_space_id,H5P_DEFAULT,&temp_buf[0]);
2193 if(ret_vlen_claim < 0){
2196 H5Sclose(temp_space_id);
2199 throw InternalErr(__FILE__, __LINE__,
"Cannot reclaim the memory buffer of the HDF5 variable length string.");
2204 H5Sclose(temp_space_id);
2207bool check_str_attr_value(hid_t attr_id,hid_t atype_id,
const string & value_to_compare,
bool check_substr) {
2209 bool ret_value =
false;
2211 H5T_str_t str_pad = H5Tget_strpad(atype_id);
2212 if(str_pad == H5T_STR_ERROR)
2213 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain string pad.");
2215 hid_t aspace_id = -1;
2216 aspace_id = H5Aget_space(attr_id);
2218 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain attribute space.");
2220 int ndims = H5Sget_simple_extent_ndims(aspace_id);
2222 H5Sclose(aspace_id);
2223 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain number of dimensions.");
2231 vector<hsize_t> asize;
2232 asize.resize(ndims);
2233 if (H5Sget_simple_extent_dims(aspace_id, &asize[0], NULL)<0) {
2234 H5Sclose(aspace_id);
2235 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the dimension info.");
2239 for (
int j = 0; j < ndims; j++)
2243 size_t ty_size = H5Tget_size(atype_id);
2245 H5Sclose(aspace_id);
2246 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the type size.");
2249 size_t total_bytes = nelmts * ty_size;
2250 string total_vstring =
"";
2251 if(H5Tis_variable_str(atype_id) > 0) {
2254 vector<char> temp_buf;
2255 temp_buf.resize(total_bytes);
2257 if (H5Aread(attr_id, atype_id, &temp_buf[0]) < 0){
2258 H5Sclose(aspace_id);
2259 throw InternalErr(__FILE__,__LINE__,
"Fail to read the attribute.");
2262 char *temp_bp = NULL;
2263 temp_bp = &temp_buf[0];
2264 char* onestring = NULL;
2266 for (
unsigned int temp_i = 0; temp_i <nelmts; temp_i++) {
2269 onestring =*(
char **)temp_bp;
2271 if(onestring!= NULL)
2272 total_vstring +=string(onestring);
2278 if ((&temp_buf[0]) != NULL) {
2280 if (H5Dvlen_reclaim(atype_id,aspace_id,H5P_DEFAULT,&temp_buf[0]) < 0) {
2281 H5Sclose(aspace_id);
2282 throw InternalErr(__FILE__,__LINE__,
"Fail to reclaim VL memory.");
2290 vector<char> temp_buf;
2291 temp_buf.resize(total_bytes);
2292 if (H5Aread(attr_id, atype_id, &temp_buf[0]) < 0){
2293 H5Sclose(aspace_id);
2294 throw InternalErr(__FILE__,__LINE__,
"Fail to read the attribute.");
2296 string temp_buf_string(temp_buf.begin(),temp_buf.end());
2297 total_vstring = temp_buf_string.substr(0,total_bytes);
2300 if(str_pad != H5T_STR_ERROR)
2301 total_vstring = total_vstring.substr(0,total_vstring.size()-1);
2306 H5Sclose(aspace_id);
2308 if(
false == check_substr) {
2309 if(total_vstring == value_to_compare)
2313 if(total_vstring.size()>=value_to_compare.size()) {
2314 if( 0 == total_vstring.compare(0,value_to_compare.size(),value_to_compare))
2323visit_link_cb(hid_t group_id,
const char *name,
const H5L_info_t *linfo,
2326#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2328 unsigned link_unvisited;
2329 H5O_token_t link_addr;
2330 vector<string> hl_names;
2334 unsigned link_unvisited;
2336 vector<string> hl_names;
2340 t_link_info_t *op_data = (t_link_info_t *)_op_data;
2344 if(linfo->type == H5L_TYPE_HARD) {
2345#if (H5_VERS_MAJOR == 1 && ((H5_VERS_MINOR == 12) || (H5_VERS_MINOR == 13)))
2347 if(H5Otoken_cmp(group_id,&(op_data->link_addr),&(linfo->u.token),&token_cmp) <0)
2348 throw InternalErr(__FILE__,__LINE__,
"H5Otoken_cmp failed");
2351 if(op_data->link_addr == linfo->u.address) {
2353 op_data->link_unvisited = op_data->link_unvisited -1;
2354 string tmp_str(name,name+strlen(name));
2355 op_data->hl_names.push_back(tmp_str);
2357 if(op_data->link_unvisited == 0)
2367std::string obtain_shortest_ancestor_path(
const std::vector<std::string> & hls) {
2369 vector<string> hls_path;
2371 bool hl_under_root =
false;
2375 for (i= 0; i<hls.size(); i++) {
2377 size_t path_pos = hls[i].find_last_of(slash);
2381 if(path_pos == std::string::npos) {
2383 hl_under_root =
true;
2387 string tmp_str = hls[i].substr(0,path_pos+1);
2388 hls_path.push_back(tmp_str);
2397 unsigned short_path_index = 0;
2398 unsigned min_path_size = hls_path[0].size();
2401 for(
unsigned j = 1; j <hls_path.size();j++) {
2402 if(min_path_size>hls_path[j].size()) {
2403 min_path_size = hls_path[j].size();
2404 short_path_index = j;
2407 string tmp_sp = hls_path[short_path_index];
2408 ret_str = hls[short_path_index];
2412 for(
unsigned j = 0; j <hls_path.size();j++) {
2413 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.