bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
FONcArrayStructure.cc
1// FONcArrayStructure.cc
2
3// This file is part of BES Netcdf File Out Module
4
5// // Copyright (c) The HDF Group, Inc. and OPeNDAP, Inc.
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
18// License along with this library; if not, write to the Free Software
19// Foundation, 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// You can contact The HDF Group, Inc. at 410 E University Ave,
23// Suite 200, Champaign, IL 61820
24
25#include <libdap/util.h>
26#include <BESInternalError.h>
27#include <BESDebug.h>
28
29#include "FONcArrayStructure.h"
30#include "FONcUtils.h"
31#include "FONcAttributes.h"
32
42 FONcBaseType(),_as(dynamic_cast<Array*>(b))
43{
44 if (!_as) {
45 string s = "File out netcdf, array of structure was passed a variable that is not an array ";
46 throw BESInternalError(s, __FILE__, __LINE__);
47 }
48 if (_as->var()->type() != dods_structure_c) {
49 string s = "File out netcdf, array of structure was passed a variable that is not a structure ";
50 throw BESInternalError(s, __FILE__, __LINE__);
51 }
52}
53
60{
61 for (auto &var: _vars) {
62 delete var;
63 }
64
65}
66
85void FONcArrayStructure::convert(vector<string> embed, bool _dap4, bool is_dap4_group){
86
87 set_is_dap4(_dap4);
88 FONcBaseType::convert(embed,_dap4,is_dap4_group);
89 embed.push_back(name());
90
91 auto as_v = dynamic_cast<Structure *>(_as->var());
92 if (!as_v) {
93 string s = "File out netcdf, write an array of structure was passed a variable that is not a structure";
94 throw BESInternalError(s, __FILE__, __LINE__);
95 }
96
97 if (false == isNetCDF4_ENHANCED()) {
98 throw BESInternalError("Fileout netcdf: We don't support array of structure for the classical model now. ",
99 __FILE__, __LINE__);
100 }
101
102 for (auto &bt: as_v->variables()) {
103
104 Type t_bt = bt->type();
105
106 // Only support array or scalar of float/int/string.
107 if (libdap::is_simple_type(t_bt) == false) {
108
109 if (t_bt != dods_array_c) {
110 can_handle_str_memb = false;
111 break;
112 }
113 else {
114 auto t_a = dynamic_cast<Array *>(bt);
115 Type t_array_var = t_a->var()->type();
116 if (!libdap::is_simple_type(t_array_var) || t_array_var == dods_url_c || t_array_var == dods_enum_c || t_array_var==dods_opaque_c) {
117 can_handle_str_memb = false;
118 break;
119 }
120 }
121 }
122 else if (t_bt == dods_url_c || t_bt == dods_enum_c || t_bt==dods_opaque_c) {
123 can_handle_str_memb= false;
124 break;
125 }
126 }
127
128 // If we handle the structure that contains the string, we need to obtain the data here.
129 if(can_handle_str_memb) {
130 if (d_is_dap4)
131 _as->intern_data();
132 else
133 _as->intern_data(*get_eval(),*get_dds());
134 }
135
136 for (auto &bt: as_v->variables()) {
137 if (bt->send_p()) {
138 BESDEBUG("fonc", "FONcArrayStructure::convert - converting " << bt->name() << endl);
139 auto fsf = new FONcArrayStructureField(bt, _as, isNetCDF4_ENHANCED());
140 _vars.push_back(fsf);
141 fsf->convert(embed,_dap4,is_dap4_group);
142 }
143 }
144
145}
146
163{
164
165 if (!d_defined) {
166 BESDEBUG("fonc", "FONcArrayStructure::define - defining " << d_varname << endl);
167
168 for (auto &fbt:_vars) {
169 BESDEBUG("fonc", "defining " << fbt->name() << endl);
170 fbt->define(ncid);
171 }
172
173 d_defined = true;
174
175 BESDEBUG("fonc", "FONcArrayStructure::define - done defining " << d_varname << endl);
176 }
177
178}
179
188{
189
190 BESDEBUG("fonc", "FONcArrayStructure::write - writing " << d_varname << endl);
191 // If we don't handle the structure that contains strings, we can obtain the data at this time.
192 if(!can_handle_str_memb) {
193 if (d_is_dap4)
194 _as->intern_data();
195 else
196 _as->intern_data(*get_eval(),*get_dds());
197 }
198
199 for (const auto &var:_vars) {
200 var->write(ncid);
201 }
202 BESDEBUG("fonc", "FONcArrayStructure::define - done writing " << d_varname << endl);
203}
204
210{
211 return _as->name();
212}
213
223{
224 strm << BESIndent::LMarg << "FONcArrayStructure::dump - (" << (void *) this << ")" << endl;
225 BESIndent::Indent();
226 strm << BESIndent::LMarg << "name = " << _as->name() << " {" << endl;
227 BESIndent::Indent();
228 for (const auto & _var:_vars)
229 _var->dump(strm);
230 BESIndent::UnIndent();
231 strm << BESIndent::LMarg << "}" << endl;
232 BESIndent::UnIndent();
233}
234
exception thrown if internal error encountered
A DAP Array with file out netcdf information included.
void convert(vector< string > embed, bool _dap4=true, bool is_dap4_group=false) override
Creates the FONc objects for each variable of the DAP array of structure.
~FONcArrayStructure() override
Destructor that cleans up the array of structure.
void define(int ncid) override
Define the members of the array of structure in the netcdf file.
void dump(ostream &strm) const override
dumps information about this object for debugging purposes
string name() override
Returns the name of the structure.
FONcArrayStructure(libdap::BaseType *b)
Constructor for FONcArrayStructure that takes a DAP Array Structure.
void write(int ncid) override
write the member variables of the structure to the netcdf file
STL class.
STL class.