bes  Updated for version 3.20.6
FONcShort.cc
1 // FONcShort.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 <Int16.h>
35 #include <UInt16.h>
36 
37 #include "FONcShort.h"
38 #include "FONcUtils.h"
39 #include "FONcAttributes.h"
40 
49 FONcShort::FONcShort( BaseType *b )
50  : FONcBaseType(), _bt( b )
51 {
52  Int16 *i16 = dynamic_cast<Int16 *>(b) ;
53  UInt16 *u16 = dynamic_cast<UInt16 *>(b) ;
54  if( !i16 && !u16 )
55  {
56  string s = (string)"File out netcdf, FONcShort was passed a "
57  + "variable that is not a DAP Int16 or UInt16" ;
58  throw BESInternalError( s, __FILE__, __LINE__ ) ;
59  }
60 }
61 
68 {
69 }
70 
81 void
82 FONcShort::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 
105 void
106 FONcShort::write( int ncid )
107 {
108  BESDEBUG( "fonc", "FONcShort::write for var " << _varname << endl ) ;
109  size_t var_index[] = {0} ;
110  short *data = new short ;
111  _bt->buf2val( (void**)&data ) ;
112  int stax = nc_put_var1_short( ncid, _varid, var_index, data ) ;
113  if( stax != NC_NOERR )
114  {
115  string err = (string)"fileout.netcdf - "
116  + "Failed to write short data for "
117  + _varname ;
118  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
119  }
120  delete data ;
121  BESDEBUG( "fonc", "FONcShort::done write for var " << _varname << endl ) ;
122 }
123 
128 string
130 {
131  return _bt->name() ;
132 }
133 
138 nc_type
140 {
141  return NC_SHORT ;
142 }
143 
150 void
151 FONcShort::dump( ostream &strm ) const
152 {
153  strm << BESIndent::LMarg << "FONcShort::dump - ("
154  << (void *)this << ")" << endl ;
155  BESIndent::Indent() ;
156  strm << BESIndent::LMarg << "name = " << _bt->name() << endl ;
157  BESIndent::UnIndent() ;
158 }
159 
FONcBaseType::define
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:53
FONcShort::FONcShort
FONcShort(BaseType *b)
Constructor for FOncShort that takes a DAP Int16 or UInt16.
Definition: FONcShort.cc:49
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
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
FONcShort::name
virtual string name()
returns the name of the DAP Int16 or UInt16
Definition: FONcShort.cc:129
FONcShort::dump
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcShort.cc:151
FONcShort::~FONcShort
virtual ~FONcShort()
Destructor that cleans up the short.
Definition: FONcShort.cc:67
FONcShort::write
virtual void write(int ncid)
Write the short out to the netcdf file.
Definition: FONcShort.cc:106
FONcShort::type
virtual nc_type type()
returns the netcdf type of the DAP object
Definition: FONcShort.cc:139
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
FONcShort::define
virtual void define(int ncid)
define the DAP Int16 or UInt16 in the netcdf file
Definition: FONcShort.cc:82
FONcBaseType
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:58