bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
hdfclass.h
1#ifndef _HDFCLASS_H
2#define _HDFCLASS_H
3
4// -*- C++ -*-
5
7// This file is part of the hdf4 data handler for the OPeNDAP data server.
8
9// Copyright (c) 2005 OPeNDAP, Inc.
10// Author: James Gallagher <jgallagher@opendap.org>
11//
12// This is free software; you can redistribute it and/or modify it under the
13// terms of the GNU Lesser General Public License as published by the Free
14// Software Foundation; either version 2.1 of the License, or (at your
15// option) any later version.
16//
17// This software is distributed in the hope that it will be useful, but
18// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20// License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public License
23// along with this software; if not, write to the Free Software Foundation,
24// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25//
26// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
27
28// Copyright 1996, by the California Institute of Technology.
29// ALL RIGHTS RESERVED. United States Government Sponsorship
30// acknowledged. Any commercial use must be negotiated with the
31// Office of Technology Transfer at the California Institute of
32// Technology. This software may be subject to U.S. export control
33// laws and regulations. By accepting this software, the user
34// agrees to comply with all applicable U.S. export laws and
35// regulations. User has the responsibility to obtain export
36// licenses, or other export authority as may be required before
37// exporting such information to foreign countries or providing
38// access to foreign persons.
39
40// U.S. Government Sponsorship under NASA Contract
41// NAS7-1260 is acknowledged.
42
43// Author: Todd.K.Karakashian@jpl.nasa.gov
44//
46
47#include <iostream>
48#include <string>
49#include <vector>
50
51using std::vector;
52using std::string;
53
54#ifdef NO_BOOL
55enum bool { false = 0, true = 1 };
56#endif
57
58// Global values -- someday change "struct" to "namespace"
59// The enum-inside-of-struct hack is more portable than the previous
60// const int-inside-of-struct hack, which didn't work with Sun C++
61struct hdfclass {
62 enum hdfenum {
63 MAXSTR = 32767, // maximum length of a string
64 MAXDIMS = 20, // maximum dimensions in a dataset
65 MAXANNOTS = 20, // max number of annotations per object
66 MAXREFS = 1000 // max number of instances of a tag in a file
67 };
68};
69
70// generic vector class
71class hdf_genvec {
72 public:
73 hdf_genvec(void);
74 hdf_genvec(int32 nt, void *data, int begin, int end, int stride = 1);
75 hdf_genvec(int32 nt, void *data, int nelts);
76 hdf_genvec(const hdf_genvec & gv);
77
78 virtual ~ hdf_genvec(void);
79
80 hdf_genvec & operator=(const hdf_genvec & gv);
81
82 int32 number_type(void) const {
83 return _nt;
84 } int size(void) const {
85 return _nelts;
86 } const char *data(void) const {
87 return _data;
88 } // use with care!
89 void append(int32 nt, const char *new_data, int32 nelts);
90
91 void import_vec(int32 nt, void *data, int nelts) {
92 import_vec(nt, data, 0, nelts - 1, 1);
93 }
94
95 void import_vec(int32 nt, void *data, int begin, int end, int stride = 1);
96 void import_vec(int32 nt) {
97 import_vec(nt, nullptr, 0, 0, 0);
98 }
99 void import_vec(int32 nt, const vector < string > &sv);
100
101 void print(vector < string > &strv) const;
102 void print(vector < string > &strv, int begin, int end,
103 int stride) const;
104
105 vector < uchar8 > exportv_uchar8(void) const;
106 uchar8 *export_uchar8(void) const;
107 uchar8 elt_uchar8(int i) const;
108 vector < char8 > exportv_char8(void) const;
109 char8 *export_char8(void) const;
110 char8 elt_char8(int i) const;
111 vector < uint8 > exportv_uint8(void) const;
112 uint8 *export_uint8(void) const;
113 uint8 elt_uint8(int i) const;
114 vector < int8 > exportv_int8(void) const;
115 int8 *export_int8(void) const;
116 int8 elt_int8(int i) const;
117 vector < uint16 > exportv_uint16(void) const;
118 uint16 *export_uint16(void) const;
119 uint16 elt_uint16(int i) const;
120 vector < int16 > exportv_int16(void) const;
121 int16 *export_int16(void) const;
122 int16 elt_int16(int i) const;
123 vector < uint32 > exportv_uint32(void) const;
124 uint32 *export_uint32(void) const;
125 uint32 elt_uint32(int i) const;
126 vector < int32 > exportv_int32(void) const;
127 int32 *export_int32(void) const;
128 int32 elt_int32(int i) const;
129 vector < float32 > exportv_float32(void) const;
130 float32 *export_float32(void) const;
131 float32 elt_float32(int i) const;
132 vector < float64 > exportv_float64(void) const;
133 float64 *export_float64(void) const;
134 float64 elt_float64(int i) const;
135 string export_string(void) const;
136
137 protected:
138 void _init(int32 nt, void *data, int begin, int end, int stride = 1);
139 void _init(void);
140 void _init(const hdf_genvec & gv);
141 void _del(void);
142
143 int32 _nt; // HDF data type of vector
144 int _nelts; // number of elements in vector
145 char *_data; // hold data
146};
147
148// HDF attribute class
149class hdf_attr {
150 public:
151 string name; // name of attribute
152 hdf_genvec values; // value(s) of attribute
153};
154
155// Structure to hold array-type constraint information. Used within
156// hdfistream_sds (See hcstream.h)
157struct array_ce {
158 string name;
159 int start;
160 int edge;
161 int stride;
162 array_ce(const string & n, int s1, int e, int s3)
163 :name(n), start(s1), edge(e), stride(s3) {
164}};
165
166// HDF dimension class - holds dimension info and scale for an SDS
167class hdf_dim {
168 public:
169 string name; // name of dimension
170 string label; // label of dimension
171 string unit; // units of this dimension
172 string format; // format to use when displaying
173 int32 count; // size of this dimension
174 hdf_genvec scale; // dimension scale data
175 vector < hdf_attr > attrs; // vector of dimension attributes
176};
177
178// HDF SDS class
179class hdf_sds {
180 public:
181 bool operator!(void) const {
182 return !_ok();
183 } bool has_scale(void) const; // does this SDS have a dim scale?
184 int32 ref; // ref number of SDS
185 string name;
186 vector < hdf_dim > dims; // dimensions and dimension scales
187 hdf_genvec data; // data stored in SDS
188 vector < hdf_attr > attrs; // vector of attributes
189 protected:
190 bool _ok(bool * has_scale = nullptr) const; // is this hdf_sds correctly initialized?
191};
192
194 public:
195 friend class hdf_vdata;
196 bool operator!(void) const {
197 return !_ok();
198 } string name;
199 vector < hdf_genvec > vals; // values for field; vals.size() is order of field
200 protected:
201 bool _ok(void) const; // is this hdf_field correctly initialized?
202};
203
205 public:
206 bool operator!(void) const {
207 return !_ok();
208 } int32 ref; // ref number
209 string name; // name of vdata
210 string vclass; // class name of vdata
211 vector < hdf_field > fields;
212 vector < hdf_attr > attrs;
213 protected:
214 bool _ok(void) const; // is this hdf_vdata correctly initialized?
215};
216
217// Vgroup class
219 public:
220 bool operator!(void) const {
221 return !_ok();
222 } int32 ref; // ref number of vgroup
223 string name; // name of vgroup
224 string vclass; // class name of vgroup
225 vector < int32 > tags; // vector of tags inside vgroup
226 vector < int32 > refs; // vector of refs inside vgroup
227 vector < string > vnames; // vector of variable name(refs) inside vgroup
228 vector < hdf_attr > attrs;
229 protected:
230 bool _ok(void) const; // is this hdf_vgroup correctly initialized?
231};
232
233// Palette container class
235 public:
236 string name; // palettes name
237 hdf_genvec table; // palette
238 int32 ncomp; // number of components
239 int32 num_entries; // number of entries
240};
241
242// Raster container class based on the gernal raster image (GR API)
243class hdf_gri {
244 public:
245 int32 ref; // ref number of raster
246 string name;
247 vector < hdf_palette > palettes; // vector of associated palettes
248 vector < hdf_attr > attrs; // vector of attributes
249 int32 dims[2]; // the image dimensions
250 int32 num_comp; // the number of components
251 int32 interlace; // the interlace mode of the image
252 hdf_genvec image; // the image
253 bool operator!(void) const {
254 return !_ok();
255 } bool has_palette(void) const {
256 return (!palettes.empty());
257 } protected:
258 bool _ok(void) const;
259};
260
261// misc utility functions
262
263#if 0
264vector < string > split(const string & str, const string & delim);
265#endif
266string join(const vector < string > &sv, const string & delim);
267bool SDSExists(const char *filename, const char *sdsname);
268bool GRExists(const char *filename, const char *grname);
269bool VdataExists(const char *filename, const char *vdname);
270
271#endif // _HDFCLASS_H
272