OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
FONcBaseType.cc
Go to the documentation of this file.
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 #define RETURNAS_NETCDF "netcdf"
38 #define RETURNAS_NETCDF4 "netcdf-4"
39 
40 void
41 FONcBaseType::convert( vector<string> embed )
42 {
43  _embed = embed ;
44  _varname = name() ;
45 }
46 
57 void
59 {
60  if( !_defined )
61  {
63  BESDEBUG( "fonc", "FONcBaseType::define - defining "
64  << _varname << endl ) ;
65  int stax = nc_def_var( ncid, _varname.c_str(), type(),
66  0, NULL, &_varid ) ;
67  if( stax != NC_NOERR )
68  {
69  string err = (string)"fileout.netcdf - "
70  + "Failed to define variable "
71  + _varname ;
72  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
73  }
74 
75  BESDEBUG( "fonc", "FONcBaseType::define - done defining "
76  << _varname << endl ) ;
77  }
78 }
79 
86 nc_type
88 {
89  return NC_NAT ; // the constant ncdf uses to define simple type
90 }
91 
94 void
96 {
97  _embed.clear() ;
98 }
99 
102 void FONcBaseType::setVersion(string version)
103 {
104  _ncVersion = version;
105 
106  BESDEBUG( "fonc", "FONcBaseType::setVersion: "
107  << _ncVersion << endl ) ;
108 }
109 
113 {
114 
115  int stax = NC_NOERR;
116 
118  return true;
119  }
120 
122  return false;
123  }
124  else {
125  string err = (string)"fileout.netcdf - "
126  + "Failed to define netcdf version: variable "
127  + _varname ;
128  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
129 
130  return false;
131  }
132 }
string _ncVersion
Definition: FONcBaseType.h:56
virtual void clear_embedded()
Clears the list of embedded variable names.
Definition: FONcBaseType.cc:95
virtual bool isNetCDF4()
Returns true if NetCDF4 features will be required.
virtual string name()=0
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:58
vector< string > _embed
Definition: FONcBaseType.h:54
string _orig_varname
Definition: FONcBaseType.h:53
string _varname
Definition: FONcBaseType.h:52
#define NULL
Definition: wcsUtil.h:65
#define RETURNAS_NETCDF
Definition: FONcBaseType.cc:37
#define RETURNAS_NETCDF4
Definition: FONcBaseType.cc:38
static void handle_error(int stax, string &err, const string &file, int line)
handle any netcdf errors
Definition: FONcUtils.cc:238
static string gen_name(const vector< string > &embed, const string &name, string &original)
generate a new name for the embedded variable
Definition: FONcUtils.cc:150
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
virtual void convert(vector< string > embed)
Definition: FONcBaseType.cc:41
virtual nc_type type()
Returns the type of data of this variable.
Definition: FONcBaseType.cc:87
virtual void setVersion(string version)
Identifies variable with use of NetCDF4 features.