75 os <<
out_basename <<
"." << varname <<
"." << file_index <<
".nc";
79 os << filename <<
"." << file_index <<
".nc";
99 out2 <<
" Reading " << efilename <<
'\n';
103#pragma omp critical(netcdf__critical_region)
106 if (nc_open(efilename.c_str(), NC_NOWRITE, &ncid)) {
108 fail_msg =
"Error opening file. Does it exists?";
112 }
catch (
const std::runtime_error &e) {
139 out2 <<
" Writing " << efilename <<
'\n';
143#pragma omp critical(netcdf__critical_region)
146 if (nc_create(efilename.c_str(), NC_CLOBBER | NC_NETCDF4, &ncid)) {
148 fail_msg =
"Error opening file for writing.";
152 }
catch (
const std::runtime_error &e) {
176 if ((retval = nc_def_dim(ncid, name.c_str(), nelem, ncdim)))
192 const int ndims,
const int *dims,
int *varid) {
194 if ((retval = nc_def_var(ncid, name.c_str(), type, ndims, dims, varid)))
209 std::array<int, 1> ncdims;
212 nca_def_dim(ncid, name +
"_nelem",
a.nelem(), &ncdims[0]);
213 nca_def_var(ncid, name, NC_INT, 1, &ncdims[0], &varid);
230 std::array<int, 1> ncdims;
233 nca_def_dim(ncid, name +
"_nelem",
v.nelem(), &ncdims[0]);
234 nca_def_var(ncid, name, NC_DOUBLE, 1, &ncdims[0], &varid);
251 std::array<int, 2> ncdims;
256 nca_def_var(ncid, name, NC_DOUBLE, 2, &ncdims[0], &varid);
273 std::array<int, 4> ncdims;
280 nca_def_var(ncid, name, NC_DOUBLE, 4, &ncdims[0], &varid);
299 if ((retval = nc_inq_dimid(ncid, name.c_str(), &dimid))) {
301 nca_error(retval,
"nc_inq_ndims(" + name +
")");
305 if ((retval = nc_inq_dimlen(ncid, dimid, &ndim))) {
307 nca_error(retval,
"nc_inq_dimlen(" + name +
")");
325 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
326 nca_error(retval,
"nc_inq_varid(" + name +
")");
327 if ((retval = nc_get_var_int(ncid, varid, data)))
328 nca_error(retval,
"nc_get_var(" + name +
")");
341 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
342 nca_error(retval,
"nc_inq_varid(" + name +
")");
343 if ((retval = nc_get_var_long(ncid, varid, data)))
344 nca_error(retval,
"nc_get_var(" + name +
")");
357 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
358 nca_error(retval,
"nc_inq_varid(" + name +
")");
359 if ((retval = nc_get_var_longlong(ncid, varid, data)))
360 nca_error(retval,
"nc_get_var(" + name +
")");
373 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
374 nca_error(retval,
"nc_inq_varid(" + name +
")");
375 if ((retval = nc_get_var_double(ncid, varid, data)))
376 nca_error(retval,
"nc_get_var(" + name +
")");
390 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
391 nca_error(retval,
"nc_inq_varid(" + name +
")");
392 if ((retval = nc_get_vara_double(ncid, varid, &start, &count, data)))
393 nca_error(retval,
"nc_get_var(" + name +
")");
406 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
407 nca_error(retval,
"nc_inq_varid(" + name +
")");
408 if ((retval = nc_get_var_text(ncid, varid, data)))
409 nca_error(retval,
"nc_get_var(" + name +
")");
423 const bool noerror) {
444 nca_get_data(ncid, name +
"_count", species_count, noerror);
445 aast.resize(species_count.
nelem());
446 if (species_count.
nelem()) {
447 Index species_strings_nelem =
448 nca_get_dim(ncid, name +
"_strings_nelem", noerror);
449 Index species_strings_length =
450 nca_get_dim(ncid, name +
"_strings_length", noerror);
451 char *species_strings =
452 new char[species_strings_nelem * species_strings_length];
453 if (species_count.
nelem())
457 for (
Index i = 0; i < species_count.
nelem(); i++) {
459 for (
Index j = 0; j < species_count[i]; j++) {
460 aast[i].push_back(
SpeciesTag(&species_strings[si]));
461 si += species_strings_length;
465 delete[] species_strings;
480 const bool noerror) {
498 const bool noerror) {
517 const bool noerror) {
522 t.
resize(nbooks, npages, nrows, ncols);
523 if (nbooks && npages && nrows && ncols)
536void nca_put_var(
const int ncid,
const int varid,
const long *ind_arr) {
538 if ((retval = nc_put_var_long(ncid, varid, ind_arr)))
551void nca_put_var(
const int ncid,
const int varid,
const long long *ind_arr) {
553 if ((retval = nc_put_var_longlong(ncid, varid, ind_arr)))
588 if ((retval = nc_put_var_double(ncid, varid,
v.get_c_array())))
608 if ((retval = nc_put_var_double(ncid, varid, m.
get_c_array())))
628 if ((retval = nc_put_var_double(ncid, varid, t.
get_c_array())))
644 ARTS_USER_ERROR(
"NetCDF error: ", s,
", ", e,
"\nCheck your input file.");
The global header file for ARTS.
Index nelem() const ARTS_NOEXCEPT
Numeric * get_c_array() const noexcept
Index nrows() const noexcept
Index ncols() const noexcept
Index ncols() const noexcept
Index nrows() const noexcept
Index nbooks() const noexcept
Index npages() const noexcept
void resize(Index r, Index c)
Resize function.
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
void resize(Index b, Index p, Index r, Index c)
Resize function.
#define ARTS_USER_ERROR(...)
The declarations of all the exception classes.
String add_basedir(const std::string_view path)
String expand_path(String path)
This file contains basic functions to handle ASCII files.
NUMERIC Numeric
The type to use for all floating point numbers.
INDEX Index
The type to use for all integer numbers and indices.
String out_basename
The basename for the report file and for all other output files.
Declarations having to do with the four output streams.
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.
int nca_def_Tensor4(const int ncid, const String &name, const Tensor4 &t)
Define NetCDF dimensions and variable for a Tensor4.
int nca_def_ArrayOfIndex(const int ncid, const String &name, const ArrayOfIndex &a)
Define NetCDF dimensions and variable for an ArrayOfIndex.
void nca_filename(String &filename, const String &varname)
Gives the default filename for the NetCDF formats.
int nca_def_Vector(const int ncid, const String &name, const Vector &v)
Define NetCDF dimensions and variable for a Vector.
Index nca_get_dim(const int ncid, const String &name, const bool noerror)
Read a dimension from NetCDF file.
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.
int nca_def_Matrix(const int ncid, const String &name, const Matrix &m)
Define NetCDF dimensions and variable for a Matrix.
void nca_error(const int e, const std::string_view s)
Throws a runtime error for the given NetCDF error code.
void nca_def_dim(const int ncid, const String &name, const Index nelem, int *ncdim)
Define NetCDF dimension.
void nca_put_var(const int ncid, const int varid, const long *ind_arr)
Write variable of type long* to NetCDF file.
void nca_get_data(const int ncid, const String &name, int *data)
Read variable of type int from NetCDF file.
void nca_write_to_file(const String &filename, const T &type, const Verbosity &verbosity)
Writes a variable to a NetCDF file.
void nca_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads a variable from a NetCDF file.
This file contains basic functions to handle NetCDF data files.
This file contains private function declarations and template instantiation to handle NetCDF data fil...