76    if (H5Gget_info(pid, &g_info) < 0) {
 
   77        string msg = 
"h5_das handler: unable to obtain the HDF5 group info. for ";
 
   79        throw InternalErr(__FILE__, __LINE__, msg);
 
   81    nelems = g_info.nlinks;
 
   83    ssize_t oname_size = 0;
 
   84    for (hsize_t i = 0; i < nelems; i++) {
 
   87        oname_size = H5Lget_name_by_idx(pid, 
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, 
nullptr, (
size_t) 
DODS_NAMELEN,
 
   90        if (oname_size <= 0) {
 
   91            string msg = 
"hdf5 object name error from: ";
 
   93            throw InternalErr(__FILE__, __LINE__, msg);
 
   96        vector<char> oname(oname_size + 1);
 
   97        if (H5Lget_name_by_idx(pid, 
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, oname.data(), (
size_t) (oname_size + 1),
 
   99            string msg = 
"hdf5 object name error from: ";
 
  101            throw InternalErr(__FILE__, __LINE__, msg);
 
  106        if (H5Lget_info(pid, oname.data(), &linfo, H5P_DEFAULT) < 0) {
 
  107            string msg = 
"hdf5 link name error from: ";
 
  109            throw InternalErr(__FILE__, __LINE__, msg);
 
  113        if (linfo.type == H5L_TYPE_SOFT) {
 
  115            size_t val_size = linfo.u.val_size;
 
  116            get_softlink(das, pid, gname, oname.data(), slinkindex, val_size);
 
  122        if (H5OGET_INFO_BY_IDX(pid, 
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT) < 0) {
 
  123            string msg = 
"Cannot obtain the object info ";
 
  125            throw InternalErr(__FILE__, __LINE__, msg);
 
  127        H5O_type_t obj_type = oinfo.type;
 
  131        case H5O_TYPE_GROUP: {
 
  133            BESDEBUG(
"h5", 
"=depth_first():H5G_GROUP " << oname.data() << endl);
 
  136            add_group_structure_info(das, gname, oname.data(), 
true);
 
  138            string full_path_name = string(gname) + string(oname.data()) + 
"/";
 
  140            hid_t cgroup = H5Gopen(pid, full_path_name.c_str(), H5P_DEFAULT);
 
  142                string msg = 
"opening hdf5 group failed for ";
 
  143                msg += full_path_name;
 
  144                throw InternalErr(__FILE__, __LINE__, msg);
 
  149            if (H5OGET_INFO(cgroup, &obj_info) < 0) {
 
  151                string msg = 
"Obtaining the hdf5 group info. failed for ";
 
  152                msg += full_path_name;
 
  153                throw InternalErr(__FILE__, __LINE__, msg);
 
  157            auto num_attr = (
int)obj_info.num_attrs;
 
  160                string msg = 
"Fail to get the number of attributes for group ";
 
  161                msg += full_path_name;
 
  162                throw InternalErr(__FILE__, __LINE__, msg);
 
  167                read_objects(das, full_path_name.c_str(), cgroup, num_attr);
 
  175            string oid = 
get_hardlink(cgroup, full_path_name.c_str());
 
  186                AttrTable *at = das.get_table(full_path_name);
 
  188                    auto new_attr_table_unique = make_unique<libdap::AttrTable>();
 
  189                    at = das.add_table(full_path_name, new_attr_table_unique.release());
 
  194                at->append_attr(
"HDF5_HARDLINK", STRING, 
paths.get_name(oid));
 
  197            if (H5Gclose(cgroup) < 0) {
 
  198                throw InternalErr(__FILE__, __LINE__, 
"H5Gclose() failed.");
 
  203        case H5O_TYPE_DATASET: {
 
  205            BESDEBUG(
"h5", 
"=depth_first():H5G_DATASET " << oname.data() << endl);
 
  208            add_group_structure_info(das, gname, oname.data(), 
false);
 
  210            string full_path_name = string(gname) + string(oname.data());
 
  214            if ((dset = H5Dopen(pid, full_path_name.c_str(), H5P_DEFAULT)) < 0) {
 
  215                string msg = 
"unable to open the hdf5 dataset of the group ";
 
  217                throw InternalErr(__FILE__, __LINE__, msg);
 
  222            if (H5OGET_INFO(dset, &obj_info) < 0) {
 
  224                string msg = 
"Obtaining the info. failed for the dataset ";
 
  225                msg += full_path_name;
 
  226                throw InternalErr(__FILE__, __LINE__, msg);
 
  230            auto num_attr = (
int)(obj_info.num_attrs);
 
  233                string msg = 
"Fail to get the number of attributes for dataset ";
 
  234                msg += full_path_name;
 
  235                throw InternalErr(__FILE__, __LINE__, msg);
 
  256                AttrTable *at = das.get_table(full_path_name);
 
  258                    auto new_attr_table_unique = make_unique<libdap::AttrTable>();
 
  259                    at = das.add_table(full_path_name, new_attr_table_unique.release());
 
  264                at->append_attr(
"HDF5_HARDLINK", STRING, 
paths.get_name(oid));
 
  267            if (H5Dclose(dset) < 0) {
 
  268                throw InternalErr(__FILE__, __LINE__, 
"Could not close the dataset.");
 
  273        case H5O_TYPE_NAMED_DATATYPE:
 
  282    BESDEBUG(
"h5", 
"<depth_first():" << gname << endl);
 
 
  299void read_objects(DAS & das, 
const string & varname, hid_t oid, 
int num_attr)
 
  302    BESDEBUG(
"h5", 
">read_objects():" << 
"varname=" << varname << 
" id=" << oid << endl);
 
  309    AttrTable *attr_table_ptr = das.get_table(varname);
 
  310    if (!attr_table_ptr) {
 
  311        BESDEBUG(
"h5", 
"=read_objects(): adding a table with name " << varname << endl);
 
  312        auto new_attr_table_unique = make_unique<libdap::AttrTable>();
 
  313        attr_table_ptr = das.add_table(varname, new_attr_table_unique.release());
 
  317    attr_table_ptr->append_attr(hdf5_path.c_str(), STRING, varname);
 
  322    vector<char> temp_buf;
 
  324    bool ignore_attr = 
false;
 
  326    for (
int j = 0; j < num_attr; j++) {
 
  334        attr_id = get_attr_info(oid, j, 
false, &attr_inst, &ignore_attr);
 
  335        if (
true == ignore_attr) {
 
  342        hid_t ty_id = H5Aget_type(attr_id);
 
  343        string dap_type = get_dap_type(ty_id, 
false);
 
  344        string attr_name = attr_inst.
name;
 
  346        bool is_utf8_str = 
false;
 
  347        if (dap_type == STRING) {
 
  348            H5T_cset_t c_set_type = H5Tget_cset(ty_id);
 
  350                throw InternalErr(__FILE__, __LINE__, 
"Cannot get hdf5 character set type for the attribute.");
 
  351            if (HDF5RequestHandler::get_escape_utf8_attr() == 
false && (c_set_type == H5T_CSET_UTF8))
 
  356        if (H5Tis_variable_str(ty_id)) 
 
  357            write_vlen_str_attrs(attr_id,ty_id,&attr_inst,
nullptr,attr_table_ptr,
false);
 
  360            value.resize(attr_inst.
need);
 
  361            BESDEBUG(
"h5", 
"arttr_inst.need=" << attr_inst.
need << endl);
 
  363            hid_t memtype = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
 
  365            if (H5Aread(attr_id, memtype, (
void *) (value.data())) < 0)
 
  366                throw InternalErr(__FILE__, __LINE__, 
"unable to read HDF5 attribute data");
 
  371            if (attr_inst.
ndims == 0) {
 
  372                for (
int loc = 0; loc < (
int) attr_inst.
nelmts; loc++) {
 
  373                    print_rep = print_attr(ty_id, loc, value.data());
 
  374                    if (print_rep.c_str() != 
nullptr) {
 
  376                            attr_table_ptr->append_attr(attr_name, dap_type, print_rep.c_str(),
true);
 
  378                            attr_table_ptr->append_attr(attr_name, dap_type, print_rep.c_str());
 
  384                BESDEBUG(
"h5", 
"=read_objects(): ndims=" << (
int) attr_inst. ndims << endl);
 
  387                auto elesize = (
int) H5Tget_size(ty_id);
 
  389                    BESDEBUG(
"h5", 
"=read_objects(): elesize=0" << endl);
 
  392                    throw InternalErr(__FILE__, __LINE__, 
"unable to get attibute size");
 
  397                char *tempvalue = value.data();
 
  401                for (hsize_t temp_index = 0; temp_index < attr_inst.
nelmts; temp_index++) {
 
  402                    print_rep = print_attr(ty_id, 0, tempvalue);
 
  403                    if (print_rep.c_str() != 
nullptr) {
 
  405                            attr_table_ptr->append_attr(attr_name, dap_type, print_rep.c_str(),
true);
 
  407                            attr_table_ptr->append_attr(attr_name, dap_type, print_rep.c_str());
 
  409                        tempvalue = tempvalue + elesize;
 
  411                        BESDEBUG(
"h5", 
"tempvalue=" << tempvalue << 
"elesize=" << elesize << endl);
 
  417                        throw InternalErr(__FILE__, __LINE__, 
"unable to convert attibute value to DAP");
 
  422        if (H5Tclose(ty_id) < 0) {
 
  424            throw InternalErr(__FILE__, __LINE__, 
"unable to close HDF5 type id");
 
  426        if (H5Aclose(attr_id) < 0) {
 
  427            throw InternalErr(__FILE__, __LINE__, 
"unable to close attibute id");
 
  430    BESDEBUG(
"h5", 
"<read_objects()" << endl);
 
 
  446    BESDEBUG(
"h5", 
">find_gloattr()" << endl);
 
  448    hid_t root = H5Gopen(file, 
"/", H5P_DEFAULT);
 
  450        if (root < 0) 
throw InternalErr(__FILE__, __LINE__, 
"unable to open the HDF5 root group");
 
  457        auto new_attr_table_unique = make_unique<libdap::AttrTable>();
 
  458        das.add_table(
"HDF5_ROOT_GROUP", new_attr_table_unique.release());
 
  469        if (H5OGET_INFO(root, &obj_info) < 0) {
 
  471            string msg = 
"Obtaining the info. failed for the root group ";
 
  472            throw InternalErr(__FILE__, __LINE__, msg);
 
  476        num_attrs = obj_info.num_attrs;
 
  479            throw InternalErr(__FILE__, __LINE__, 
"unable to get the number of attributes for the HDF root group ");
 
  482        if (num_attrs == 0) {
 
  483            if (H5Gclose(root) < 0) {
 
  484                throw InternalErr(__FILE__, __LINE__, 
"Could not close the group.");
 
  486            BESDEBUG(
"h5", 
"<find_gloattr():no attributes" << endl);
 
  495        BESDEBUG(
"h5", 
"=find_gloattr(): H5Gclose()" << endl);
 
  496        if (H5Gclose(root) < 0) {
 
  497            throw InternalErr(__FILE__, __LINE__, 
"Could not close the group.");
 
  499        BESDEBUG(
"h5", 
"<find_gloattr()" << endl);
 
  502        if (H5Gclose(root) < 0) {
 
  503            throw InternalErr(__FILE__, __LINE__, 
"Could not close the group.");