OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDF5UInt32.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 // Author: Hyo-Kyung Lee <hyoklee@hdfgroup.org> and Muqun Yang
5 // <myang6@hdfgroup.org>
6 
7 // Copyright (c) 2009-2013 The HDF Group, Inc. and OPeNDAP, Inc.
8 //
9 // This is free software; you can redistribute it and/or modify it under the
10 // terms of the GNU Lesser General Public License as published by the Free
11 // Software Foundation; either version 2.1 of the License, or (at your
12 // option) any later version.
13 //
14 // This software is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 // License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
25 // Suite 203, Champaign, IL 61820
26 
35 
36 
37 #include "config_hdf5.h"
38 
39 #include <string>
40 #include <ctype.h>
41 
42 #include "InternalErr.h"
43 
44 #include "h5dds.h"
45 #include "HDF5UInt32.h"
46 #include "HDF5Structure.h"
47 #include "debug.h"
48 
49 typedef struct s_uint32_t {
51  dods_int32 a;
52 } s_uint32_t;
53 
54 
55 HDF5UInt32::HDF5UInt32(const string & n, const string &d) : UInt32(n, d)
56 {
57 }
58 
60 {
61 
62  return new HDF5UInt32(*this);
63 }
64 
66 {
67  if (read_p())
68  return true;
69 
70  if (get_dap_type(ty_id) == "UInt32") {
71  dods_uint32 buf;
72  get_data(dset_id, (void *) &buf);
73  set_read_p(true);
74  set_value(buf);
75  // Release the handles.
76  if (H5Tclose(ty_id) < 0) {
77  throw InternalErr(__FILE__, __LINE__, "Unable to close the datatype.");
78  }
79  if (H5Dclose(dset_id) < 0) {
80  throw InternalErr(__FILE__, __LINE__, "Unable to close the dset.");
81  }
82 
83  }
84 
85  if (get_dap_type(ty_id) == "Structure") {
86 
87  BaseType *q = get_parent();
88  if (!q)
89  throw InternalErr(__FILE__, __LINE__, "null pointer");
90  HDF5Structure &p = static_cast<HDF5Structure &> (*q);
91 
92 #ifdef DODS_DEBUG
93  int i = H5Tget_nmembers(ty_id);
94  if(i < 0) {
95  throw InternalErr(__FILE__, __LINE__, "H5Tget_nmembers() failed.");
96  }
97 #endif
98  int j = 0;
99  int k = 0;
100 
101  hid_t s1_tid = H5Tcreate(H5T_COMPOUND, sizeof(s_uint32_t));
102  hid_t stemp_tid;
103 
104  if (s1_tid < 0) {
105  throw InternalErr(__FILE__, __LINE__, "cannot create a new datatype");
106  }
107 
108  vector<s_uint32_t> buf(p.get_entire_array_size());
109  string myname = name();
110  string parent_name;
111 
112  DBG( cerr << "=read() ty_id=" << ty_id
113  << " name=" << myname << " size=" << i << endl);
114  while (q != NULL) {
115 
116  if (q->is_constructor_type()) { // Grid, structure or sequence
117  if (k == 0) {
118  // Bottom level structure
119  DBG(cerr << "my_name " << myname.c_str() << endl);
120  if (H5Tinsert(s1_tid, myname.c_str(), HOFFSET(s_uint32_t, a), H5T_NATIVE_UINT32) < 0) {
121  throw InternalErr(__FILE__, __LINE__, "Unable to add datatype.");
122  }
123  }
124  else {
125  DBG(cerr << k << " parent_name=" << parent_name
126  << endl);
127 
128  stemp_tid = H5Tcreate(H5T_COMPOUND, sizeof(s_uint32_t));
129  if (stemp_tid < 0) {
130  throw InternalErr(__FILE__, __LINE__, "cannot create a new datatype");
131  }
132  if (H5Tinsert(stemp_tid, parent_name.c_str(), 0, s1_tid) < 0) {
133  throw InternalErr(__FILE__, __LINE__, "Unable to add datatype.");
134  }
135  s1_tid = stemp_tid;
136  }
137  // Remember the last parent name.
138  parent_name = q->name();
139  p = static_cast<HDF5Structure &> (*q);
140  // Remember the index of array from the last parent.
141  j = p.get_array_index();
142  q = q->get_parent();
143 
144  }
145  else {
146  q = NULL;
147  }
148  k++;
149  } // while ()
150 
151 
152  if (H5Dread(dset_id, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buf[0]) < 0) {
153  // this should not be called here. The exception on
154  // the next line is thrown and caught below. In the
155  // catch block the buf is deleted. pcw Mar 18, 2009
156  // delete[] buf;
157  throw InternalErr(__FILE__, __LINE__, "hdf5_dods server failed when getting int32 data for structure");
158  // string
159  // ()
160  // + Msgi);
161  }
162 
163  set_read_p(true);
164  DBG(cerr << "index " << j << endl);
165 
166  set_value(buf[j].a);
167  } // In case of structure
168 
169 
170  return true;
171 }
172 
173 void HDF5UInt32::set_did(hid_t dset)
174 {
175  dset_id = dset;
176 }
177 
178 void HDF5UInt32::set_tid(hid_t type)
179 {
180  ty_id = type;
181 }
182 
184 {
185  return dset_id;
186 }
187 
189 {
190  return ty_id;
191 }
virtual BaseType * ptr_duplicate()
Clone this instance.
Definition: HDF5UInt32.cc:59
void set_did(hid_t dset)
remembers HDF5 dataset id.
Definition: HDF5UInt32.cc:173
This class converts HDF5 compound type into DAP structure for the default option. ...
string get_dap_type(hid_t type)
returns the string representation of HDF5 type.
Definition: h5get.cc:237
int get_array_index()
returns the array index of this Structure if it's a part of array of structures.
Data structure and retrieval processing header for the default option.
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
hid_t get_tid()
returns HDF5 datatype id.
Definition: HDF5UInt32.cc:188
#define NULL
Definition: wcsUtil.h:65
HDF5UInt32(const string &n, const string &d)
Constructor.
Definition: HDF5UInt32.cc:55
virtual bool read()
Reads HDF5 unsigned 32-bit integer data into local buffer.
Definition: HDF5UInt32.cc:65
This class provides a way to map unsigned HDF5 32 bit integer to DAP UInt32.
hid_t get_did()
returns HDF5 dataset id.
Definition: HDF5UInt32.cc:183
void set_tid(hid_t type)
remembers HDF5 datatype id.
Definition: HDF5UInt32.cc:178
int get_entire_array_size()
returns the entire array size of this Structure if it's a part of array of structures.
struct s_uint32_t s_uint32_t