bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
FONcStructure.cc
1// FONcStructure.cc
2
3// This file is part of BES Netcdf File Out Module
4
5// Copyright (c) 2004,2005 University Corporation for Atmospheric Research
6// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// You can contact University Corporation for Atmospheric Research at
23// 3080 Center Green Drive, Boulder, CO 80301
24
25// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
26// Please read the full copyright statement in the file COPYRIGHT_UCAR.
27//
28// Authors:
29// pwest Patrick West <pwest@ucar.edu>
30// jgarcia Jose Garcia <jgarcia@ucar.edu>
31
32#include <libdap/util.h> // is_simple_type()
33#include <libdap/Array.h>
34#include <BESInternalError.h>
35#include <BESDebug.h>
36
37#include "FONcStructure.h"
38#include "FONcUtils.h"
39#include "FONcAttributes.h"
40
50 FONcBaseType(), _s(0)
51{
52 _s = dynamic_cast<Structure *>(b);
53 if (!_s) {
54 string s = (string) "File out netcdf, write_structure was passed a " + "variable that is not a structure";
55 throw BESInternalError(s, __FILE__, __LINE__);
56 }
57
58 for (const auto &bt:_s->variables()) {
59
60 Type t_bt = bt->type();
61 // Only support array or scalar of float/int/string.
62 if (libdap::is_simple_type(t_bt) == false) {
63
64 if (t_bt != dods_array_c) {
65 can_handle_str_memb = false;
66 break;
67 }
68 else {
69 auto t_a = dynamic_cast<Array *>(bt);
70 Type t_array_var = t_a->var()->type();
71 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) {
72 can_handle_str_memb = false;
73 break;
74 }
75 }
76 }
77 else if (t_bt == dods_url_c || t_bt == dods_enum_c || t_bt==dods_opaque_c) {
78 can_handle_str_memb = false;
79 break;
80 }
81
82 }
83}
84
91{
92 bool done = false;
93 while (!done) {
94 vector<FONcBaseType *>::iterator i = _vars.begin();
96 if (i == e) {
97 done = true;
98 }
99 else {
100 // These are the FONc types, not the actual ones
101 FONcBaseType *b = (*i);
102 delete b;
103 _vars.erase(i);
104 }
105 }
106}
107
126void FONcStructure::convert(vector<string> embed,bool _dap4, bool is_dap4_group)
127{
128
129 if (can_handle_str_memb) {
130 if (_dap4)
131 _s->intern_data();
132 else
133 _s->intern_data(*get_eval(),*get_dds());
134 }
135
136 FONcBaseType::convert(embed,_dap4,is_dap4_group);
137 embed.push_back(name());
138 Constructor::Vars_iter vi = _s->var_begin();
139 Constructor::Vars_iter ve = _s->var_end();
140 for (; vi != ve; vi++) {
141 BaseType *bt = *vi;
142 if (bt->send_p()) {
143 BESDEBUG("fonc", "FONcStructure::convert - converting " << bt->name() << endl);
144 bool is_classic_model = true;
145 if(true == isNetCDF4_ENHANCED())
146 is_classic_model = false;
147 FONcBaseType *fbt = FONcUtils::convert(bt, this->d_ncVersion, is_classic_model);
148 _vars.push_back(fbt);
149 fbt->convert(embed,_dap4,is_dap4_group);
150 }
151 }
152}
153
170{
171 if (!d_defined) {
172 BESDEBUG("fonc", "FONcStructure::define - defining " << d_varname << endl);
173
176 for (; i != e; i++) {
177 FONcBaseType *fbt = (*i);
178 BESDEBUG("fonc", "defining " << fbt->name() << endl);
179 fbt->define(ncid);
180 }
181
182 d_defined = true;
183
184 BESDEBUG("fonc", "FONcStructure::define - done defining " << d_varname << endl);
185 }
186}
187
196{
197
198 if (can_handle_str_memb == false) {
199 if (d_is_dap4)
200 _s->intern_data();
201 else
202 _s->intern_data(*get_eval(),*get_dds());
203 }
204 BESDEBUG("fonc", "FONcStructure::write - writing " << d_varname << endl);
207 for (; i != e; i++) {
208 FONcBaseType *fbt = (*i);
209
210 fbt->set_dds(get_dds());
211 fbt->set_eval(get_eval());
212
213 fbt->write(ncid);
214 nc_sync(ncid);
215 }
216 BESDEBUG("fonc", "FONcStructure::define - done writing " << d_varname << endl);
217}
218
224{
225 return _s->name();
226}
227
237{
238 strm << BESIndent::LMarg << "FONcStructure::dump - (" << (void *) this << ")" << endl;
239 BESIndent::Indent();
240 strm << BESIndent::LMarg << "name = " << _s->name() << " {" << endl;
241 BESIndent::Indent();
244 for (; i != e; i++) {
245 FONcBaseType *fbt = *i;
246 fbt->dump(strm);
247 }
248 BESIndent::UnIndent();
249 strm << BESIndent::LMarg << "}" << endl;
250 BESIndent::UnIndent();
251}
252
exception thrown if internal error encountered
virtual void define(int ncid)
Define the variable in the netcdf file.
void dump(std::ostream &strm) const override=0
dump the contents of this object to the specified ostream
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
virtual void define(int ncid)
Define the members of the structure in the netcdf file.
FONcStructure(libdap::BaseType *b)
Constructor for FONcStructure that takes a DAP Structure.
virtual void write(int ncid)
write the member variables of the structure to the netcdf file
virtual string name()
Returns the name of the structure.
virtual void convert(vector< string > embed, bool _dap4=false, bool is_dap4_group=false)
Creates the FONc objects for each variable of the DAP structure.
virtual ~FONcStructure()
Destructor that cleans up the structure.
STL class.
STL class.
STL iterator class.
STL iterator class.
STL class.