36 using std::ostringstream;
37 using std::istringstream;
39 #include "FONcRequestHandler.h"
41 #include "FONcTransform.h"
42 #include "FONcUtils.h"
43 #include "FONcBaseType.h"
44 #include "FONcAttributes.h"
47 #include <Structure.h>
52 #include <BESInternalError.h>
54 #include "DapFunctionUtils.h"
71 string s = (string)
"File out netcdf, " +
"null DDS passed to constructor";
74 if (localfile.empty()) {
75 string s = (string)
"File out netcdf, " +
"empty local file name passed to constructor";
78 _localfile = localfile;
80 _returnAs = ncVersion;
105 vector<FONcBaseType *>::iterator i = _fonc_vars.begin();
106 vector<FONcBaseType *>::iterator e = _fonc_vars.end();
135 DDS::Vars_iter vi = _dds->var_begin();
136 DDS::Vars_iter ve = _dds->var_end();
137 for (; vi != ve; vi++) {
138 if ((*vi)->send_p()) {
141 BESDEBUG(
"fonc",
"FONcTransform::transform() - Converting variable '" << v->name() <<
"'" << endl);
146 _fonc_vars.push_back(fb);
148 vector<string> embed;
155 if ( FONcTransform::_returnAs == RETURNAS_NETCDF4 ) {
156 if (FONcRequestHandler::classic_model){
157 BESDEBUG(
"fonc",
"FONcTransform::transform() - Opening NetCDF-4 cache file in classic mode. fileName: " << _localfile << endl);
158 stax = nc_create(_localfile.c_str(), NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &_ncid);
161 BESDEBUG(
"fonc",
"FONcTransform::transform() - Opening NetCDF-4 cache file. fileName: " << _localfile << endl);
162 stax = nc_create(_localfile.c_str(), NC_CLOBBER|NC_NETCDF4, &_ncid);
166 BESDEBUG(
"fonc",
"FONcTransform::transform() - Opening NetCDF-3 cache file. fileName: " << _localfile << endl);
167 stax = nc_create(_localfile.c_str(), NC_CLOBBER, &_ncid);
170 if (stax != NC_NOERR) {
182 vector<FONcBaseType *>::iterator i = _fonc_vars.begin();
183 vector<FONcBaseType *>::iterator e = _fonc_vars.end();
184 for (; i != e; i++) {
186 BESDEBUG(
"fonc",
"FONcTransform::transform() - Defining variable: " << fbt->name() << endl);
191 AttrTable &globals = _dds->get_attr_table();
192 BESDEBUG(
"fonc",
"FONcTransform::transform() - Adding Global Attributes" << endl << globals << endl);
197 int stax = nc_enddef(_ncid);
201 if (stax != NC_NOERR) {
202 FONcUtils::handle_error(stax,
"File out netcdf, unable to end the define mode: " + _localfile, __FILE__, __LINE__);
206 i = _fonc_vars.begin();
207 e = _fonc_vars.end();
208 for (; i != e; i++) {
210 BESDEBUG(
"fonc",
"FONcTransform::transform() - Writing data for variable: " << fbt->name() << endl);
214 stax = nc_close(_ncid);
215 if (stax != NC_NOERR)
219 (void) nc_close(_ncid);
235 strm << BESIndent::LMarg <<
"FONcTransform::dump - (" << (
void *)
this <<
")" << endl;
237 strm << BESIndent::LMarg <<
"ncid = " << _ncid << endl;
238 strm << BESIndent::LMarg <<
"temporary file = " << _localfile << endl;
240 vector<FONcBaseType *>::const_iterator i = _fonc_vars.begin();
241 vector<FONcBaseType *>::const_iterator e = _fonc_vars.end();
242 for (; i != e; i++) {
246 BESIndent::UnIndent();
247 BESIndent::UnIndent();