Go to the documentation of this file.
101 out2 <<
" Reading " << efilename <<
'\n';
103 #pragma omp critical(netcdf__critical_region)
106 if (nc_open(efilename.c_str(), NC_NOWRITE, &ncid)) {
108 os <<
"Error reading file: " << efilename << endl;
109 throw runtime_error(os.str());
114 }
catch (
const std::runtime_error& e) {
116 os <<
"Error reading file: " << efilename << endl;
117 os << e.what() << endl;
118 throw runtime_error(os.str());
133 template <
typename T>
141 out2 <<
" Writing " << efilename <<
'\n';
143 #pragma omp critical(netcdf__critical_region)
146 if (nc_create(efilename.c_str(), NC_CLOBBER, &ncid)) {
148 os <<
"Error writing file: " << efilename << endl;
149 throw runtime_error(os.str());
154 }
catch (
const std::runtime_error& e) {
156 os <<
"Error writing file: " << efilename << endl;
157 os << e.what() << endl;
158 throw runtime_error(os.str());
179 if ((retval = nc_def_dim(ncid, name.c_str(),
nelem, ncdim)))
201 if ((retval = nc_def_var(ncid, name.c_str(), type, ndims, dims, varid)))
217 int ncdims[1], varid;
220 nca_def_var(ncid, name, NC_INT, 1, &ncdims[0], &varid);
237 int ncdims[1], varid;
240 nca_def_var(ncid, name, NC_DOUBLE, 1, &ncdims[0], &varid);
257 int ncdims[2], varid;
261 nca_def_var(ncid, name, NC_DOUBLE, 2, &ncdims[0], &varid);
278 int ncdims[4], varid;
284 nca_def_var(ncid, name, NC_DOUBLE, 4, &ncdims[0], &varid);
303 if ((retval = nc_inq_dimid(ncid, name.c_str(), &dimid))) {
305 nca_error(retval,
"nc_inq_ndims(" + name +
")");
309 if ((retval = nc_inq_dimlen(ncid, dimid, &ndim))) {
311 nca_error(retval,
"nc_inq_dimlen(" + name +
")");
329 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
330 nca_error(retval,
"nc_inq_varid(" + name +
")");
331 if ((retval = nc_get_var_int(ncid, varid,
data)))
332 nca_error(retval,
"nc_get_var(" + name +
")");
345 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
346 nca_error(retval,
"nc_inq_varid(" + name +
")");
347 if ((retval = nc_get_var_long(ncid, varid,
data)))
348 nca_error(retval,
"nc_get_var(" + name +
")");
361 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
362 nca_error(retval,
"nc_inq_varid(" + name +
")");
363 if ((retval = nc_get_var_double(ncid, varid,
data)))
364 nca_error(retval,
"nc_get_var(" + name +
")");
381 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
382 nca_error(retval,
"nc_inq_varid(" + name +
")");
383 if ((retval = nc_get_vara_double(ncid, varid, &
start, &count,
data)))
384 nca_error(retval,
"nc_get_var(" + name +
")");
397 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
398 nca_error(retval,
"nc_inq_varid(" + name +
")");
399 if ((retval = nc_get_var_text(ncid, varid,
data)))
400 nca_error(retval,
"nc_get_var(" + name +
")");
416 const bool noerror) {
423 for (ArrayOfIndex::iterator it = aoi.begin(); it != aoi.end(); it++, i++)
441 const bool noerror) {
444 aast.resize(species_count.
nelem());
445 if (species_count.
nelem()) {
446 Index species_strings_nelem =
447 nc_get_dim(ncid, name +
"_strings_nelem", noerror);
448 Index species_strings_length =
449 nc_get_dim(ncid, name +
"_strings_length", noerror);
450 char* species_strings =
451 new char[species_strings_nelem * species_strings_length];
452 if (species_count.
nelem())
456 for (
Index i = 0; i < species_count.
nelem(); i++) {
458 for (
Index j = 0; j < species_count[i]; j++) {
459 aast[i].push_back(
SpeciesTag(&species_strings[si]));
460 si += species_strings_length;
464 delete[] species_strings;
481 const bool noerror) {
500 const bool noerror) {
520 const bool noerror) {
545 for (
Index i = 0; i < a.
nelem(); i++) ind_arr[i] = a[i];
548 if ((retval = nc_put_var_long(ncid, varid, ind_arr)))
570 if ((retval = nc_put_var_double(ncid, varid, v.
get_c_array())))
589 if ((retval = nc_put_var_double(ncid, varid, m.
get_c_array())))
608 if ((retval = nc_put_var_double(ncid, varid, t.
get_c_array())))
624 os <<
"NetCDF error: " << s <<
", " << e;
625 throw runtime_error(os.str());
void nca_get_data_Matrix(const int ncid, const String &name, Matrix &m, const bool noerror)
Read variable of type Matrix from NetCDF file.
void resize(Index b, Index p, Index r, Index c)
Resize function.
The declarations of all the exception classes.
String out_basename
The basename for the report file and for all other output files.
void nca_get_data_double(const int ncid, const String &name, Numeric *data)
Read variable of type double from NetCDF file.
void nca_get_data_int(const int ncid, const String &name, int *data)
Read variable of type int from NetCDF file.
void nca_get_data_ArrayOfIndex(const int ncid, const String &name, ArrayOfIndex &aoi, const bool noerror)
Read variable of type ArrayOfIndex from NetCDF file.
Index nc_get_dim(const int ncid, const String &name, const bool noerror)
Read a dimension from NetCDF file.
This file contains basic functions to handle NetCDF data files.
Verbosity verbosity(Workspace &ws) noexcept
void nca_get_data_text(const int ncid, const String &name, char *data)
Read variable of type array of char from NetCDF file.
void nca_write_to_file(const String &filename, const T &type, const Verbosity &verbosity)
Writes a variable to a NetCDF file.
bool nca_put_var_Matrix(const int ncid, const int varid, const Matrix &m)
Write variable of type Matrix to NetCDF file.
void resize(Index n)
Resize function.
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Index nrows() const
Returns the number of rows.
void nca_get_data_Tensor4(const int ncid, const String &name, Tensor4 &t, const bool noerror)
Read variable of type Tensor4 from NetCDF file.
void nca_filename(String &filename, const String &varname)
Gives the default filename for the NetCDF formats.
This file contains private function declarations and template instantiation to handle NetCDF data fil...
void nca_filename_with_index(String &filename, const Index &file_index, const String &varname)
Gives the default filename, with file index, for the NetCDF formats.
void nca_get_dataa_double(const int ncid, const String &name, size_t start, size_t count, Numeric *data)
Read variable of type array of double from NetCDF file.
This can be used to make arrays out of anything.
A tag group can consist of the sum of several of these.
bool nca_put_var_ArrayOfIndex(const int ncid, const int varid, const ArrayOfIndex &a)
Write variable of type ArrayOfIndex to NetCDF file.
Index nelem(const Lines &l)
Number of lines.
int nca_def_Vector(const int ncid, const String &name, const Vector &v)
Define NetCDF dimensions and variable for a Vector.
Declarations having to do with the four output streams.
Index ncols() const
Returns the number of columns.
int nca_def_Tensor4(const int ncid, const String &name, const Tensor4 &t)
Define NetCDF dimensions and variable for a Tensor4.
bool nca_put_var_Tensor4(const int ncid, const int varid, const Tensor4 &t)
Write variable of type Tensor4 to NetCDF file.
Index nelem() const
Returns the number of elements.
Index ncols() const
Returns the number of columns.
NUMERIC Numeric
The type to use for all floating point numbers.
Index npages() const
Returns the number of pages.
void nca_get_data_long(const int ncid, const String &name, long *data)
Read variable of type long from NetCDF file.
void nca_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads a variable from a NetCDF file.
int nca_def_Matrix(const int ncid, const String &name, const Matrix &m)
Define NetCDF dimensions and variable for a Matrix.
Index nbooks() const
Returns the number of books.
int nca_def_ArrayOfIndex(const int ncid, const String &name, const ArrayOfIndex &a)
Define NetCDF dimensions and variable for an ArrayOfIndex.
Index npages(Workspace &ws) noexcept
void resize(Index r, Index c)
Resize function.
void nca_def_var(const int ncid, const String &name, const nc_type type, const int ndims, const int *dims, int *varid)
Define NetCDF variable.
Index nrows(Workspace &ws) noexcept
Index nrows() const
Returns the number of rows.
String expand_path(const String &path)
constexpr Rational start(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the lowest M for a polarization type of this transition.
String add_basedir(const String &path)
void nca_def_dim(const int ncid, const String &name, const Index nelem, int *ncdim)
Define NetCDF dimension.
This file contains basic functions to handle ASCII files.
Index file_index(Workspace &ws) noexcept
INDEX Index
The type to use for all integer numbers and indices.
void nca_get_data_Vector(const int ncid, const String &name, Vector &v, const bool noerror)
Read variable of type Vector from NetCDF file.
const Numeric * get_c_array() const
Conversion to plain C-array.
Index ncols(Workspace &ws) noexcept
void nca_error(const int e, const String s)
Throws a runtime error for the given NetCDF error code.
const Numeric * get_c_array() const
Conversion to plain C-array.
Index nelem() const
Number of elements.
Index nbooks(Workspace &ws) noexcept
const Numeric * get_c_array() const
Conversion to plain C-array, const-version.
The global header file for ARTS.
void nca_get_data_ArrayOfArrayOfSpeciesTag(const int ncid, const String &name, ArrayOfArrayOfSpeciesTag &aast, const bool noerror)
Read variable of type ArrayOfArrayOfSpeciesTag from NetCDF file.
bool nca_put_var_Vector(const int ncid, const int varid, const Vector &v)
Write variable of type Vector to NetCDF file.