34#include <libdap/InternalErr.h> 
   52    BESDEBUG(
"h5", 
">get_data()" << endl);
 
   55    if ((dtype = H5Dget_type(dset)) < 0) {
 
   56        throw InternalErr(__FILE__, __LINE__, 
"Failed to get the datatype of the dataset");
 
   59    if ((dspace = H5Dget_space(dset)) < 0) {
 
   61        throw InternalErr(__FILE__, __LINE__, 
"Failed to get the data space of the dataset");
 
   64    hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
 
   68        throw InternalErr(__FILE__, __LINE__, 
"failed to get memory type");
 
   71    if (H5Dread(dset, memtype, dspace, dspace, H5P_DEFAULT, buf)
 
   76        throw InternalErr(__FILE__, __LINE__, 
"failed to read data");
 
   79    if (H5Tclose(dtype) < 0){
 
   82    throw InternalErr(__FILE__, __LINE__, 
"Unable to release the dtype.");
 
   85    if (H5Tclose(memtype) < 0){
 
   87        throw InternalErr(__FILE__, __LINE__, 
"Unable to release the memtype.");
 
   90    if(H5Sclose(dspace)<0) {
 
   91        throw InternalErr(__FILE__, __LINE__, 
"Unable to release the data space.");
 
  101    BESDEBUG(
"h5", 
"<get_data()" << endl);
 
 
  115void get_strdata(int64_t strindex, 
char *allbuf, 
char *buf, 
int elesize)
 
  117    char *tempvalue = allbuf;   
 
  119    BESDEBUG(
"h5", 
">get_strdata(): " 
  120        << 
" strindex=" << strindex << 
" allbuf=" << allbuf << endl);
 
  126    for (
int i = 0; i < strindex; i++) {
 
  127        tempvalue = tempvalue + elesize;
 
  130    tempvalue = tempvalue +strindex *elesize;
 
  132    strncpy(buf, tempvalue, elesize);
 
  149get_slabdata(hid_t dset, 
const int64_t *offset, 
const int64_t *step, 
const int64_t *count, 
const int num_dim,
 
  152    BESDEBUG(
"h5", 
">get_slabdata() " << endl);
 
  154    hid_t dtype = H5Dget_type(dset);
 
  156        throw InternalErr(__FILE__, __LINE__, 
"could not get data type");
 
  159    hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
 
  162        throw InternalErr(__FILE__, __LINE__, 
"could not get memory type");
 
  165    hid_t dspace = H5Dget_space(dset);
 
  169        throw InternalErr(__FILE__, __LINE__, 
"could not get data space");
 
  173    vector<hsize_t>dyn_count;
 
  174    vector<hsize_t>dyn_step;
 
  175    vector<hssize_t>dyn_offset;
 
  176    dyn_count.resize(num_dim);
 
  177    dyn_step.resize(num_dim);
 
  178    dyn_offset.resize(num_dim);
 
  180    for (
int i = 0; i < num_dim; i++) {
 
  181        dyn_count[i] = (hsize_t) (*count);
 
  182        dyn_step[i] = (hsize_t) (*step);
 
  183        dyn_offset[i] = (hssize_t) (*offset);
 
  185                "count:" << dyn_count[i]
 
  186                << 
" step:" << dyn_step[i]
 
  187                << 
" offset:" << dyn_step[i]
 
  194    if (H5Sselect_hyperslab(dspace, H5S_SELECT_SET, 
 
  195                           (
const hsize_t *)dyn_offset.data(), dyn_step.data(),
 
  196                            dyn_count.data(), 
nullptr) < 0) {
 
  200        throw InternalErr(__FILE__, __LINE__, 
"could not select hyperslab");
 
  203    hid_t memspace = H5Screate_simple(num_dim, dyn_count.data(), 
nullptr);
 
  208        throw InternalErr(__FILE__, __LINE__, 
"could not open space");
 
  211    if (H5Dread(dset, memtype, memspace, dspace, H5P_DEFAULT, buf) < 0) {
 
  216        throw InternalErr(__FILE__, __LINE__, 
"could not get data");
 
  219    if (H5Sclose(dspace) < 0){
 
  223    throw InternalErr(__FILE__, __LINE__, 
"Unable to close the dspace.");
 
  225    if (H5Sclose(memspace) < 0){
 
  228        throw InternalErr(__FILE__, __LINE__, 
"Unable to close the memspace.");
 
  230    if (H5Tclose(dtype) < 0){
 
  232        throw InternalErr(__FILE__, __LINE__, 
"Unable to close the dtype.");
 
  235    if (H5Tclose(memtype) < 0){
 
  236            throw InternalErr(__FILE__, __LINE__, 
"Unable to close the memtype.");
 
  239    BESDEBUG(
"h5", 
"<get_slabdata() " << endl);
 
  243bool read_vlen_string(hid_t dsetid, 
const int64_t nelms, 
const hsize_t *hoffset, 
const hsize_t *hstep,
 
  244                      const hsize_t *hcount, vector<string> &finstrval)
 
  251    bool is_scalar = 
false;
 
  254    if ((dspace = H5Dget_space(dsetid))<0) {
 
  255        throw InternalErr (__FILE__, __LINE__, 
"Cannot obtain data space.");
 
  258    if(H5S_SCALAR == H5Sget_simple_extent_type(dspace))
 
  263        if (H5Sselect_hyperslab(dspace, H5S_SELECT_SET,
 
  265                               hcount, 
nullptr) < 0) {
 
  267            throw InternalErr (__FILE__, __LINE__, 
"Cannot generate the hyperslab of the HDF5 dataset.");
 
  270        int d_num_dim = H5Sget_simple_extent_ndims(dspace);
 
  273            throw InternalErr (__FILE__, __LINE__, 
"Cannot obtain the number of dimensions of the data space.");
 
  276        mspace = H5Screate_simple(d_num_dim, hcount,
nullptr);
 
  279            throw InternalErr (__FILE__, __LINE__, 
"Cannot create the memory space.");
 
  284    if ((dtypeid = H5Dget_type(dsetid)) < 0) {
 
  289        throw InternalErr (__FILE__, __LINE__, 
"Cannot obtain the datatype.");
 
  293    if ((memtype = H5Tget_native_type(dtypeid, H5T_DIR_ASCEND))<0) {
 
  299        throw InternalErr (__FILE__, __LINE__, 
"Fail to obtain memory datatype.");
 
  303    size_t ty_size = H5Tget_size(memtype);
 
  305    vector <char> strval;
 
  306    strval.resize(nelms*ty_size);
 
  309        read_ret = H5Dread(dsetid,
 
  314                           (
void*)strval.data());
 
  316        read_ret = H5Dread(dsetid,
 
  321                           (
void*)strval.data());
 
  329        throw InternalErr (__FILE__, __LINE__, 
"Fail to read the HDF5 variable length string dataset.");
 
  334    char *temp_bp = strval.data();
 
  335    for (
int i =0;i<nelms;i++) {
 
  336        char *onestring = *(
char**)temp_bp;
 
  337        if (onestring != 
nullptr )
 
  338            finstrval[i] =string(onestring);
 
  344    read_vlen_string_value(nelms, strval, finstrval, ty_size);
 
  345    claim_vlen_string_memory(memtype, dspace, dtypeid, mspace, strval, is_scalar);
 
  347    if (
false == strval.empty()) {
 
  348        herr_t ret_vlen_claim;
 
  349        if (
true == is_scalar) 
 
  350            ret_vlen_claim = H5Dvlen_reclaim(memtype,dspace,H5P_DEFAULT,(
void*)strval.data());
 
  352            ret_vlen_claim = H5Dvlen_reclaim(memtype,mspace,H5P_DEFAULT,(
void*)strval.data());
 
  353        if (ret_vlen_claim < 0){
 
  354            if (
false == is_scalar) 
 
  359            throw InternalErr (__FILE__, __LINE__, 
"Cannot reclaim the memory buffer of the HDF5 variable length string.");
 
  364    if (
false == is_scalar) 
 
  374void read_vlen_string_value(
const int64_t nelms, vector<char> &strval, vector<string>&finstrval, 
size_t ty_size ) {
 
  376    const char *temp_bp = strval.data();
 
  377    for (
int i =0;i<nelms;i++) {
 
  379        get_vlen_str_data(temp_bp, finalstr_val);
 
  380        finstrval[i] = finalstr_val;
 
  382        char *onestring = *(
char**)temp_bp;
 
  383        if (onestring != 
nullptr )
 
  384            finstrval[i] =string(onestring);
 
  393void claim_vlen_string_memory(hid_t memtype, hid_t dspace, hid_t dtypeid, hid_t mspace, vector<char> &strval,
 
  396    if (
false == strval.empty()) {
 
  397        herr_t ret_vlen_claim;
 
  398        if (
true == is_scalar)
 
  399            ret_vlen_claim = H5Dvlen_reclaim(memtype,dspace,H5P_DEFAULT,(
void*)strval.data());
 
  401            ret_vlen_claim = H5Dvlen_reclaim(memtype,mspace,H5P_DEFAULT,(
void*)strval.data());
 
  402        if (ret_vlen_claim < 0){
 
  403            if (
false == is_scalar)
 
  408            throw InternalErr (__FILE__, __LINE__, 
"Cannot reclaim the memory buffer of the HDF5 variable length string.");
 
  413bool promote_char_to_short(H5T_class_t type_cls, hid_t type_id) {
 
  415    bool ret_value = 
false;
 
  416    if(type_cls == H5T_INTEGER) {
 
  417        size_t size = H5Tget_size(type_id);
 
  418        int sign = H5Tget_sign(type_id);
 
  419        if(size == 1 && sign == H5T_SGN_2)
 
  427void get_vlen_str_data(
const char*temp_bp,
string &finalstr_val) {
 
  429    const char *onestring = *(
const char**)temp_bp;
 
  430    if(onestring!=
nullptr )
 
  431        finalstr_val =string(onestring);
 
void get_data(hid_t dset, void *buf)