bes  Updated for version 3.20.6
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)
99 {
100  FONcBaseType::convert(embed);
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  FONcBaseType *fbt = FONcUtils::convert(bt);
109  fbt->setVersion(this->_ncVersion);
110  _vars.push_back(fbt);
111  fbt->convert(embed);
112  }
113  }
114 }
115 
131 void FONcStructure::define(int ncid)
132 {
133  if (!_defined) {
134  BESDEBUG("fonc", "FONcStructure::define - defining " << _varname << endl);
135  vector<FONcBaseType *>::const_iterator i = _vars.begin();
136  vector<FONcBaseType *>::const_iterator e = _vars.end();
137  for (; i != e; i++) {
138  FONcBaseType *fbt = (*i);
139  BESDEBUG("fonc", "defining " << fbt->name() << endl);
140  fbt->define(ncid);
141  }
142 
143  _defined = true;
144 
145  BESDEBUG("fonc", "FONcStructure::define - done defining " << _varname << endl);
146  }
147 }
148 
156 void FONcStructure::write(int ncid)
157 {
158  BESDEBUG("fonc", "FONcStructure::write - writing " << _varname << endl);
159  vector<FONcBaseType *>::const_iterator i = _vars.begin();
160  vector<FONcBaseType *>::const_iterator e = _vars.end();
161  for (; i != e; i++) {
162  FONcBaseType *fbt = (*i);
163  fbt->write(ncid);
164  }
165  BESDEBUG("fonc", "FONcStructure::define - done writing " << _varname << endl);
166 }
167 
173 {
174  return _s->name();
175 }
176 
185 void FONcStructure::dump(ostream &strm) const
186 {
187  strm << BESIndent::LMarg << "FONcStructure::dump - (" << (void *) this << ")" << endl;
188  BESIndent::Indent();
189  strm << BESIndent::LMarg << "name = " << _s->name() << " {" << endl;
190  BESIndent::Indent();
191  vector<FONcBaseType *>::const_iterator i = _vars.begin();
192  vector<FONcBaseType *>::const_iterator e = _vars.end();
193  for (; i != e; i++) {
194  FONcBaseType *fbt = *i;
195  fbt->dump(strm);
196  }
197  BESIndent::UnIndent();
198  strm << BESIndent::LMarg << "}" << endl;
199  BESIndent::UnIndent();
200 }
201 
FONcBaseType::define
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:53
FONcBaseType::dump
virtual void dump(std::ostream &strm) const =0
dump the contents of this object to the specified ostream
FONcStructure::write
virtual void write(int ncid)
write the member variables of the structure to the netcdf file
Definition: FONcStructure.cc:156
FONcStructure::~FONcStructure
virtual ~FONcStructure()
Destructor that cleans up the structure.
Definition: FONcStructure.cc:62
FONcStructure::name
virtual string name()
Returns the name of the structure.
Definition: FONcStructure.cc:172
FONcStructure::dump
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcStructure.cc:185
FONcStructure::FONcStructure
FONcStructure(BaseType *b)
Constructor for FONcStructure that takes a DAP Structure.
Definition: FONcStructure.cc:47
FONcStructure::define
virtual void define(int ncid)
Define the members of the structure in the netcdf file.
Definition: FONcStructure.cc:131
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
FONcUtils::convert
static FONcBaseType * convert(BaseType *v)
Creates a FONc object for the given DAP object.
Definition: FONcUtils.cc:182
FONcBaseType
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:58
FONcStructure::convert
virtual void convert(vector< string > embed)
Creates the FONc objects for each variable of the DAP structure.
Definition: FONcStructure.cc:98
FONcBaseType::setVersion
virtual void setVersion(std::string version)
Identifies variable with use of NetCDF4 features.
Definition: FONcBaseType.cc:88