bes  Updated for version 3.20.6
FONcInt.cc
1 // FONcInt.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 #include <Int32.h>
35 #include <UInt32.h>
36 
37 #include "FONcInt.h"
38 #include "FONcUtils.h"
39 #include "FONcAttributes.h"
40 
49 FONcInt::FONcInt( BaseType *b )
50  : FONcBaseType(), _bt( b )
51 {
52  Int32 *i32 = dynamic_cast<Int32 *>(b) ;
53  UInt32 *u32 = dynamic_cast<UInt32 *>(b) ;
54  if( !i32 && !u32 )
55  {
56  string s = (string)"File out netcdf, FONcInt was passed a "
57  + "variable that is not a DAP Int32 or UInt32" ;
58  throw BESInternalError( s, __FILE__, __LINE__ ) ;
59  }
60 }
61 
68 {
69 }
70 
81 void
82 FONcInt::define( int ncid )
83 {
84  FONcBaseType::define( ncid ) ;
85 
86  if( !_defined )
87  {
88  FONcAttributes::add_variable_attributes( ncid, _varid, _bt ) ;
90  _varname, _orig_varname ) ;
91 
92  _defined = true ;
93  }
94 }
95 
103 void
104 FONcInt::write( int ncid )
105 {
106  BESDEBUG( "fonc", "FONcInt::write for var " << _varname << endl ) ;
107  size_t var_index[] = {0} ;
108  int *data = new int ;
109  _bt->buf2val( (void**)&data ) ;
110  int stax = nc_put_var1_int( ncid, _varid, var_index, data ) ;
111  if( stax != NC_NOERR )
112  {
113  string err = (string)"fileout.netcdf - "
114  + "Failed to write int data for "
115  + _varname ;
116  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
117  }
118  delete data ;
119  BESDEBUG( "fonc", "FONcInt::done write for var " << _varname << endl ) ;
120 }
121 
126 string
128 {
129  return _bt->name() ;
130 }
131 
136 nc_type
138 {
139  return NC_INT ;
140 }
141 
148 void
149 FONcInt::dump( ostream &strm ) const
150 {
151  strm << BESIndent::LMarg << "FONcInt::dump - ("
152  << (void *)this << ")" << endl ;
153  BESIndent::Indent() ;
154  strm << BESIndent::LMarg << "name = " << _bt->name() << endl ;
155  BESIndent::UnIndent() ;
156 }
157 
FONcInt::define
virtual void define(int ncid)
define the DAP Int32 or UInt32 in the netcdf file
Definition: FONcInt.cc:82
FONcBaseType::define
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:53
FONcUtils::handle_error
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
Definition: FONcUtils.cc:245
FONcInt::~FONcInt
virtual ~FONcInt()
Destructor that cleans up the instance.
Definition: FONcInt.cc:67
FONcAttributes::add_variable_attributes
static void add_variable_attributes(int ncid, int varid, BaseType *b)
Add the attributes for an OPeNDAP variable to the netcdf file.
Definition: FONcAttributes.cc:77
FONcInt::write
virtual void write(int ncid)
Write the int out to the netcdf file.
Definition: FONcInt.cc:104
FONcInt::type
virtual nc_type type()
returns the netcdf type of the DAP object
Definition: FONcInt.cc:137
FONcInt::name
virtual string name()
returns the name of the DAP Int32 or UInt32
Definition: FONcInt.cc:127
FONcInt::FONcInt
FONcInt(BaseType *b)
Constructor for FOncInt that takes a DAP Int32 or UInt32.
Definition: FONcInt.cc:49
FONcInt::dump
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcInt.cc:149
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
FONcAttributes::add_original_name
static void add_original_name(int ncid, int varid, const string &var_name, const string &orig)
Adds an attribute for the variable if the variable name had to be modified in any way.
Definition: FONcAttributes.cc:415
FONcBaseType
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:58