bes  Updated for version 3.20.8
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 <BESInternalError.h>
33 #include <BESDebug.h>
34 
35 #include "FONcStructure.h"
36 #include "FONcUtils.h"
37 #include "FONcAttributes.h"
38 
48  FONcBaseType(), _s(0)
49 {
50  _s = dynamic_cast<Structure *>(b);
51  if (!_s) {
52  string s = (string) "File out netcdf, write_structure was passed a " + "variable that is not a structure";
53  throw BESInternalError(s, __FILE__, __LINE__);
54  }
55 }
56 
63 {
64  bool done = false;
65  while (!done) {
66  vector<FONcBaseType *>::iterator i = _vars.begin();
67  vector<FONcBaseType *>::iterator e = _vars.end();
68  if (i == e) {
69  done = true;
70  }
71  else {
72  // These are the FONc types, not the actual ones
73  FONcBaseType *b = (*i);
74  delete b;
75  _vars.erase(i);
76  }
77  }
78 }
79 
98 void FONcStructure::convert(vector<string> embed,bool is_dap4_group)
99 {
100  FONcBaseType::convert(embed,is_dap4_group);
101  embed.push_back(name());
102  Constructor::Vars_iter vi = _s->var_begin();
103  Constructor::Vars_iter ve = _s->var_end();
104  for (; vi != ve; vi++) {
105  BaseType *bt = *vi;
106  if (bt->send_p()) {
107  BESDEBUG("fonc", "FONcStructure::convert - converting " << bt->name() << endl);
108  bool is_classic_model = true;
109  if(true == isNetCDF4_ENHANCED())
110  is_classic_model = false;
111  FONcBaseType *fbt = FONcUtils::convert(bt,this->_ncVersion,is_classic_model);
112  //fbt->setVersion(this->_ncVersion);
113  //if(true == isNetCDF4())
114  // fbt->setNC4DataModel(this->_nc4_datamodel);
115  _vars.push_back(fbt);
116  fbt->convert(embed,is_dap4_group);
117  }
118  }
119 }
120 
136 void FONcStructure::define(int ncid)
137 {
138  if (!_defined) {
139  BESDEBUG("fonc", "FONcStructure::define - defining " << _varname << endl);
140  vector<FONcBaseType *>::const_iterator i = _vars.begin();
141  vector<FONcBaseType *>::const_iterator e = _vars.end();
142  for (; i != e; i++) {
143  FONcBaseType *fbt = (*i);
144  BESDEBUG("fonc", "defining " << fbt->name() << endl);
145  fbt->define(ncid);
146  }
147 
148  _defined = true;
149 
150  BESDEBUG("fonc", "FONcStructure::define - done defining " << _varname << endl);
151  }
152 }
153 
161 void FONcStructure::write(int ncid)
162 {
163  BESDEBUG("fonc", "FONcStructure::write - writing " << _varname << endl);
164  vector<FONcBaseType *>::const_iterator i = _vars.begin();
165  vector<FONcBaseType *>::const_iterator e = _vars.end();
166  for (; i != e; i++) {
167  FONcBaseType *fbt = (*i);
168  fbt->write(ncid);
169  }
170  BESDEBUG("fonc", "FONcStructure::define - done writing " << _varname << endl);
171 }
172 
178 {
179  return _s->name();
180 }
181 
190 void FONcStructure::dump(ostream &strm) const
191 {
192  strm << BESIndent::LMarg << "FONcStructure::dump - (" << (void *) this << ")" << endl;
193  BESIndent::Indent();
194  strm << BESIndent::LMarg << "name = " << _s->name() << " {" << endl;
195  BESIndent::Indent();
196  vector<FONcBaseType *>::const_iterator i = _vars.begin();
197  vector<FONcBaseType *>::const_iterator e = _vars.end();
198  for (; i != e; i++) {
199  FONcBaseType *fbt = *i;
200  fbt->dump(strm);
201  }
202  BESIndent::UnIndent();
203  strm << BESIndent::LMarg << "}" << endl;
204  BESIndent::UnIndent();
205 }
206 
exception thrown if internal error encountered
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:61
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:54
virtual void dump(std::ostream &strm) const =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.
virtual void write(int ncid)
write the member variables of the structure to the netcdf file
virtual void convert(vector< string > embed, bool is_dap4_group=false)
Creates the FONc objects for each variable of the DAP structure.
FONcStructure(BaseType *b)
Constructor for FONcStructure that takes a DAP Structure.
virtual string name()
Returns the name of the structure.
virtual ~FONcStructure()
Destructor that cleans up the structure.
static FONcBaseType * convert(BaseType *v, const string &version, const bool classic_model)
Creates a FONc object for the given DAP object.
Definition: FONcUtils.cc:225