OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDFSequence.cc
Go to the documentation of this file.
1 // This file is part of the hdf4 data handler for the OPeNDAP data server.
2 
3 // Copyright (c) 2005 OPeNDAP, Inc.
4 // Author: James Gallagher <jgallagher@opendap.org>
5 //
6 // This is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your
9 // option) any later version.
10 //
11 // This software is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this software; if not, write to the Free Software Foundation,
18 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
21 
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 <map>
43 #include <string>
44 // Include this on linux to suppres an annoying warning about multiple
45 // definitions of MIN and MAX.
46 #ifdef HAVE_SYS_PARAM_H
47 #include <sys/param.h>
48 #endif
49 #include <mfhdf.h>
50 #include <hdfclass.h>
51 #include <hcstream.h>
52 #include "HDFSequence.h"
53 #include "HDFStructure.h"
54 #include "escaping.h"
55 
56 #include "Error.h"
57 
58 HDFSequence::HDFSequence(const string &n, const string &d)
59  : Sequence(n, d), row(0)
60 {
61 }
62 
64 {
65 }
66 
68 {
69  return new HDFSequence(*this);
70 }
71 
72 void LoadSequenceFromVdata(HDFSequence * seq, hdf_vdata & vd, int row);
73 
75 {
76  int err = 0;
77  int status = read_tagref(-1, -1, err);
78  if (err)
79  throw Error(unknown_error, "Could not read from dataset.");
80  return status;
81 }
82 
83 bool HDFSequence::read_tagref(int32 /*tag*/, int32 ref, int &err)
84 {
85  string hdf_file = dataset();
86  string hdf_name = this->name();
87 
88  // check to see if vd is empty; if so, read in Vdata
89  if (vd.name.length() == 0) {
90  hdfistream_vdata vin(hdf_file.c_str());
91  if (ref != -1)
92  vin.seek_ref(ref);
93  else
94  vin.seek(hdf_name.c_str());
95  vin >> vd;
96  vin.close();
97  if (!vd) { // something is wrong
98  err = 1; // indicate error
99  return false;
100  }
101  }
102  // Return false when no more data are left to be read. Note that error is
103  // also false (i.e., no error occurred). 02/06/98 jhrg
104  if (row >= vd.fields[0].vals[0].size()) {
105  set_read_p(true);
106  err = 0; // everything is OK
107  return true; // Indicate EOF
108  }
109  // is this an empty Vdata.
110  // I'm not sure that it should be an error to read from an empty vdata.
111  // It maybe that valid files have empty vdatas when they are first
112  // created. 02/06/98 jhrg
113  if (vd.fields.size() <= 0 || vd.fields[0].vals.size() <= 0) {
114  err = 1;
115  return false;
116  }
117 
118  LoadSequenceFromVdata(this, vd, row++);
119 
120  set_read_p(true);
121  err = 0; // everything is OK
122 
123  return false;
124 }
125 
127 {
128  if (at) {
129  Vars_iter var = var_begin();
130  while (var != var_end()) {
131  (*var)->transfer_attributes(at);
132  var++;
133  }
134 
135  AttrTable *mine = at->get_attr_table(name());
136 
137  if (mine) {
138  mine->set_is_global_attribute(false);
139  AttrTable::Attr_iter at_p = mine->attr_begin();
140  while (at_p != mine->attr_end()) {
141  if (mine->get_attr_type(at_p) == Attr_container)
142  get_attr_table().append_container(new AttrTable(
143  *mine->get_attr_table(at_p)), mine->get_name(at_p));
144  else
145  get_attr_table().append_attr(mine->get_name(at_p),
146  mine->get_type(at_p), mine->get_attr_vector(at_p));
147  at_p++;
148  }
149  }
150  }
151 }
152 
153 
virtual ~HDFSequence()
Definition: HDFSequence.cc:63
virtual bool read_tagref(int32 tag, int32 ref, int &error)
Definition: HDFSequence.cc:83
vector< hdf_field > fields
Definition: hdfclass.h:211
virtual bool read()
Definition: HDFSequence.cc:74
void LoadSequenceFromVdata(HDFSequence *seq, hdf_vdata &vd, int row)
Definition: hc2dap.cc:523
virtual void seek_ref(int ref)
Definition: vdata.cc:194
virtual BaseType * ptr_duplicate()
Definition: HDFSequence.cc:67
virtual void transfer_attributes(AttrTable *at_container)
Definition: HDFSequence.cc:126
string name
Definition: hdfclass.h:209
hdf_vdata vd
Definition: HDFSequence.h:66
HDFSequence(const string &n, const string &d)
Definition: HDFSequence.cc:58