bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDFSequence.cc
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 <libdap/escaping.h>
55
56#include <libdap/Error.h>
57
58using namespace libdap;
59using namespace std;
60
61HDFSequence::HDFSequence(const string &n, const string &d)
62 : Sequence(n, d)
63{
64}
65
66HDFSequence::~HDFSequence() = default;
67
68BaseType *HDFSequence::ptr_duplicate()
69{
70 return new HDFSequence(*this);
71}
72
73void LoadSequenceFromVdata(HDFSequence * seq, hdf_vdata & vd, int row);
74
75bool HDFSequence::read()
76{
77 int err = 0;
78 int status = read_tagref(-1, -1, err);
79 if (err)
80 throw Error(unknown_error, "Could not read from dataset.");
81 return status;
82}
83
84bool HDFSequence::read_tagref(int32 /*tag*/, int32 ref, int &err)
85{
86 string hdf_file = dataset();
87 string hdf_name = this->name();
88
89 // check to see if vd is empty; if so, read in Vdata
90 if (vd.name.size() == 0) {
91 hdfistream_vdata vin(hdf_file.c_str());
92 if (ref != -1)
93 vin.seek_ref(ref);
94 else
95 vin.seek(hdf_name.c_str());
96 vin >> vd;
97 vin.close();
98 if (!vd) { // something is wrong
99 err = 1; // indicate error
100 return false;
101 }
102 }
103 // Return false when no more data are left to be read. Note that error is
104 // also false (i.e., no error occurred). 02/06/98 jhrg
105 if (row >= vd.fields[0].vals[0].size()) {
106 set_read_p(true);
107 err = 0; // everything is OK
108 return true; // Indicate EOF
109 }
110 // is this an empty Vdata.
111 // I'm not sure that it should be an error to read from an empty vdata.
112 // It maybe that valid files have empty vdatas when they are first
113 // created. 02/06/98 jhrg
114 if (vd.fields.size() <= 0 || vd.fields[0].vals.size() <= 0) {
115 err = 1;
116 return false;
117 }
118
119 LoadSequenceFromVdata(this, vd, row++);
120
121 set_read_p(true);
122 err = 0; // everything is OK
123
124 return false;
125}
126
127void HDFSequence::transfer_attributes(AttrTable *at)
128{
129 if (at) {
130 Vars_iter var = var_begin();
131 while (var != var_end()) {
132 (*var)->transfer_attributes(at);
133 var++;
134 }
135
136 AttrTable *mine = at->get_attr_table(name());
137
138 if (mine) {
139 mine->set_is_global_attribute(false);
140 AttrTable::Attr_iter at_p = mine->attr_begin();
141 while (at_p != mine->attr_end()) {
142 if (mine->get_attr_type(at_p) == Attr_container)
143 get_attr_table().append_container(new AttrTable(
144 *mine->get_attr_table(at_p)), mine->get_name(at_p));
145 else
146 get_attr_table().append_attr(mine->get_name(at_p),
147 mine->get_type(at_p), mine->get_attr_vector(at_p));
148 at_p++;
149 }
150 }
151 }
152}
153
154