OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
h5get.cc
Go to the documentation of this file.
1 // This file is part of hdf5_handler a HDF5 file handler for the OPeNDAP
2 // data server.
3 
4 // Copyright (c) 2007-2013 The HDF Group, Inc. and OPeNDAP, Inc.
5 //
6 // This is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your
9 // option) any later version.
10 //
11 // This software is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
21 // You can contact The HDF Group, Inc. at 1901 South First Street,
22 // Suite C-2, Champaign, IL 61820
23 
36 
37 #include "h5get.h"
38 
39 using namespace libdap;
40 
56 hid_t get_attr_info(hid_t dset, int index, DSattr_t * attr_inst_ptr,
57  bool *ignore_attr_ptr)
58 {
59 
60  hid_t attrid;
61 
62  // Always assume that we don't ignore any attributes.
63  *ignore_attr_ptr = false;
64 
65  if ((attrid = H5Aopen_by_idx(dset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC,(hsize_t)index, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
66  string msg = "unable to open attribute by index ";
67  msg += index;
68  throw InternalErr(__FILE__, __LINE__, msg);
69  }
70 
71  // Obtain the size of attribute name.
72  ssize_t name_size = H5Aget_name(attrid, 0, NULL);
73  if (name_size < 0) {
74  H5Aclose(attrid);
75  string msg = "unable to obtain the size of the hdf5 attribute name ";
76  throw InternalErr(__FILE__, __LINE__, msg);
77  };
78 
79  vector<char> attr_name;
80  attr_name.resize(name_size+1);
81  // Obtain the attribute name.
82  if ((H5Aget_name(attrid, name_size+1, &attr_name[0])) < 0) {
83  H5Aclose(attrid);
84  string msg = "unable to obtain the hdf5 attribute name ";
85  throw InternalErr(__FILE__, __LINE__, msg);
86  }
87 
88  // Obtain the type of the attribute.
89  hid_t ty_id;
90  if ((ty_id = H5Aget_type(attrid)) < 0) {
91  string msg = "unable to obtain hdf5 datatype for the attribute ";
92  string attrnamestr(attr_name.begin(),attr_name.end());
93  msg += attrnamestr;
94  H5Aclose(attrid);
95  throw InternalErr(__FILE__, __LINE__, msg);
96  }
97 
98  H5T_class_t ty_class = H5Tget_class(ty_id);
99  if (ty_class < 0) {
100  string msg = "cannot get hdf5 attribute datatype class for the attribute ";
101  string attrnamestr(attr_name.begin(),attr_name.end());
102  msg += attrnamestr;
103  H5Aclose(attrid);
104  throw InternalErr(__FILE__, __LINE__, msg);
105  }
106 
107  // The following datatype will not be supported for mapping to DAS.
108  // Note: H5T_COMPOUND and H5T_ARRAY can be mapped to DAP2 DAS(variable)
109  // but not map to DAS due to really rarely used and unimportance.
110  // 1-D variable length of string can also be mapped to both DAS and DDS.
111  // The variable length string class is H5T_STRING rather than H5T_VLEN,
112  // So safe here.
113  // We also ignore the mapping of integer 64 bit since DAP2 doesn't
114  // support 64-bit integer. In theory, DAP2 doesn't support long double
115  // (128-bit or 92-bit floating point type), since this rarely happens
116  // in DAP application, we simply don't consider here.
117  if ((ty_class == H5T_TIME) || (ty_class == H5T_BITFIELD)
118  || (ty_class == H5T_OPAQUE) || (ty_class == H5T_ENUM)
119  || (ty_class == H5T_REFERENCE) ||(ty_class == H5T_COMPOUND)
120  || (ty_class == H5T_VLEN) || (ty_class == H5T_ARRAY)
121  || ((ty_class == H5T_INTEGER) && (H5Tget_size(ty_id)== 8))) {//64-bit int
122 
123  *ignore_attr_ptr = true;
124  return attrid;
125  }
126 
127  hid_t aspace_id;
128  if ((aspace_id = H5Aget_space(attrid)) < 0) {
129  string msg = "cannot get hdf5 dataspace id for the attribute ";
130  string attrnamestr(attr_name.begin(),attr_name.end());
131  msg += attrnamestr;
132  H5Aclose(attrid);
133  throw InternalErr(__FILE__, __LINE__, msg);
134  }
135 
136  // It is better to use the dynamic allocation of the array.
137  // However, since the DODS_MAX_RANK is not big and it is also
138  // used in other location, we still keep the original code.
139  // KY 2011-11-16
140 
141  int ndims = H5Sget_simple_extent_ndims(aspace_id);
142  if (ndims < 0) {
143  string msg = "cannot get hdf5 dataspace number of dimension for attribute ";
144  string attrnamestr(attr_name.begin(),attr_name.end());
145  msg += attrnamestr;
146  H5Sclose(aspace_id);
147  H5Aclose(attrid);
148  throw InternalErr(__FILE__, __LINE__, msg);
149  }
150 
151  // Check if the dimension size exceeds the maximum number of dimension DAP supports
152  if (ndims > DODS_MAX_RANK) {
153  string msg = "number of dimensions exceeds allowed for attribute ";
154  string attrnamestr(attr_name.begin(),attr_name.end());
155  msg += attrnamestr;
156  H5Sclose(aspace_id);
157  H5Aclose(attrid);
158  throw InternalErr(__FILE__, __LINE__, msg);
159  }
160 
161  hsize_t size[DODS_MAX_RANK];
162  hsize_t maxsize[DODS_MAX_RANK];
163 
164  // DAP applications don't care about the unlimited dimensions
165  // since the applications only care about retrieving the data.
166  // So we don't check the maxsize to see if it is the unlimited dimension
167  // attribute.
168  if (H5Sget_simple_extent_dims(aspace_id, size, maxsize)<0){
169  string msg = "cannot obtain the dim. info for the attribute ";
170  string attrnamestr(attr_name.begin(),attr_name.end());
171  msg += attrnamestr;
172  H5Sclose(aspace_id);
173  H5Aclose(attrid);
174  throw InternalErr(__FILE__, __LINE__, msg);
175  }
176 
177 
178  // Return ndims and size[ndims].
179  hsize_t nelmts = 1;
180  if (ndims) {
181  for (int j = 0; j < ndims; j++)
182  nelmts *= size[j];
183  }
184 
185 
186  size_t ty_size = H5Tget_size(ty_id);
187  if (ty_size == 0) {
188  string msg = "cannot obtain the dtype size for the attribute ";
189  string attrnamestr(attr_name.begin(),attr_name.end());
190  msg += attrnamestr;
191  H5Sclose(aspace_id);
192  H5Aclose(attrid);
193  throw InternalErr(__FILE__, __LINE__, msg);
194  }
195 
196 
197  size_t need = nelmts * H5Tget_size(ty_id);
198 
199  // We want to save memory type in the struct.
200  hid_t memtype = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
201 
202  if (memtype < 0){
203  string msg = "cannot obtain the memory dtype for the attribute ";
204  string attrnamestr(attr_name.begin(),attr_name.end());
205  msg += attrnamestr;
206  H5Sclose(aspace_id);
207  H5Aclose(attrid);
208  throw InternalErr(__FILE__, __LINE__, msg);
209  }
210 
211  // Save the information to the struct
212  (*attr_inst_ptr).type = memtype;
213  (*attr_inst_ptr).ndims = ndims;
214  (*attr_inst_ptr).nelmts = nelmts;
215  (*attr_inst_ptr).need = need;
216  strncpy((*attr_inst_ptr).name, &attr_name[0], name_size+1);
217 
218  for (int j = 0; j < ndims; j++) {
219  (*attr_inst_ptr).size[j] = size[j];
220  }
221 
222  H5Sclose(aspace_id);
223 
224  return attrid;
225 }
226 
237 string get_dap_type(hid_t type)
238 {
239  size_t size = 0;
240  H5T_sign_t sign;
241  DBG(cerr << ">get_dap_type(): type=" << type << endl);
242  H5T_class_t class_t = H5Tget_class(type);
243  if (H5T_NO_CLASS == class_t)
244  throw InternalErr(__FILE__, __LINE__,
245  "The HDF5 datatype doesn't belong to any Class.");
246  switch (class_t) {
247 
248  case H5T_INTEGER:
249 
250  size = H5Tget_size(type);
251  if (size == 0){
252  throw InternalErr(__FILE__, __LINE__,
253  "size of datatype is invalid");
254  }
255 
256  sign = H5Tget_sign(type);
257  if (sign < 0){
258  throw InternalErr(__FILE__, __LINE__,
259  "sign of datatype is invalid");
260  }
261 
262  DBG(cerr << "=get_dap_type(): H5T_INTEGER" <<
263  " sign = " << sign <<
264  " size = " << size <<
265  endl);
266  if (size == 1){
267  if (sign == H5T_SGN_NONE)
268  return BYTE;
269  else
270  return INT16;
271  }
272 
273  if (size == 2) {
274  if (sign == H5T_SGN_NONE)
275  return UINT16;
276  else
277  return INT16;
278  }
279 
280  if (size == 4) {
281  if (sign == H5T_SGN_NONE)
282  return UINT32;
283  else
284  return INT32;
285  }
286 
287  return INT_ELSE;
288 
289  case H5T_FLOAT:
290  size = H5Tget_size(type);
291  if (size == 0){
292  throw InternalErr(__FILE__, __LINE__,
293  "size of the datatype is invalid");
294  }
295 
296  DBG(cerr << "=get_dap_type(): FLOAT size = " << size << endl);
297  if (size == 4)
298  return FLOAT32;
299  if (size == 8)
300  return FLOAT64;
301 
302  return FLOAT_ELSE;
303 
304  case H5T_STRING:
305  DBG(cerr << "<get_dap_type(): H5T_STRING" << endl);
306  return STRING;
307 
308  case H5T_REFERENCE:
309  DBG(cerr << "<get_dap_type(): H5T_REFERENCE" << endl);
310  return URL;
311 
312  case H5T_COMPOUND:
313  DBG(cerr << "<get_dap_type(): COMPOUND" << endl);
314  return COMPOUND;
315 
316  case H5T_ARRAY:
317  return ARRAY;
318 
319  default:
320  DBG(cerr << "<get_dap_type(): Unmappable Type" << endl);
321  return "Unmappable Type";
322  }
323 }
324 
334 hid_t get_fileid(const char *filename)
335 {
336  hid_t fileid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
337  if (fileid < 0){
338  string msg = "cannot open the HDF5 file ";
339  string filenamestr(filename);
340  msg += filenamestr;
341  throw InternalErr(__FILE__, __LINE__, msg);
342  }
343 
344  return fileid;
345 }
346 
356 void close_fileid(hid_t fid)
357 {
358  if (H5Fclose(fid) < 0)
359  throw Error(unknown_error,
360  string("Could not close the HDF5 file."));
361 
362 }
363 
374 void get_dataset(hid_t pid, const string &dname, DS_t * dt_inst_ptr)
375 {
376 
377  DBG(cerr << ">get_dataset()" << endl);
378 
379  // Obtain the dataset ID
380  hid_t dset;
381  if ((dset = H5Dopen(pid, dname.c_str(),H5P_DEFAULT)) < 0) {
382  string msg = "cannot open the HDF5 dataset ";
383  msg += dname;
384  throw InternalErr(__FILE__, __LINE__, msg);
385  }
386 
387  // Obtain the datatype ID
388  hid_t dtype;
389  if ((dtype = H5Dget_type(dset)) < 0) {
390  H5Dclose(dset);
391  string msg = "cannot get the the datatype of HDF5 dataset ";
392  msg += dname;
393  throw InternalErr(__FILE__, __LINE__, msg);
394  }
395 
396  // Obtain the datatype class
397  H5T_class_t ty_class = H5Tget_class(dtype);
398  if (ty_class < 0) {
399  H5Tclose(dtype);
400  H5Dclose(dset);
401  string msg = "cannot get the datatype class of HDF5 dataset ";
402  msg += dname;
403  throw InternalErr(__FILE__, __LINE__, msg);
404  }
405 
406  // These datatype classes are unsupported. Note we do support
407  // variable length string and the variable length string class is
408  // H5T_STRING rather than H5T_VLEN.
409  if ((ty_class == H5T_TIME) || (ty_class == H5T_BITFIELD)
410  || (ty_class == H5T_OPAQUE) || (ty_class == H5T_ENUM) || (ty_class == H5T_VLEN)) {
411  string msg = "unexpected datatype of HDF5 dataset ";
412  msg += dname;
413  throw InternalErr(__FILE__, __LINE__, msg);
414  }
415 
416  hid_t dspace;
417  if ((dspace = H5Dget_space(dset)) < 0) {
418  H5Tclose(dtype);
419  H5Dclose(dset);
420  string msg = "cannot get the the dataspace of HDF5 dataset ";
421  msg += dname;
422  throw InternalErr(__FILE__, __LINE__, msg);
423  }
424 
425  // It is better to use the dynamic allocation of the array.
426  // However, since the DODS_MAX_RANK is not big and it is also
427  // used in other location, we still keep the original code.
428  // KY 2011-11-17
429 
430  int ndims = H5Sget_simple_extent_ndims(dspace);
431  if (ndims < 0) {
432  H5Tclose(dtype);
433  H5Sclose(dspace);
434  H5Dclose(dset);
435  string msg = "cannot get hdf5 dataspace number of dimension for dataset ";
436  msg += dname;
437  throw InternalErr(__FILE__, __LINE__, msg);
438  }
439 
440  // Check if the dimension size exceeds the maximum number of dimension DAP supports
441  if (ndims > DODS_MAX_RANK) {
442  string msg = "number of dimensions exceeds allowed for dataset ";
443  msg += dname;
444  H5Tclose(dtype);
445  H5Sclose(dspace);
446  H5Dclose(dset);
447  throw InternalErr(__FILE__, __LINE__, msg);
448  }
449 
450  hsize_t size[DODS_MAX_RANK];
451  hsize_t maxsize[DODS_MAX_RANK];
452 
453  // DAP applications don't care about the unlimited dimensions
454  // since the applications only care about retrieving the data.
455  // So we don't check the maxsize to see if it is the unlimited dimension
456  // attribute.
457  if (H5Sget_simple_extent_dims(dspace, size, maxsize)<0){
458  string msg = "cannot obtain the dim. info for the dataset ";
459  msg += dname;
460  H5Tclose(dtype);
461  H5Sclose(dspace);
462  H5Dclose(dset);
463  throw InternalErr(__FILE__, __LINE__, msg);
464  }
465 
466  // return ndims and size[ndims].
467  hsize_t nelmts = 1;
468  if (ndims) {
469  for (int j = 0; j < ndims; j++)
470  nelmts *= size[j];
471  }
472 
473  size_t dtype_size = H5Tget_size(dtype);
474  if (dtype_size == 0) {
475  string msg = "cannot obtain the data type size for the dataset ";
476  msg += dname;
477  H5Tclose(dtype);
478  H5Sclose(dspace);
479  H5Dclose(dset);
480  throw InternalErr(__FILE__, __LINE__, msg);
481  }
482 
483  size_t need = nelmts * dtype_size;
484 
485  hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
486  if (memtype < 0){
487  string msg = "cannot obtain the memory data type for the dataset ";
488  msg += dname;
489  H5Tclose(dtype);
490  H5Sclose(dspace);
491  H5Dclose(dset);
492  throw InternalErr(__FILE__, __LINE__, msg);
493  }
494 
495  (*dt_inst_ptr).dset = dset;
496  (*dt_inst_ptr).dataspace = dspace;
497  (*dt_inst_ptr).type = memtype;
498  (*dt_inst_ptr).ndims = ndims;
499  (*dt_inst_ptr).nelmts = nelmts;
500  (*dt_inst_ptr).need = need;
501  strncpy((*dt_inst_ptr).name, dname.c_str(), dname.length());
502  (*dt_inst_ptr).name[dname.length()] = '\0';
503 
504  for (int j = 0; j < ndims; j++) {
505  (*dt_inst_ptr).size[j] = size[j];
506  }
507 
508  DBG(cerr << "<get_dataset() dimension=" << ndims << " elements=" <<
509  nelmts << endl);
510 }
511 
512 
521 void get_data(hid_t dset, void *buf)
522 {
523  DBG(cerr << ">get_data()" << endl);
524 
525  hid_t dtype;
526  if ((dtype = H5Dget_type(dset)) < 0) {
527  H5Dclose(dset);
528  throw InternalErr(__FILE__, __LINE__, "Failed to get the datatype of the dataset");
529  }
530  hid_t dspace;
531  if ((dspace = H5Dget_space(dset)) < 0) {
532  H5Tclose(dtype);
533  H5Dclose(dset);
534  throw InternalErr(__FILE__, __LINE__, "Failed to get the data space of the dataset");
535  }
536  // Use HDF5 H5Tget_native_type API
537  hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
538  if (memtype < 0) {
539  H5Tclose(dtype);
540  H5Sclose(dspace);
541  H5Dclose(dset);
542  throw InternalErr(__FILE__, __LINE__, "failed to get memory type");
543  }
544 
545  // Just test with tstring-at.h5, the memtype works. KY 2011-11-17
546  // So comment out the old code until the full test is done.
547  if (H5Dread(dset, memtype, dspace, dspace, H5P_DEFAULT, buf)
548  < 0) {
549  H5Tclose(dtype);
550  H5Tclose(memtype);
551  H5Sclose(dspace);
552  H5Dclose(dset);
553  throw InternalErr(__FILE__, __LINE__, "failed to read data");
554  }
555 
556 // leave this comments, may delete them after the final testing.
557 #if 0
558  // For some reason, if you must handle the H5T_STRING type differently.
559  // Otherwise, the "tstring-at.h5" test will fail.
560  if (memtype == H5T_STRING) {
561  DBG(cerr << "=get_data(): H5T_STRING type is detected." << endl);
562  //if (H5Dread(dset, dtype, dspace, dspace, H5P_DEFAULT, buf)
563  if (H5Dread(dset, memtype, dspace, dspace, H5P_DEFAULT, buf)
564  < 0) {
565  H5Dclose(dset);
566  throw InternalErr(__FILE__, __LINE__, "failed to read data");
567  }
568  }
569  else {
570  DBG(cerr << "=get_data(): H5T_STRING type is NOT detected." << endl);
571  if (H5Dread(dset, memtype, dspace, dspace, H5P_DEFAULT, buf)
572  < 0) {
573  H5Dclose(dset);
574  throw InternalErr(__FILE__, __LINE__, "failed to read data");
575  }
576 
577  }
578 #endif
579  // This I don't understand... jhrg 4/16/08
580  // If you remove the following if(){} block, the "tstring-at.h5" test
581  // will fail.
582  // Due to the HDF5 handles are used by H5T_STRING datatype in
583  // m_intern_plain_array_data defined in HDF5Array.cc. So cannot
584  // release all handles here. The dataset handler will be released at
585  // HDF5Array.cc read function.
586  // Better handling the string data should be in the future. KY-2011-11-17
587 
588  if (H5Sclose(dspace) < 0){
589  H5Tclose(dtype);
590  H5Tclose(memtype);
591  H5Dclose(dset);
592  throw InternalErr(__FILE__, __LINE__, "Unable to terminate the data space access.");
593  }
594 
595 #if 0
596  if (H5Tget_class(dtype) != H5T_STRING) {
597 #endif
598 
599  if (H5Tclose(dtype) < 0){
600  H5Tclose(memtype);
601  H5Dclose(dset);
602  throw InternalErr(__FILE__, __LINE__, "Unable to release the dtype.");
603  }
604 
605  if (H5Tclose(memtype) < 0){
606  H5Dclose(dset);
607  throw InternalErr(__FILE__, __LINE__, "Unable to release the memtype.");
608  }
609 
610 #if 0
611  // Supposed to release the resource at the release at the HDF5Array destructor.
612  //if (H5Dclose(dset) < 0){
613  // throw InternalErr(__FILE__, __LINE__, "Unable to close the dataset.");
614  //}
615  }
616 #endif
617 
618  DBG(cerr << "<get_data()" << endl);
619 }
620 
632 void get_strdata(int strindex, char *allbuf, char *buf, int elesize)
633 {
634  char *tempvalue = allbuf; // The beginning of entire buffer.
635 
636  DBG(cerr << ">get_strdata(): "
637  << " strindex=" << strindex << " allbuf=" << allbuf << endl);
638 
639  // Tokenize the convbuf.
640  for (int i = 0; i < strindex; i++) {
641  tempvalue = tempvalue + elesize;
642  }
643 
644  strncpy(buf, tempvalue, elesize);
645  buf[elesize] = '\0';
646 }
647 
660 int
661 get_slabdata(hid_t dset, int *offset, int *step, int *count, int num_dim,
662  void *buf)
663 {
664  DBG(cerr << ">get_slabdata() " << endl);
665 
666  hid_t dtype = H5Dget_type(dset);
667  if (dtype < 0) {
668  H5Dclose(dset);
669  throw InternalErr(__FILE__, __LINE__, "could not get data type");
670  }
671  // Using H5T_get_native_type API
672  hid_t memtype = H5Tget_native_type(dtype, H5T_DIR_ASCEND);
673  if (memtype < 0) {
674  H5Dclose(dset);
675  H5Tclose(dtype);
676  throw InternalErr(__FILE__, __LINE__, "could not get memory type");
677  }
678 
679  hid_t dspace = H5Dget_space(dset);
680  if (dspace < 0) {
681  H5Dclose(dset);
682  H5Tclose(dtype);
683  H5Tclose(memtype);
684  throw InternalErr(__FILE__, __LINE__, "could not get data space");
685  }
686 
687  hsize_t *dyn_count = 0;
688  hsize_t *dyn_step = 0;
689  hssize_t *dyn_offset = 0;
690  try {
691  dyn_count = new hsize_t[num_dim];
692  dyn_step = new hsize_t[num_dim];
693  dyn_offset = new hssize_t[num_dim];
694 
695  for (int i = 0; i < num_dim; i++) {
696  dyn_count[i] = (hsize_t) (*count);
697  dyn_step[i] = (hsize_t) (*step);
698  dyn_offset[i] = (hssize_t) (*offset);
699  DBG(cerr
700  << "count:" << dyn_count[i]
701  << " step:" << dyn_step[i]
702  << " offset:" << dyn_step[i]
703  << endl);
704  count++;
705  step++;
706  offset++;
707  }
708 
709  if (H5Sselect_hyperslab(dspace, H5S_SELECT_SET,
710  (const hsize_t *)dyn_offset, dyn_step,
711  dyn_count, NULL) < 0) {
712  H5Dclose(dset);
713  H5Tclose(dtype);
714  H5Tclose(memtype);
715  H5Sclose(dspace);
716  delete[] dyn_count;
717  delete[] dyn_step;
718  delete[] dyn_offset;
719  throw
720  InternalErr(__FILE__, __LINE__, "could not select hyperslab");
721  }
722 
723  hid_t memspace = H5Screate_simple(num_dim, dyn_count, NULL);
724  if (memspace < 0) {
725  H5Dclose(dset);
726  H5Tclose(dtype);
727  H5Tclose(memtype);
728  H5Sclose(dspace);
729  delete[] dyn_count;
730  delete[] dyn_step;
731  delete[] dyn_offset;
732  throw InternalErr(__FILE__, __LINE__, "could not open space");
733  }
734 
735  delete[] dyn_count;
736  delete[] dyn_step;
737  delete[] dyn_offset;
738 
739  if (H5Dread(dset, memtype, memspace, dspace, H5P_DEFAULT,
740  (void *) buf) < 0) {
741  H5Dclose(dset);
742  H5Tclose(dtype);
743  H5Tclose(memtype);
744  H5Sclose(dspace);
745  H5Sclose(memspace);
746  throw InternalErr(__FILE__, __LINE__, "could not get data");
747  }
748 
749  if (H5Sclose(dspace) < 0){
750  H5Dclose(dset);
751  H5Tclose(dtype);
752  H5Tclose(memtype);
753  H5Sclose(memspace);
754  throw InternalErr(__FILE__, __LINE__, "Unable to close the dspace.");
755  }
756  if (H5Sclose(memspace) < 0){
757  H5Dclose(dset);
758  H5Tclose(dtype);
759  H5Tclose(memtype);
760  throw InternalErr(__FILE__, __LINE__, "Unable to close the memspace.");
761  }
762  if (H5Tclose(dtype) < 0){
763  H5Dclose(dset);
764  H5Tclose(memtype);
765  throw InternalErr(__FILE__, __LINE__, "Unable to close the dtype.");
766  }
767 
768  if (H5Tclose(memtype) < 0){
769  H5Dclose(dset);
770  throw InternalErr(__FILE__, __LINE__, "Unable to close the memtype.");
771  }
772 
773 
774  // Dataset close will be handled at HDF5Array, HDF5Byte etc. read() functions.
775 // if (H5Dclose(dset) < 0){
776 // throw InternalErr(__FILE__, __LINE__, "Unable to close the dset.");
777 // }
778  }
779  catch (...) {
780  // Memory allocation exceptions could have been thrown when
781  // creating these, so check if these are not null before deleting.
782  if( dyn_count ) delete[] dyn_count;
783  if( dyn_step ) delete[] dyn_step;
784  if( dyn_offset ) delete[] dyn_offset;
785 
786  throw;
787  }
788  DBG(cerr << "<get_slabdata() " << endl);
789  return 0;
790 }
791 
792 
793 
802 bool check_h5str(hid_t h5type)
803 {
804  if (H5Tget_class(h5type) == H5T_STRING)
805  return true;
806  else
807  return false;
808 }
809 
810 
A structure for DDS generation.
Definition: hdf5_handler.h:68
void get_dataset(hid_t pid, const string &dname, DS_t *dt_inst_ptr)
obtain data information in a dataset datatype, dataspace(dimension sizes) and number of dimensions an...
Definition: h5get.cc:374
#define DODS_MAX_RANK
Maximum number of dimensions in an array(default option only).
Definition: hdf5_handler.h:41
string get_dap_type(hid_t type)
returns the string representation of HDF5 type.
Definition: h5get.cc:237
void get_data(hid_t dset, void *buf)
will get all data of a dset dataset and put it into buf.
Definition: h5get.cc:521
bool check_h5str(hid_t h5type)
checks if type is HDF5 string type
Definition: h5get.cc:802
static class NCMLUtil overview
#define NULL
Definition: wcsUtil.h:65
A structure for DAS generation.
Definition: hdf5_handler.h:87
hid_t get_attr_info(hid_t dset, int index, DSattr_t *attr_inst_ptr, bool *ignore_attr_ptr)
Definition: h5get.cc:56
void get_strdata(int strindex, char *allbuf, char *buf, int elesize)
will get an individual string data from all string data elements and put it into buf.
Definition: h5get.cc:632
int get_slabdata(hid_t dset, int *offset, int *step, int *count, int num_dim, void *buf)
will get hyperslab data of a dataset and put it into buf.
Definition: h5get.cc:661
void close_fileid(hid_t fid)
closes HDF5 file reffered by fid.
Definition: h5get.cc:356
hid_t get_fileid(const char *filename)
gets HDF5 file id.
Definition: h5get.cc:334
Helper functions to generate DDS/DAS/DODS for the default option.