58 os <<
out_basename <<
"." << varname <<
"." << file_index <<
".nc";
62 os << filename <<
"." << file_index <<
".nc";
82 out2 <<
" Reading " << efilename <<
'\n';
86#pragma omp critical(netcdf__critical_region)
89 if (nc_open(efilename.c_str(), NC_NOWRITE, &ncid)) {
91 fail_msg =
"Error opening file. Does it exists?";
95 }
catch (
const std::runtime_error &e) {
122 out2 <<
" Writing " << efilename <<
'\n';
126#pragma omp critical(netcdf__critical_region)
129 if (nc_create(efilename.c_str(), NC_CLOBBER | NC_NETCDF4, &ncid)) {
131 fail_msg =
"Error opening file for writing.";
135 }
catch (
const std::runtime_error &e) {
159 if ((retval = nc_def_dim(ncid, name.c_str(), nelem, ncdim)))
175 const int ndims,
const int *dims,
int *varid) {
177 if ((retval = nc_def_var(ncid, name.c_str(), type, ndims, dims, varid)))
192 std::array<int, 1> ncdims;
195 nca_def_dim(ncid, name +
"_nelem",
a.nelem(), &ncdims[0]);
196 nca_def_var(ncid, name, NC_INT, 1, &ncdims[0], &varid);
213 std::array<int, 1> ncdims;
216 nca_def_dim(ncid, name +
"_nelem",
v.nelem(), &ncdims[0]);
217 nca_def_var(ncid, name, NC_DOUBLE, 1, &ncdims[0], &varid);
234 std::array<int, 2> ncdims;
236 if (m.nrows() && m.ncols()) {
237 nca_def_dim(ncid, name +
"_nrows", m.nrows(), &ncdims[0]);
238 nca_def_dim(ncid, name +
"_ncols", m.ncols(), &ncdims[1]);
239 nca_def_var(ncid, name, NC_DOUBLE, 2, &ncdims[0], &varid);
256 std::array<int, 4> ncdims;
258 if (t.nbooks() && t.npages() && t.nrows() && t.ncols()) {
259 nca_def_dim(ncid, name +
"_nbooks", t.nbooks(), &ncdims[0]);
260 nca_def_dim(ncid, name +
"_npages", t.npages(), &ncdims[1]);
261 nca_def_dim(ncid, name +
"_nrows", t.nrows(), &ncdims[2]);
262 nca_def_dim(ncid, name +
"_ncols", t.ncols(), &ncdims[3]);
263 nca_def_var(ncid, name, NC_DOUBLE, 4, &ncdims[0], &varid);
282 if ((retval = nc_inq_dimid(ncid, name.c_str(), &dimid))) {
284 nca_error(retval,
"nc_inq_ndims(" + name +
")");
288 if ((retval = nc_inq_dimlen(ncid, dimid, &ndim))) {
290 nca_error(retval,
"nc_inq_dimlen(" + name +
")");
308 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
309 nca_error(retval,
"nc_inq_varid(" + name +
")");
310 if ((retval = nc_get_var_int(ncid, varid, data)))
311 nca_error(retval,
"nc_get_var(" + name +
")");
324 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
325 nca_error(retval,
"nc_inq_varid(" + name +
")");
326 if ((retval = nc_get_var_long(ncid, varid, data)))
327 nca_error(retval,
"nc_get_var(" + name +
")");
340 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
341 nca_error(retval,
"nc_inq_varid(" + name +
")");
342 if ((retval = nc_get_var_longlong(ncid, varid, data)))
343 nca_error(retval,
"nc_get_var(" + name +
")");
356 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
357 nca_error(retval,
"nc_inq_varid(" + name +
")");
358 if ((retval = nc_get_var_double(ncid, varid, data)))
359 nca_error(retval,
"nc_get_var(" + name +
")");
371 size_t count, Numeric *data) {
373 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
374 nca_error(retval,
"nc_inq_varid(" + name +
")");
375 if ((retval = nc_get_vara_double(ncid, varid, &start, &count, data)))
376 nca_error(retval,
"nc_get_var(" + name +
")");
389 if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
390 nca_error(retval,
"nc_inq_varid(" + name +
")");
391 if ((retval = nc_get_var_text(ncid, varid, data)))
392 nca_error(retval,
"nc_get_var(" + name +
")");
406 const bool noerror) {
407 Index nelem =
nca_get_dim(ncid, name +
"_nelem", noerror);
427 nca_get_data(ncid, name +
"_count", species_count, noerror);
428 aast.resize(species_count.
nelem());
429 if (species_count.
nelem()) {
430 Index species_strings_nelem =
431 nca_get_dim(ncid, name +
"_strings_nelem", noerror);
432 Index species_strings_length =
433 nca_get_dim(ncid, name +
"_strings_length", noerror);
434 char *species_strings =
435 new char[species_strings_nelem * species_strings_length];
436 if (species_count.
nelem())
440 for (Index i = 0; i < species_count.
nelem(); i++) {
442 for (Index j = 0; j < species_count[i]; j++) {
443 aast[i].push_back(
SpeciesTag(&species_strings[si]));
444 si += species_strings_length;
448 delete[] species_strings;
463 const bool noerror) {
464 Index nelem =
nca_get_dim(ncid, name +
"_nelem", noerror);
481 const bool noerror) {
482 Index nrows =
nca_get_dim(ncid, name +
"_nrows", noerror);
483 Index ncols =
nca_get_dim(ncid, name +
"_ncols", noerror);
484 m.resize(nrows, ncols);
500 const bool noerror) {
501 Index nbooks =
nca_get_dim(ncid, name +
"_nbooks", noerror);
502 Index npages =
nca_get_dim(ncid, name +
"_npages", noerror);
503 Index nrows =
nca_get_dim(ncid, name +
"_nrows", noerror);
504 Index ncols =
nca_get_dim(ncid, name +
"_ncols", noerror);
505 t.resize(nbooks, npages, nrows, ncols);
506 if (nbooks && npages && nrows && ncols)
519void nca_put_var(
const int ncid,
const int varid,
const long *ind_arr) {
521 if ((retval = nc_put_var_long(ncid, varid, ind_arr)))
534void nca_put_var(
const int ncid,
const int varid,
const long long *ind_arr) {
536 if ((retval = nc_put_var_longlong(ncid, varid, ind_arr)))
571 if ((retval = nc_put_var_double(ncid, varid,
v.unsafe_data_handle())))
587bool nca_put_var(
const int ncid,
const int varid,
const Matrix &m) {
589 if (m.nrows() && m.ncols()) {
591 if ((retval = nc_put_var_double(ncid, varid, m.unsafe_data_handle())))
607bool nca_put_var(
const int ncid,
const int varid,
const Tensor4 &t) {
609 if (t.nbooks() && t.npages() && t.nrows() && t.ncols()) {
611 if ((retval = nc_put_var_double(ncid, varid, t.unsafe_data_handle())))
627 ARTS_USER_ERROR(
"NetCDF error: ", s,
", ", e,
"\nCheck your input file.");
The global header file for ARTS.
Index nelem() const ARTS_NOEXCEPT
#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.
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...