bes  Updated for version 3.20.8
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,bool dap4_group)
38 {
39  _embed = embed;
40  _varname = name();
41  is_dap4_group = dap4_group;
42 }
43 
54 void FONcBaseType::define(int ncid)
55 {
56  if (!_defined) {
57  _varname = FONcUtils::gen_name(_embed, _varname, _orig_varname);
58  BESDEBUG("fonc", "FONcBaseType::define - defining '" << _varname << "'" << endl);
59  int stax = nc_def_var(ncid, _varname.c_str(), type(), 0, NULL, &_varid);
60  if (stax != NC_NOERR) {
61  string err = (string) "fileout.netcdf - " + "Failed to define variable " + _varname;
62  FONcUtils::handle_error(stax, err, __FILE__, __LINE__);
63  }
64 
65  BESDEBUG("fonc", "FONcBaseType::define - done defining " << _varname << endl);
66  }
67 }
68 
76 {
77  return NC_NAT; // the constant ncdf uses to define simple type
78 }
79 
83 {
84  _embed.clear();
85 }
86 
89 void FONcBaseType::setVersion(string version)
90 {
91  _ncVersion = version;
92 
93  BESDEBUG("fonc", "FONcBaseType::setVersion() - version: '" << _ncVersion << "'" << endl);
94 }
95 
98 void FONcBaseType::setNC4DataModel(string nc4_datamodel)
99 {
100  _nc4_datamodel= nc4_datamodel;
101 
102  BESDEBUG("fonc", "FONcBaseType::setNC4DataModel() - data model: '" << _nc4_datamodel << "'" << endl);
103 }
107 {
108  return FONcBaseType::_ncVersion == RETURNAS_NETCDF4;
109 }
110 bool FONcBaseType::isNetCDF4_ENHANCED()
111 {
112  return FONcBaseType::_nc4_datamodel == NC4_ENHANCED;
113 }
virtual void setVersion(std::string version)
Identifies variable with use of NetCDF4 features.
Definition: FONcBaseType.cc:89
virtual void setNC4DataModel(std::string nc4_datamodel)
Identifies the netCDF4 data model (CLASSIC or ENHANCED)
Definition: FONcBaseType.cc:98
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:54
virtual bool isNetCDF4()
Returns true if NetCDF4 features will be required.
virtual nc_type type()
Returns the type of data of this variable.
Definition: FONcBaseType.cc:75
virtual void clear_embedded()
Clears the list of embedded variable names.
Definition: FONcBaseType.cc:82
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
Definition: FONcUtils.cc:399
static string gen_name(const vector< string > &embed, const string &name, string &original)
generate a new name for the embedded variable
Definition: FONcUtils.cc:189