bes  Updated for version 3.20.6
FONcBaseType.cc
1 // FONcBaseType.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 <BESDebug.h>
33 
34 #include "FONcBaseType.h"
35 #include "FONcUtils.h"
36 
37 void FONcBaseType::convert(vector<string> embed)
38 {
39  _embed = embed;
40  _varname = name();
41 }
42 
53 void FONcBaseType::define(int ncid)
54 {
55  if (!_defined) {
56  _varname = FONcUtils::gen_name(_embed, _varname, _orig_varname);
57  BESDEBUG("fonc", "FONcBaseType::define - defining '" << _varname << "'" << endl);
58  int stax = nc_def_var(ncid, _varname.c_str(), type(), 0, NULL, &_varid);
59  if (stax != NC_NOERR) {
60  string err = (string) "fileout.netcdf - " + "Failed to define variable " + _varname;
61  FONcUtils::handle_error(stax, err, __FILE__, __LINE__);
62  }
63 
64  BESDEBUG("fonc", "FONcBaseType::define - done defining " << _varname << endl);
65  }
66 }
67 
75 {
76  return NC_NAT; // the constant ncdf uses to define simple type
77 }
78 
82 {
83  _embed.clear();
84 }
85 
88 void FONcBaseType::setVersion(string version)
89 {
90  _ncVersion = version;
91 
92  BESDEBUG("fonc", "FONcBaseType::setVersion() - version: '" << _ncVersion << "'" << endl);
93 }
94 
98 {
99  return FONcBaseType::_ncVersion == RETURNAS_NETCDF4;
100 }
FONcBaseType::define
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:53
FONcUtils::gen_name
static string gen_name(const vector< string > &embed, const string &name, string &original)
generate a new name for the embedded variable
Definition: FONcUtils.cc:148
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
FONcBaseType::type
virtual nc_type type()
Returns the type of data of this variable.
Definition: FONcBaseType.cc:74
FONcBaseType::clear_embedded
virtual void clear_embedded()
Clears the list of embedded variable names.
Definition: FONcBaseType.cc:81
FONcBaseType::isNetCDF4
virtual bool isNetCDF4()
Returns true if NetCDF4 features will be required.
Definition: FONcBaseType.cc:97
FONcBaseType::setVersion
virtual void setVersion(std::string version)
Identifies variable with use of NetCDF4 features.
Definition: FONcBaseType.cc:88