54 filename_nc (
String& filename,
75 filename_nc_with_index (
77 const Index& file_index,
84 os <<
out_basename <<
"." << varname <<
"." << file_index <<
".nc";
90 os << filename <<
"." << file_index <<
".nc";
96 template<
typename T>
void
97 nc_read_from_file (
const String& filename,
105 out2 <<
" Reading " << efilename <<
'\n';
108 if (nc_open (efilename.c_str(), NC_NOWRITE, &ncid))
111 os <<
"Error reading file: " << efilename << endl;
112 throw runtime_error (os.str());
115 nc_read_from_file (ncid, type);
121 template<
typename T>
void
122 nc_write_to_file (
const String& filename,
130 out2 <<
" Writing " << efilename <<
'\n';
133 if (nc_create (efilename.c_str(), NC_CLOBBER, &ncid))
136 os <<
"Error writing file: " << efilename << endl;
137 throw runtime_error (os.str());
140 nc_write_to_file (ncid, type);
146 void nc_get_data_int (
const int ncid,
const String &name,
int *data)
149 if ((retval = nc_inq_varid (ncid, name.c_str(), &varid)))
150 ncerror (retval,
"nc_inq_varid("+name+
")");
151 if ((retval = nc_get_var_int (ncid, varid, data)))
152 ncerror (retval,
"nc_get_var("+name+
")");
156 void nc_get_data_long (
const int ncid,
const String &name,
long *data)
159 if ((retval = nc_inq_varid (ncid, name.c_str(), &varid)))
160 ncerror (retval,
"nc_inq_varid("+name+
")");
161 if ((retval = nc_get_var_long (ncid, varid, data)))
162 ncerror (retval,
"nc_get_var("+name+
")");
166 void nc_get_data_double (
const int ncid,
const String &name,
Numeric *data)
169 if ((retval = nc_inq_varid (ncid, name.c_str(), &varid)))
170 ncerror (retval,
"nc_inq_varid("+name+
")");
171 if ((retval = nc_get_var_double (ncid, varid, data)))
172 ncerror (retval,
"nc_get_var("+name+
")");
176 void nc_get_dataa_double (
const int ncid,
const String &name,
177 size_t start,
size_t count,
Numeric *data)
180 if ((retval = nc_inq_varid (ncid, name.c_str(), &varid)))
181 ncerror (retval,
"nc_inq_varid("+name+
")");
182 if ((retval = nc_get_vara_double (ncid, varid, &start, &count, data)))
183 ncerror (retval,
"nc_get_var("+name+
")");
187 Index nc_get_dim (
const int ncid,
const String &name)
191 if ((retval = nc_inq_dimid (ncid, name.c_str(), &dimid)))
192 ncerror (retval,
"nc_inq_ndims("+name+
")");
193 if ((retval = nc_inq_dimlen (ncid, dimid, &ndim)))
194 ncerror (retval,
"nc_inq_dimlen("+name+
")");
200 void ncerror (
const int e,
const String s)
203 os <<
"NetCDF error: " << s <<
", " << e;
204 throw runtime_error (os.str());