bes Updated for version 3.20.13
HDFStructure.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//#define DODS_DEBUG
42
43#include <vector>
44
45// Include this on linux to suppres an annoying warning about multiple
46// definitions of MIN and MAX.
47#ifdef HAVE_SYS_PARAM_H
48#include <sys/param.h>
49#endif
50#include <mfhdf.h>
51#include <hdfclass.h>
52#include <hcstream.h>
53
54#include <libdap/Error.h>
55#include <libdap/escaping.h>
56#include <libdap/Sequence.h>
57#include <libdap/debug.h>
58#include <BESDebug.h>
59
60#include "HDFStructure.h"
61
62using namespace libdap;
63using namespace std;
64
65HDFStructure::HDFStructure(const string &n, const string &d) :
66 Structure(n, d) {
67}
68
69HDFStructure::~HDFStructure() {
70}
71BaseType *HDFStructure::ptr_duplicate() {
72 return new HDFStructure(*this);
73}
74void LoadStructureFromVgroup(HDFStructure * str, const hdf_vgroup & vgroup,
75 const string & hdf_file);
76
77void HDFStructure::set_read_p(bool state) {
78 // override Structure::set_read_p() to not set children as read yet
79 BaseType::set_read_p(state);
80}
81
82bool HDFStructure::read() {
83 int err = 0;
84 int status = read_tagref(-1, -1, err);
85 if (err)
86 throw Error(unknown_error, "Could not read from dataset.");
87 return status;
88}
89
90// TODO: Combine the try/catch block and the following if/then/else and
91// eliminate the boolean 'foundvgroup' Consider moving the
92// LoadStructureFromVgroup() from hc2dap.cc here since this is the only
93// place it's used.
94bool HDFStructure::read_tagref(int32 /*tag //unused SBL 2/7/20*/, int32 ref, int &err) {
95 if (read_p())
96 return true;
97
98 // get the HDF dataset name, Vgroup name
99 string hdf_file = dataset();
100 string hdf_name = this->name();
101
102 BESDEBUG("h4", " hdf_name = " << hdf_name << endl);
103
104 hdf_vgroup vgroup;
105
106 // Wrap this with a try/catch block but don't do anything with it. The
107 // error condition is checked later in this function. pcw 02/19/2008
108 try {
109 hdfistream_vgroup vgin(hdf_file.c_str());
110 if (ref != -1)
111 vgin.seek_ref(ref);
112 else
113 vgin.seek(hdf_name.c_str());
114 vgin >> vgroup;
115 vgin.close();
116
117 set_read_p(true);
118
119 LoadStructureFromVgroup(this, vgroup, hdf_file);
120 return true;
121 }
122 catch (...) {
123 set_read_p(false);
124 err = 1;
125 return false;
126 }
127}
128
150
151 BESDEBUG("h4", "Entering HDFStructure::transfer_attributes for variable " << name() << endl);
152
153 if (at) {
154 Vars_iter var = var_begin();
155 while (var != var_end()) {
156 try {
157 BESDEBUG("h4", "Processing the attributes for: " << (*var)->name() << " a " << (*var)->type_name() << endl);
158 (*var)->transfer_attributes(at);
159 var++;
160 } catch (Error &e) {
161 BESDEBUG("h4", "Got this exception: " << e.get_error_message() << endl);
162 var++;
163 throw e;
164 }
165 }
166
167 AttrTable *mine = at->get_attr_table(name());
168
169 if (mine) {
170 mine->set_is_global_attribute(false);
171 AttrTable::Attr_iter at_p = mine->attr_begin();
172 while (at_p != mine->attr_end()) {
173 if (mine->get_attr_type(at_p) == Attr_container)
174 get_attr_table().append_container(new AttrTable(*mine->get_attr_table(at_p)), mine->get_name(at_p));
175 else
176 get_attr_table().append_attr(mine->get_name(at_p), mine->get_type(at_p), mine->get_attr_vector(at_p));
177 at_p++;
178 }
179 }
180 }
181}
virtual void transfer_attributes(libdap::AttrTable *at_container)