bes  Updated for version 3.20.6
FONcSequence.cc
1 // FONcSequence.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 
34 #include "FONcSequence.h"
35 #include "FONcUtils.h"
36 
46  FONcBaseType(), _s(0)
47 {
48  _s = dynamic_cast<Sequence *>(b);
49  if (!_s) {
50  throw BESInternalError("File out netcdf, FONcSequence was passed a variable that is not a DAP Sequence", __FILE__, __LINE__);
51  }
52 }
53 
60 {
61 }
62 
72 void FONcSequence::convert(vector<string> embed)
73 {
74  FONcBaseType::convert(embed);
75  _varname = FONcUtils::gen_name(embed, _varname, _orig_varname);
76 }
77 
88 void FONcSequence::define(int ncid)
89 {
90  // for now we are simply going to add a global variable noting the
91  // presence of the sequence, the name of the sequence, and that the
92  // sequences has been elided.
93  string val = (string) "The sequence " + _varname + " is a member of this dataset and has been elided.";
94  int stax = nc_put_att_text(ncid, NC_GLOBAL, _varname.c_str(), val.length(), val.c_str());
95  if (stax != NC_NOERR) {
96  string err = (string) "File out netcdf, " + "failed to write string attribute for sequence " + _varname;
97  FONcUtils::handle_error(stax, err, __FILE__, __LINE__);
98  }
99 }
100 
110 void FONcSequence::write(int /*ncid*/)
111 {
112 }
113 
114 string FONcSequence::name()
115 {
116  return _s->name();
117 }
118 
125 void FONcSequence::dump(ostream &strm) const
126 {
127  strm << BESIndent::LMarg << "FONcSequence::dump - (" << (void *) this << ")" << endl;
128  BESIndent::Indent();
129  strm << BESIndent::LMarg << "name = " << _s->name() << endl;
130  BESIndent::UnIndent();
131 }
132 
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
FONcSequence::~FONcSequence
virtual ~FONcSequence()
Destructor that cleans up the sequence.
Definition: FONcSequence.cc:59
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
FONcSequence::FONcSequence
FONcSequence(BaseType *b)
Constructor for FONcSequence that takes a DAP Sequence.
Definition: FONcSequence.cc:45
FONcSequence::define
virtual void define(int ncid)
define the DAP Sequence in the netcdf file
Definition: FONcSequence.cc:88
FONcSequence::convert
virtual void convert(vector< string > embed)
convert the Sequence to something that can be stored in a netcdf file
Definition: FONcSequence.cc:72
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
FONcBaseType
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:58
FONcSequence::dump
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcSequence.cc:125
FONcSequence::write
virtual void write(int ncid)
Write the sequence data out to the netcdf file.
Definition: FONcSequence.cc:110