bes Updated for version 3.20.13
FONcInt64.cc
1// FONcInt64.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// kyang Kent Yang <myang6@hdfgroup.org>
30// Note: The code follows FONcUInt.cc.
31
32
33#include <BESInternalError.h>
34#include <BESDebug.h>
35#include <libdap/Int64.h>
36
37#include "FONcInt64.h"
38#include "FONcUtils.h"
39#include "FONcAttributes.h"
40
50 : FONcBaseType(), _bt( b )
51{
52 Int64 *u64 = dynamic_cast<Int64 *>(b) ;
53 if( !u64 )
54 {
55 string s = (string)"File out netcdf, FONcUInt was passed a "
56 + "variable that is not a DAP Int64" ;
57 throw BESInternalError( s, __FILE__, __LINE__ ) ;
58 }
59}
60
67{
68}
69
80void
82{
83 FONcBaseType::define( ncid ) ;
84
85 if( !_defined )
86 {
87 if(is_dap4) {
88 D4Attributes *d4_attrs = _bt->attributes();
89 updateD4AttrType(d4_attrs,NC_INT64);
90 }
91 else {
92 AttrTable &attrs = _bt->get_attr_table();
93 updateAttrType(attrs,NC_INT64);
94 }
95
96 FONcAttributes::add_variable_attributes( ncid, _varid, _bt ,isNetCDF4_ENHANCED(),is_dap4) ;
98 _varname, _orig_varname ) ;
99
100 _defined = true ;
101 }
102}
103
111void
113{
114 BESDEBUG( "fonc", "FONcInt64::write for var " << _varname << endl ) ;
115 size_t var_index[] = {0} ;
116 //int64_t *data = new int64_t ;
117 long long *data = new long long ;
118
119 if (is_dap4)
120 _bt->intern_data();
121 else
122 _bt->intern_data(*get_eval(), *get_dds());
123
124 _bt->buf2val( (void**)&data ) ;
125 //int stax = nc_put_var1_longlong( ncid, _varid, var_index, (const long long*)data ) ;
126 int stax = nc_put_var1_longlong( ncid, _varid, var_index, data ) ;
127 if( stax != NC_NOERR )
128 {
129 string err = (string)"fileout.netcdf - "
130 + "Failed to write unsigned int data for "
131 + _varname ;
132 FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
133 }
134 delete data ;
135 BESDEBUG( "fonc", "FONcInt64::done write for var " << _varname << endl ) ;
136}
137
142string
144{
145 return _bt->name() ;
146}
147
152nc_type
154{
155 return NC_INT64 ;
156}
157
164void
165FONcInt64::dump( ostream &strm ) const
166{
167 strm << BESIndent::LMarg << "FONcInt64::dump - ("
168 << (void *)this << ")" << endl ;
169 BESIndent::Indent() ;
170 strm << BESIndent::LMarg << "name = " << _bt->name() << endl ;
171 BESIndent::UnIndent() ;
172}
173
exception thrown if internal error encountered
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.
static void add_variable_attributes(int ncid, int varid, BaseType *b, bool is_netCDF_enhanced, bool is_dap4)
Add the attributes for an OPeNDAP variable to the netcdf file.
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:60
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:60
virtual string name()
returns the name of the DAP Int64
Definition: FONcInt64.cc:143
virtual void define(int ncid)
define the DAP Int64 in the netcdf file
Definition: FONcInt64.cc:81
virtual ~FONcInt64()
Destructor that cleans up the instance.
Definition: FONcInt64.cc:66
virtual nc_type type()
returns the netcdf type of the DAP object
Definition: FONcInt64.cc:153
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcInt64.cc:165
FONcInt64(libdap::BaseType *b)
Constructor for FOncInt64 that takes a DAP Int64.
Definition: FONcInt64.cc:49
virtual void write(int ncid)
Write the unsigned int out to the netcdf file.
Definition: FONcInt64.cc:112
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
Definition: FONcUtils.cc:424