ARTS 2.5.11 (git: 6827797f)
|
This file contains basic functions to handle NetCDF data files. More...
#include "arts.h"
#include <netcdf.h>
#include "exceptions.h"
#include "messages.h"
#include "mystring.h"
#include "species_tags.h"
Go to the source code of this file.
Functions | |
void | nca_filename (String &filename, const String &varname) |
Gives the default filename for the NetCDF formats. | |
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. | |
template<typename T > | |
void | nca_read_from_file (const String &filename, T &type, const Verbosity &verbosity) |
Reads a variable from a NetCDF file. | |
template<typename T > | |
void | nca_write_to_file (const String &filename, const T &type, const Verbosity &verbosity) |
Writes a variable to a NetCDF file. | |
void | nca_def_dim (const int ncid, const String &name, const Index nelem, int *ncdim) |
Define NetCDF dimension. | |
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_ArrayOfIndex (const int ncid, const String &name, const ArrayOfIndex &a) |
Define NetCDF dimensions and variable for an ArrayOfIndex. | |
int | nca_def_Vector (const int ncid, const String &name, const Vector &v) |
Define NetCDF dimensions and variable for a Vector. | |
int | nca_def_Matrix (const int ncid, const String &name, const Matrix &m) |
Define NetCDF dimensions and variable for a Matrix. | |
int | nca_def_Tensor4 (const int ncid, const String &name, const Tensor4 &t) |
Define NetCDF dimensions and variable for a Tensor4. | |
Index | nca_get_dim (const int ncid, const String &name, const bool noerror=false) |
Read a dimension from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, int *data) |
Read variable of type int from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, long *data) |
Read variable of type long from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, long long *data) |
Read variable of type long long from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, Numeric *data) |
Read variable of type double from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, size_t start, size_t count, Numeric *data) |
Read variable of type array of double from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, char *data) |
Read variable of type array of char from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, ArrayOfIndex &aoi, const bool noerror) |
Read variable of type ArrayOfIndex from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, ArrayOfArrayOfSpeciesTag &aast, const bool noerror) |
Read variable of type ArrayOfArrayOfSpeciesTag from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, Vector &v, const bool noerror=false) |
Read variable of type Vector from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, Matrix &m, const bool noerror=false) |
Read variable of type Matrix from NetCDF file. | |
void | nca_get_data (const int ncid, const String &name, Tensor4 &m, const bool noerror=false) |
Read variable of type Tensor4 from NetCDF file. | |
void | nca_put_var (const int ncid, const int varid, const long *ind_arr) |
Write variable of type long* to NetCDF file. | |
void | nca_put_var (const int ncid, const int varid, const long long *ind_arr) |
Write variable of type long long* to NetCDF file. | |
bool | nca_put_var (const int ncid, const int varid, const ArrayOfIndex &a) |
Write variable of type ArrayOfIndex to NetCDF file. | |
bool | nca_put_var (const int ncid, const int varid, const Vector &v) |
Write variable of type Vector to NetCDF file. | |
bool | nca_put_var (const int ncid, const int varid, const Matrix &m) |
Write variable of type Matrix to NetCDF file. | |
bool | nca_put_var (const int ncid, const int varid, const Tensor4 &t) |
Write variable of type Tensor4 to NetCDF file. | |
void | nca_error (const int err, const std::string_view msg) |
Throws a runtime error for the given NetCDF error code. | |
This file contains basic functions to handle NetCDF data files.
Definition in file nc_io.h.
int nca_def_ArrayOfIndex | ( | const int | ncid, |
const String & | name, | ||
const ArrayOfIndex & | a | ||
) |
Define NetCDF dimensions and variable for an ArrayOfIndex.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | a | ArrayOfIndex |
Definition at line 190 of file nc_io.cc.
References a, nca_def_dim(), and nca_def_var().
void nca_def_dim | ( | const int | ncid, |
const String & | name, | ||
const Index | nelem, | ||
int * | ncdim | ||
) |
Define NetCDF dimension.
[in] | ncid | NetCDF file descriptor |
[in] | name | Dimension name |
[in] | nelem | Dimension size |
[out] | ncdim | NetCDF dimension handle |
Definition at line 156 of file nc_io.cc.
References nca_error().
Referenced by nca_def_ArrayOfIndex(), nca_def_Matrix(), nca_def_Tensor4(), and nca_def_Vector().
int nca_def_Matrix | ( | const int | ncid, |
const String & | name, | ||
const Matrix & | m | ||
) |
Define NetCDF dimensions and variable for a Matrix.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | m | Matrix |
Definition at line 233 of file nc_io.cc.
References nca_def_dim(), and nca_def_var().
int nca_def_Tensor4 | ( | const int | ncid, |
const String & | name, | ||
const Tensor4 & | t | ||
) |
Define NetCDF dimensions and variable for a Tensor4.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | t | Tensor4 |
Definition at line 255 of file nc_io.cc.
References nca_def_dim(), and nca_def_var().
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.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | type | NetCDF type |
[in] | ndims | Number of dimensions |
[in] | dims | Pointer to dimensions |
[out] | varid | NetCDF variable handle |
Definition at line 174 of file nc_io.cc.
References nca_error().
Referenced by nca_def_ArrayOfIndex(), nca_def_Matrix(), nca_def_Tensor4(), and nca_def_Vector().
int nca_def_Vector | ( | const int | ncid, |
const String & | name, | ||
const Vector & | v | ||
) |
Define NetCDF dimensions and variable for a Vector.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | v | Vector |
Definition at line 212 of file nc_io.cc.
References nca_def_dim(), nca_def_var(), and v.
void nca_error | ( | const int | e, |
const std::string_view | s | ||
) |
Throws a runtime error for the given NetCDF error code.
[in] | e | NetCDF error code |
[in] | s | Error message string |
Definition at line 626 of file nc_io.cc.
References ARTS_USER_ERROR.
Referenced by nca_def_dim(), nca_def_var(), nca_get_data(), nca_get_dim(), nca_put_var(), nca_write_to_file(), and WriteMolTau().
Gives the default filename for the NetCDF formats.
The default name is only used if the filename is empty.
filename | filename |
varname | variable name |
Definition at line 36 of file nc_io.cc.
References out_basename.
Referenced by WriteNetCDF().
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.
The default name is only used if the filename is empty.
[out] | filename | filename |
[in] | file_index | Index appended to the filename |
[in] | varname | variable name |
Definition at line 53 of file nc_io.cc.
References out_basename.
Referenced by WriteNetCDFIndexed().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
ArrayOfArrayOfSpeciesTag & | aast, | ||
const bool | noerror | ||
) |
Read variable of type ArrayOfArrayOfSpeciesTag from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | aast | Data read from file |
[in] | noerror | Return empty variable instead of throwing an exception if variable does not exist in file |
Definition at line 424 of file nc_io.cc.
References nca_get_data(), nca_get_dim(), and Array< base >::nelem().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
ArrayOfIndex & | aoi, | ||
const bool | noerror | ||
) |
Read variable of type ArrayOfIndex from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | aoi | Data read from file |
[in] | noerror | Return empty variable instead of throwing an exception if variable does not exist in file |
Definition at line 405 of file nc_io.cc.
References nca_get_data(), and nca_get_dim().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
char * | data | ||
) |
Read variable of type array of char from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | data | Data read from file |
Definition at line 387 of file nc_io.cc.
References nca_error().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
int * | data | ||
) |
Read variable of type int from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | data | Data read from file |
Definition at line 306 of file nc_io.cc.
References nca_error().
Referenced by nca_get_data(), and nca_read_from_file().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
long * | data | ||
) |
Read variable of type long from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | data | Data read from file |
Definition at line 322 of file nc_io.cc.
References nca_error().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
long long * | data | ||
) |
Read variable of type long long from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | data | Data read from file |
Definition at line 338 of file nc_io.cc.
References nca_error().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
Matrix & | m, | ||
const bool | noerror | ||
) |
Read variable of type Matrix from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | m | Data read from file |
[in] | noerror | Return empty variable instead of throwing an exception if variable does not exist in file |
Definition at line 480 of file nc_io.cc.
References nca_get_data(), and nca_get_dim().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
Numeric * | data | ||
) |
Read variable of type double from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | data | Data read from file |
Definition at line 354 of file nc_io.cc.
References nca_error().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
size_t | start, | ||
size_t | count, | ||
Numeric * | data | ||
) |
Read variable of type array of double from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | data | Data read from file |
Definition at line 370 of file nc_io.cc.
References nca_error().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
Tensor4 & | t, | ||
const bool | noerror | ||
) |
Read variable of type Tensor4 from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | t | Data read from file |
[in] | noerror | Return empty variable instead of throwing an exception if variable does not exist in file |
Definition at line 499 of file nc_io.cc.
References nca_get_data(), and nca_get_dim().
void nca_get_data | ( | const int | ncid, |
const String & | name, | ||
Vector & | v, | ||
const bool | noerror | ||
) |
Read variable of type Vector from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | v | Data read from file |
[in] | noerror | Return empty variable instead of throwing an exception if variable does not exist in file |
Definition at line 462 of file nc_io.cc.
References nca_get_data(), nca_get_dim(), and v.
Index nca_get_dim | ( | const int | ncid, |
const String & | name, | ||
const bool | noerror | ||
) |
Read a dimension from NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Dimension name in NetCDF file |
[in] | noerror | Return 0 instead of throwing an exception if dimension does not exist in file |
Definition at line 279 of file nc_io.cc.
References nca_error().
Referenced by nca_get_data(), and nca_read_from_file().
bool nca_put_var | ( | const int | ncid, |
const int | varid, | ||
const ArrayOfIndex & | a | ||
) |
Write variable of type ArrayOfIndex to NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | a | Data to be written |
Definition at line 549 of file nc_io.cc.
References a, and nca_put_var().
void nca_put_var | ( | const int | ncid, |
const int | varid, | ||
const long * | ind_arr | ||
) |
Write variable of type long* to NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | a | Data to be written |
Definition at line 519 of file nc_io.cc.
References nca_error().
Referenced by nca_put_var().
void nca_put_var | ( | const int | ncid, |
const int | varid, | ||
const long long * | ind_arr | ||
) |
Write variable of type long long* to NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | a | Data to be written |
Definition at line 534 of file nc_io.cc.
References nca_error().
bool nca_put_var | ( | const int | ncid, |
const int | varid, | ||
const Matrix & | m | ||
) |
Write variable of type Matrix to NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | m | Data to be written |
Definition at line 587 of file nc_io.cc.
References nca_error().
bool nca_put_var | ( | const int | ncid, |
const int | varid, | ||
const Tensor4 & | t | ||
) |
Write variable of type Tensor4 to NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | t | Data to be written |
Definition at line 607 of file nc_io.cc.
References nca_error().
bool nca_put_var | ( | const int | ncid, |
const int | varid, | ||
const Vector & | v | ||
) |
Write variable of type Vector to NetCDF file.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[in] | v | Data to be written |
Definition at line 567 of file nc_io.cc.
References nca_error(), and v.
void nca_read_from_file | ( | const String & | filename, |
T & | type, | ||
const Verbosity & | verbosity | ||
) |
Reads a variable from a NetCDF file.
[in] | filename | NetCDF filename |
[out] | type | Input variable |
[in] | verbosity | Verbosity |
Definition at line 76 of file nc_io.cc.
References ARTS_USER_ERROR, CREATE_OUT2, expand_path(), and nca_read_from_file().
Referenced by nca_read_from_file(), and ReadNetCDF().
void nca_write_to_file | ( | const String & | filename, |
const T & | type, | ||
const Verbosity & | verbosity | ||
) |
Writes a variable to a NetCDF file.
[in] | filename | NetCDF filename |
[in] | type | Output variable |
[in] | verbosity | Verbosity |
Definition at line 116 of file nc_io.cc.
References add_basedir(), ARTS_USER_ERROR, CREATE_OUT2, and nca_write_to_file().
Referenced by nca_write_to_file(), and WriteNetCDF().