bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
hdfutil.cc
1
2// This file is part of the hdf4 data handler for the OPeNDAP data server.
3
4// Copyright (c) 2005 OPeNDAP, Inc.
5// Author: James Gallagher <jgallagher@opendap.org>
6//
7// This is free software; you can redistribute it and/or modify it under the
8// terms of the GNU Lesser General Public License as published by the Free
9// Software Foundation; either version 2.1 of the License, or (at your
10// option) any later version.
11//
12// This software is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15// License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with this software; if not, write to the Free Software Foundation,
19// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20//
21// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
22
23// Copyright 1996, by the California Institute of Technology.
24// ALL RIGHTS RESERVED. United States Government Sponsorship
25// acknowledged. Any commercial use must be negotiated with the
26// Office of Technology Transfer at the California Institute of
27// Technology. This software may be subject to U.S. export control
28// laws and regulations. By accepting this software, the user
29// agrees to comply with all applicable U.S. export laws and
30// regulations. User has the responsibility to obtain export
31// licenses, or other export authority as may be required before
32// exporting such information to foreign countries or providing
33// access to foreign persons.
34
35// Author: Todd Karakashian, NASA/Jet Propulsion Laboratory
36// Todd.K.Karakashian@jpl.nasa.gov
37//
39
40#include "config_hdf.h"
41
42#include <string>
43#include <mfhdf.h>
44#include <hdfclass.h>
45#include "hdfutil.h"
46#include "dhdferr.h"
47
48#define SIGNED_BYTE_TO_INT32 1
49
50void *ExportDataForDODS(const hdf_genvec & v)
51{
52 void *rv; // reminder: rv is an array; must be deleted
53 // with delete[] not delete
54
55 switch (v.number_type()) {
56 case DFNT_INT16:
57 rv = v.export_int16();
58 break;
59
60#ifdef SIGNED_BYTE_TO_INT32
61 case DFNT_INT8:
62#endif
63 case DFNT_INT32:
64 rv = v.export_int32();
65 break;
66
67 case DFNT_UINT16:
68 rv = v.export_uint16();
69 break;
70
71 case DFNT_UINT32:
72 rv = v.export_uint32();
73 break;
74
75 case DFNT_FLOAT32:
76 rv = v.export_float32();
77 break;
78
79 case DFNT_FLOAT64:
80 rv = v.export_float64();
81 break;
82
83#ifndef SIGNED_BYTE_TO_INT32
84 case DFNT_INT8:
85#endif
86 case DFNT_UINT8:
87 case DFNT_UCHAR8:
88 case DFNT_CHAR8:
89 rv = v.export_uint8();
90 break;
91
92 default:
93 THROW(dhdferr_datatype);
94 }
95
96 return rv;
97}
98
99// Reminder: Use delete and not delete[] to free the storage returned by this
100// function.
101//
102// Declaring the pointers to be of specific types addresses an off-by-one
103// error when assigning values from the unsigned types.
104//
105// jhrg 3/2008.
106void *ExportDataForDODS(const hdf_genvec & v, int i)
107{
108 switch (v.number_type()) {
109 case DFNT_INT16:{
110 auto temp = new int16;
111 *temp = v.elt_int16(i);
112 return (void *) temp;
113 }
114
115#ifdef SIGNED_BYTE_TO_INT32
116 case DFNT_INT8:
117#endif
118 case DFNT_INT32:{
119 auto temp = new int32;
120 *temp = v.elt_int32(i);
121 return (void *) temp;
122 }
123
124 case DFNT_UINT16:{
125 auto temp = new uint16;
126 *temp = v.elt_uint16(i);
127 return (void *) temp;
128 }
129
130 case DFNT_UINT32:{
131 auto temp = new uint32;
132 *temp = v.elt_uint32(i);
133 return (void *) temp;
134 }
135
136 case DFNT_FLOAT32:{
137 auto temp = new float32;
138 *temp = v.elt_float32(i);
139 return (void *) temp;
140 }
141
142 case DFNT_FLOAT64:{
143 auto temp = new float64;
144 *temp = v.elt_float64(i);
145 return (void *) temp;
146 }
147
148#ifndef SIGNED_BYTE_TO_INT32
149 case DFNT_INT8:
150#endif
151 case DFNT_UINT8:
152 case DFNT_UCHAR8:
153 case DFNT_CHAR8:{
154 auto temp = new uint8;
155 *temp = v.elt_uint8(i);
156 return (void *) temp;
157 }
158
159 default:
160 THROW(dhdferr_datatype);
161 }
162}
163
164#if 0
165// Just like ExportDataFor DODS *except* that this function does not allocate
166// memory which must then be deleted. Why write this function? If the
167// hdf_genvec::data() method is used, then the client of hdf_genvec must cast
168// the returned pointer to one of the numeric datatypes before adding #i# to
169// access a given element. There's no need to write an Access function when
170// we're not supplying an index because the entire array returned by the
171// data() method can be used (there's no need to cast the returned pointer
172// because it's typically just passed to BaseType::val2buf() which copies the
173// data and into its own internal storage.
174//
175// This is a great idea but the problem is that hdf_genvec::elt_int16(), ...
176// all allocate and return copies of the value; the change to return the
177// address needs to be made in hdf_genvec by adding new accessor methods.
178void *AccessDataForDODS(const hdf_genvec & v, int i)
179{
180
181 void *rv = 0; // BROKEN HERE
182 switch (v.number_type()) {
183 case DFNT_INT16:
184 *(static_cast < int16 * >(rv)) = v.elt_int16(i);
185 break;
186
187#ifdef SIGNED_BYTE_TO_INT32
188 case DFNT_INT8:
189#endif
190 case DFNT_INT32:
191 *(static_cast < int32 * >(rv)) = v.elt_int32(i);
192 break;
193
194 case DFNT_UINT16:
195 *(static_cast < uint16 * >(rv)) = v.elt_uint16(i);
196 break;
197
198 case DFNT_UINT32:
199 *(static_cast < uint32 * >(rv)) = v.elt_uint32(i);
200 break;
201
202 case DFNT_FLOAT32:
203 *(static_cast < float32 * >(rv)) = v.elt_float32(i);
204 break;
205
206 case DFNT_FLOAT64:
207 *(static_cast < float64 * >(rv)) = v.elt_float64(i);
208 break;
209
210#ifndef SIGNED_BYTE_TO_INT32
211 case DFNT_INT8:
212#endif
213 case DFNT_UINT8:
214 case DFNT_UCHAR8:
215 case DFNT_CHAR8:
216 *(static_cast < uchar8 * >(rv)) = v.elt_uint8(i);
217 break;
218
219 default:
220 THROW(dhdferr_datatype);
221 }
222
223 return rv;
224}
225#endif