OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDFStructure.cc
Go to the documentation of this file.
1 // 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 <Error.h>
55 #include <escaping.h>
56 #include <Sequence.h>
57 #include <debug.h>
58 #include <BESDebug.h>
59 
60 #include "HDFStructure.h"
61 
62 HDFStructure::HDFStructure(const string &n, const string &d) :
63  Structure(n, d) {
64 }
65 
67 }
69  return new HDFStructure(*this);
70 }
71 void LoadStructureFromVgroup(HDFStructure * str, const hdf_vgroup & vgroup,
72  const string & hdf_file);
73 
74 void HDFStructure::set_read_p(bool state) {
75  // override Structure::set_read_p() to not set children as read yet
76  BaseType::set_read_p(state);
77 }
78 
80  int err = 0;
81  int status = read_tagref(-1, -1, err);
82  if (err)
83  throw Error(unknown_error, "Could not read from dataset.");
84  return status;
85 }
86 
87 // TODO: Combine the try/catch block and the following if/then/else and
88 // eliminate the boolean 'foundvgroup' Consider moving the
89 // LoadStructureFromVgroup() from hc2dap.cc here since this is the only
90 // place it's used.
91 bool HDFStructure::read_tagref(int32 tag, int32 ref, int &err) {
92  if (read_p())
93  return true;
94 
95  // get the HDF dataset name, Vgroup name
96  string hdf_file = dataset();
97  string hdf_name = this->name();
98 
99  BESDEBUG("h4", " hdf_name = " << hdf_name << endl);
100 
101  hdf_vgroup vgroup;
102 
103  // Wrap this with a try/catch block but don't do anything with it. The
104  // error condition is checked later in this function. pcw 02/19/2008
105  try {
106  hdfistream_vgroup vgin(hdf_file.c_str());
107  if (ref != -1)
108  vgin.seek_ref(ref);
109  else
110  vgin.seek(hdf_name.c_str());
111  vgin >> vgroup;
112  vgin.close();
113 
114  set_read_p(true);
115 
116  LoadStructureFromVgroup(this, vgroup, hdf_file);
117  return true;
118  }
119  catch (...) {
120  set_read_p(false);
121  err = 1;
122  return false;
123  }
124 }
125 
147 
148  BESDEBUG("h4", "Entering HDFStructure::transfer_attributes for variable " << name() << endl);
149 
150  if (at) {
151  Vars_iter var = var_begin();
152  while (var != var_end()) {
153  try {
154  BESDEBUG("h4", "Processing the attributes for: " << (*var)->name() << " a " << (*var)->type_name() << endl);
155  (*var)->transfer_attributes(at);
156  var++;
157  } catch (Error &e) {
158  BESDEBUG("h4", "Got this exception: " << e.get_error_message() << endl);
159  var++;
160  throw e;
161  }
162  }
163 
164  AttrTable *mine = at->get_attr_table(name());
165 
166  if (mine) {
167  mine->set_is_global_attribute(false);
168  AttrTable::Attr_iter at_p = mine->attr_begin();
169  while (at_p != mine->attr_end()) {
170  if (mine->get_attr_type(at_p) == Attr_container)
171  get_attr_table().append_container(new AttrTable(*mine->get_attr_table(at_p)), mine->get_name(at_p));
172  else
173  get_attr_table().append_attr(mine->get_name(at_p), mine->get_type(at_p), mine->get_attr_vector(at_p));
174  at_p++;
175  }
176  }
177  }
178 }
HDFStructure(const string &n, const string &d)
Definition: HDFStructure.cc:62
virtual bool read()
Definition: HDFStructure.cc:79
virtual BaseType * ptr_duplicate()
Definition: HDFStructure.cc:68
void LoadStructureFromVgroup(HDFStructure *str, const hdf_vgroup &vgroup, const string &hdf_file)
Definition: hc2dap.cc:585
virtual void set_read_p(bool state)
Definition: HDFStructure.cc:74
virtual void transfer_attributes(AttrTable *at_container)
Transfer attributes from a separately built DAS to the DDS.
virtual bool read_tagref(int32 tag, int32 ref, int &error)
Definition: HDFStructure.cc:91
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
virtual void seek_ref(int ref)
Definition: vgroup.cc:221
virtual ~HDFStructure()
Definition: HDFStructure.cc:66