OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDF5Float64.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 1901 South First Street,
25 // Suite C-2, Champaign, IL 61820
26 
27 // #define DODS_DEBUG
28 
37 
38 
39 
40 #include <string>
41 #include <ctype.h>
42 #include "config_hdf5.h"
43 #include "InternalErr.h"
44 #include "h5dds.h"
45 #include "HDF5Float64.h"
46 #include "HDF5Structure.h"
47 #include "debug.h"
48 
49 typedef struct s2_float64_t {
51  dods_float64 a;
52 } s2_float64_t;
53 
54 
55 
56 HDF5Float64::HDF5Float64(const string & n, const string &d) : Float64(n, d)
57 {
58  ty_id = -1;
59  dset_id = -1;
60 }
61 
63 {
64  return new HDF5Float64(*this);
65 }
66 
68 {
69  if (read_p())
70  return true;
71 
72  if (get_dap_type(ty_id) == "Float64") {
73  dods_float64 buf;
74  get_data(dset_id, (void *) &buf);
75  set_read_p(true);
76  set_value(buf);
77 
78  // Release the handles.
79  if (H5Tclose(ty_id) < 0) {
80  throw InternalErr(__FILE__, __LINE__, "Unable to close the datatype.");
81  }
82  if (H5Dclose(dset_id) < 0) {
83  throw InternalErr(__FILE__, __LINE__, "Unable to close the dset.");
84  }
85 
86  }
87 
88  if (get_dap_type(ty_id) == "Structure") {
89  DBG(cerr << "=read(): Structure" << endl);
90  BaseType *q = get_parent();
91  if (!q)
92  throw InternalErr(__FILE__, __LINE__, "null pointer");
93  HDF5Structure &p = static_cast<HDF5Structure &> (*q);
94  DBG(cerr << "=read(): Size = " << p.get_entire_array_size() << endl);
95 
96 #ifdef DODS_DEBUG
97  int i = H5Tget_nmembers(ty_id);
98  if(i < 0) {
99  throw InternalErr(__FILE__, __LINE__, "H5Tget_nmembers() failed.");
100  }
101 #endif
102  int j = 0;
103  int k = 0;
104 
105  vector<s2_float64_t> buf(p.get_entire_array_size());
106 
107  string myname = name();
108  string parent_name;
109 
110  hid_t s2_float64_tid = H5Tcreate(H5T_COMPOUND, sizeof(s2_float64_t));
111  hid_t stemp_tid;
112 
113  if (s2_float64_tid < 0) {
114  throw InternalErr(__FILE__, __LINE__, "cannot create a new datatype");
115  }
116 
117  DBG(cerr << "=read() ty_id=" << ty_id << " name=" << myname <<
118  " size=" << i << endl);
119  while (q != NULL) {
120  if (q->is_constructor_type()) { // Grid, structure or sequence
121  if (k == 0) {
122  // Bottom level structure
123  if (H5Tinsert(s2_float64_tid, myname.c_str(), HOFFSET(s2_float64_t, a), H5T_NATIVE_DOUBLE) < 0) {
124  throw InternalErr(__FILE__, __LINE__, "Unable to add datatype.");
125  }
126  }
127  else {
128  stemp_tid = H5Tcreate(H5T_COMPOUND, sizeof(s2_float64_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, s2_float64_tid) < 0) {
133  throw InternalErr(__FILE__, __LINE__, "Unable to add datatype.");
134  }
135  s2_float64_tid = stemp_tid;
136  }
137  parent_name = q->name();
138  p = static_cast<HDF5Structure &> (*q);
139  // Remember the index of array from the last parent.
140  j = p.get_array_index();
141  q = q->get_parent();
142  }
143  else {
144  q = NULL;
145  }
146  k++;
147  }
148 
149  if (H5Dread(dset_id, s2_float64_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buf[0]) < 0) {
150  // buf is deleted in the catch ... block below and
151  // should not be deleted here. pwest Mar 18, 2009
152  //delete[] buf;
153  throw InternalErr(__FILE__, __LINE__, "hdf5_dods server failed when getting int32 data for structure");
154  //string
155  //()
156  //+ Msgi);
157  }
158  set_read_p(true);
159  DBG(cerr << "index " << j << endl);
160 
161  set_value(buf[j].a);
162  }
163 
164  return true;
165 }
166 
167 void HDF5Float64::set_did(hid_t dset)
168 {
169  dset_id = dset;
170 }
171 
172 void HDF5Float64::set_tid(hid_t type)
173 {
174  ty_id = type;
175 }
176 
178 {
179  return dset_id;
180 }
181 
183 {
184  return ty_id;
185 }
HDF5Float64(const string &n, const string &d)
Constructor.
Definition: HDF5Float64.cc:56
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_did()
returns HDF5 dataset id.
Definition: HDF5Float64.cc:177
virtual BaseType * ptr_duplicate()
Clone this instance.
Definition: HDF5Float64.cc:62
virtual bool read()
Reads HDF5 64-bit float data into local buffer.
Definition: HDF5Float64.cc:67
A class for mapping HDF5 64-bit float to DAP for the default option.
hid_t get_tid()
returns HDF5 datatype id.
Definition: HDF5Float64.cc:182
#define NULL
Definition: wcsUtil.h:65
void set_did(hid_t dset)
remembers HDF5 dataset id.
Definition: HDF5Float64.cc:167
int get_entire_array_size()
returns the entire array size of this Structure if it's a part of array of structures.
void set_tid(hid_t type)
remembers HDF5 datatype id.
Definition: HDF5Float64.cc:172
struct s2_float64_t s2_float64_t