33#include <libdap/Str.h>
35#include <BESInternalError.h>
41#include "FONcAttributes.h"
54 FONcBaseType(), _str(0), _dimid(0), _data(0)
56 _str =
dynamic_cast<Str *
>(b);
58 throw BESInternalError(
"File out netcdf, FONcStr was passed a variable that is not a DAP Str", __FILE__, __LINE__);
84 BESDEBUG(
"fonc",
"FONcStr::define - defining " << d_varname << endl);
94 if (d_is_dap4 || get_eval() ==
nullptr || get_dds() ==
nullptr)
97 _str->intern_data(*get_eval(), *get_dds());
100 _str->buf2val((
void**) &_data);
104 if(d_is_dap4_group ==
true) {
106 dim_suffix_strm <<
"_len"<<FONcDim::DimNameNum +1;
107 FONcDim::DimNameNum++;
108 dimname = d_varname + dim_suffix_strm.str();
111 dimname = d_varname +
"_len";
114 int stax = nc_def_dim(ncid, dimname.c_str(), _data->size() + 1, &_dimid);
115 if (stax != NC_NOERR) {
116 string err = (
string)
"fileout.netcdf - " +
"Failed to define dim " + dimname +
" for " + d_varname;
121 var_dims[0] = _dimid;
122 stax = nc_def_var(ncid, d_varname.c_str(), NC_CHAR, 1, var_dims, &d_varid);
123 if (stax != NC_NOERR) {
124 string err = (
string)
"fileout.netcdf - " +
"Failed to define var " + d_varname;
133 BESDEBUG(
"fonc",
"FONcStr::define - done defining " << d_varname << endl);
148 BESDEBUG(
"fonc",
"FONcStr::write for var " << d_varname << endl);
153 var_count[0] = _data->size() + 1;
155 int stax = nc_put_vara_text(ncid, d_varid, var_start, var_count, _data->c_str());
156 if (stax != NC_NOERR) {
157 string err = (
string)
"fileout.netcdf - " +
"Failed to write string data " + *_data +
" for " + d_varname;
165 BESDEBUG(
"fonc",
"FONcStr::done write for var " << d_varname << endl);
194 strm << BESIndent::LMarg <<
"FONcStr::dump - (" << (
void *)
this <<
")" << endl;
196 strm << BESIndent::LMarg <<
"name = " << _str->name() << endl;
197 BESIndent::UnIndent();
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.
virtual nc_type type()
returns the netcdf type of the DAP Str
virtual void define(int ncid)
Define the string variable in the netcdf file.
virtual ~FONcStr()
Destructor that cleans up the str.
virtual void write(int ncid)
Write the str out to the netcdf file.
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
virtual string name()
returns the name of the DAP Str
FONcStr(libdap::BaseType *b)
Constructor for FONcStr that takes a DAP Str.
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
static string gen_name(const vector< string > &embed, const string &name, string &original)
generate a new name for the embedded variable