OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
FONcStructure.cc
Go to the documentation of this file.
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  {
53  string s = (string)"File out netcdf, write_structure was passed a "
54  + "variable that is not a structure" ;
55  throw BESInternalError( s, __FILE__, __LINE__ ) ;
56  }
57 }
58 
65 {
66  bool done = false ;
67  while( !done )
68  {
69  vector<FONcBaseType *>::iterator i = _vars.begin() ;
70  vector<FONcBaseType *>::iterator e = _vars.end() ;
71  if( i == e )
72  {
73  done = true ;
74  }
75  else
76  {
77  // These are the FONc types, not the actual ones
78  FONcBaseType *b = (*i) ;
79  delete b ;
80  _vars.erase( i ) ;
81  }
82  }
83 }
84 
101 void
102 FONcStructure::convert( vector<string> embed )
103 {
104  FONcBaseType::convert( embed ) ;
105  embed.push_back( name() ) ;
106  Constructor::Vars_iter vi = _s->var_begin() ;
107  Constructor::Vars_iter ve = _s->var_end() ;
108  for( ; vi != ve; vi++ )
109  {
110  BaseType *bt = *vi ;
111  if( bt->send_p() )
112  {
113  BESDEBUG( "fonc", "FONcStructure::convert - converting "
114  << bt->name() << endl ) ;
115  FONcBaseType *fbt = FONcUtils::convert( bt ) ;
116  _vars.push_back( fbt ) ;
117  fbt->convert( embed ) ;
118  }
119  }
120 }
121 
130 void
132 {
133  if( !_defined )
134  {
135  BESDEBUG( "fonc", "FONcStructure::define - defining "
136  << _varname << endl ) ;
137  vector<FONcBaseType *>::const_iterator i = _vars.begin() ;
138  vector<FONcBaseType *>::const_iterator e = _vars.end() ;
139  for( ; i != e; i++ )
140  {
141  FONcBaseType *fbt = (*i) ;
142  BESDEBUG( "fonc", "defining " << fbt->name() << endl ) ;
143  fbt->define( ncid ) ;
144  }
145 
146  _defined = true ;
147 
148  BESDEBUG( "fonc", "FONcStructure::define - done defining "
149  << _varname << endl ) ;
150  }
151 }
152 
160 void
162 {
163  BESDEBUG( "fonc", "FONcStructure::write - writing "
164  << _varname << endl ) ;
165  vector<FONcBaseType *>::const_iterator i = _vars.begin() ;
166  vector<FONcBaseType *>::const_iterator e = _vars.end() ;
167  for( ; i != e; i++ )
168  {
169  FONcBaseType *fbt = (*i) ;
170  fbt->write( ncid ) ;
171  }
172  BESDEBUG( "fonc", "FONcStructure::define - done writing "
173  << _varname << endl ) ;
174 }
175 
180 string
182 {
183  return _s->name() ;
184 }
185 
194 void
195 FONcStructure::dump( ostream &strm ) const
196 {
197  strm << BESIndent::LMarg << "FONcStructure::dump - ("
198  << (void *)this << ")" << endl ;
200  strm << BESIndent::LMarg << "name = " << _s->name() << " {" << endl ;
202  vector<FONcBaseType *>::const_iterator i = _vars.begin() ;
203  vector<FONcBaseType *>::const_iterator e = _vars.end() ;
204  for( ; i != e; i++ )
205  {
206  FONcBaseType *fbt = *i ;
207  fbt->dump( strm ) ;
208  }
210  strm << BESIndent::LMarg << "}" << endl ;
212 }
213 
virtual void define(int ncid)
Define the members of the structure in the netcdf file.
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
exception thrown if inernal error encountered
virtual void dump(ostream &strm) const =0
dump the contents of this object to the specified ostream
virtual string name()=0
FONcStructure(BaseType *b)
Constructor for FONcStructure that takes a DAP Structure.
virtual void convert(vector< string > embed)
Creates the FONc objects for each variable of the structure.
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:58
static void Indent()
Definition: BESIndent.cc:38
string _varname
Definition: FONcBaseType.h:52
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual ~FONcStructure()
Destructor that cleans up the structure.
virtual void write(int ncid)
write the member variables of the structure to the netcdf file
virtual void write(int)
Definition: FONcBaseType.h:65
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:48
virtual string name()
Returns the name of the structure.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
static FONcBaseType * convert(BaseType *v)
creates a FONc object for the given DAP object
Definition: FONcUtils.cc:178
static void UnIndent()
Definition: BESIndent.cc:44
virtual void convert(vector< string > embed)
Definition: FONcBaseType.cc:41