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