ARTS
2.3.1285(git:92a29ea9-dirty)
|
This file contains basic functions to handle NetCDF data files. More...
#include "arts.h"
#include <netcdf.h>
#include "abs_species_tags.h"
#include "exceptions.h"
#include "messages.h"
#include "mystring.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. More... | |
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. More... | |
template<typename T > | |
void | nca_read_from_file (const String &filename, T &type, const Verbosity &verbosity) |
Reads a variable from a NetCDF file. More... | |
template<typename T > | |
void | nca_write_to_file (const String &filename, const T &type, const Verbosity &verbosity) |
Writes a variable to a NetCDF file. More... | |
void | nca_def_dim (const int ncid, const String &name, const Index nelem, int *ncdim) |
Define NetCDF dimension. More... | |
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. More... | |
int | nca_def_ArrayOfIndex (const int ncid, const String &name, const ArrayOfIndex &a) |
Define NetCDF dimensions and variable for an ArrayOfIndex. More... | |
int | nca_def_Vector (const int ncid, const String &name, const Vector &v) |
Define NetCDF dimensions and variable for a Vector. More... | |
int | nca_def_Matrix (const int ncid, const String &name, const Matrix &m) |
Define NetCDF dimensions and variable for a Matrix. More... | |
int | nca_def_Tensor4 (const int ncid, const String &name, const Tensor4 &t) |
Define NetCDF dimensions and variable for a Tensor4. More... | |
Index | nc_get_dim (const int ncid, const String &name, const bool noerror=false) |
Read a dimension from NetCDF file. More... | |
void | nca_get_data_int (const int ncid, const String &name, int *data) |
Read variable of type int from NetCDF file. More... | |
void | nca_get_data_long (const int ncid, const String &name, long *data) |
Read variable of type long from NetCDF file. More... | |
void | nca_get_data_double (const int ncid, const String &name, Numeric *data) |
Read variable of type double from NetCDF file. More... | |
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. More... | |
void | nca_get_data_text (const int ncid, const String &name, char *data) |
Read variable of type array of char from NetCDF file. More... | |
void | nca_get_data_ArrayOfIndex (const int ncid, const String &name, ArrayOfIndex &aoi, const bool noerror) |
Read variable of type ArrayOfIndex from NetCDF file. More... | |
void | nca_get_data_ArrayOfArrayOfSpeciesTag (const int ncid, const String &name, ArrayOfArrayOfSpeciesTag &aast, const bool noerror) |
Read variable of type ArrayOfArrayOfSpeciesTag from NetCDF file. More... | |
void | nca_get_data_Vector (const int ncid, const String &name, Vector &v, const bool noerror=false) |
Read variable of type Vector from NetCDF file. More... | |
void | nca_get_data_Matrix (const int ncid, const String &name, Matrix &m, const bool noerror=false) |
Read variable of type Matrix from NetCDF file. More... | |
void | nca_get_data_Tensor4 (const int ncid, const String &name, Tensor4 &m, const bool noerror=false) |
Read variable of type Tensor4 from NetCDF file. More... | |
bool | nca_put_var_ArrayOfIndex (const int ncid, const int varid, const ArrayOfIndex &a) |
Write variable of type ArrayOfIndex to NetCDF file. More... | |
bool | nca_put_var_Vector (const int ncid, const int varid, const Vector &v) |
Write variable of type Vector to NetCDF file. More... | |
bool | nca_put_var_Matrix (const int ncid, const int varid, const Matrix &m) |
Write variable of type Matrix to NetCDF file. More... | |
bool | nca_put_var_Tensor4 (const int ncid, const int varid, const Tensor4 &t) |
Write variable of type Tensor4 to NetCDF file. More... | |
void | nca_error (const int err, const String msg) |
Throws a runtime error for the given NetCDF error code. More... | |
This file contains basic functions to handle NetCDF data files.
Definition in file nc_io.h.
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 300 of file nc_io.cc.
References nca_error().
Referenced by nca_get_data_ArrayOfArrayOfSpeciesTag(), nca_get_data_ArrayOfIndex(), nca_get_data_Matrix(), nca_get_data_Tensor4(), nca_get_data_Vector(), and nca_read_from_file().
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 214 of file nc_io.cc.
References nca_def_dim(), nca_def_var(), and Array< base >::nelem().
Referenced by nca_write_to_file().
Define NetCDF dimension.
[in] | ncid | NetCDF file descriptor |
[in] | name | Dimension name |
[in] | nelem | Dimension size |
[out] | ncdim | NetCDF dimension handle |
Definition at line 174 of file nc_io.cc.
References nca_error(), and Absorption::nelem().
Referenced by nca_def_ArrayOfIndex(), nca_def_Matrix(), nca_def_Tensor4(), nca_def_Vector(), and nca_write_to_file().
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 256 of file nc_io.cc.
References nca_def_dim(), nca_def_var(), ConstMatrixView::ncols(), and ConstMatrixView::nrows().
Referenced by nca_write_to_file().
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 277 of file nc_io.cc.
References ConstTensor4View::nbooks(), nca_def_dim(), nca_def_var(), ConstTensor4View::ncols(), ConstTensor4View::npages(), and ConstTensor4View::nrows().
Referenced by nca_write_to_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.
[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 194 of file nc_io.cc.
References nca_error().
Referenced by nca_def_ArrayOfIndex(), nca_def_Matrix(), nca_def_Tensor4(), nca_def_Vector(), and nca_write_to_file().
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 236 of file nc_io.cc.
References nca_def_dim(), nca_def_var(), and ConstVectorView::nelem().
Referenced by nca_write_to_file().
void nca_error | ( | const int | e, |
const String | s | ||
) |
Throws a runtime error for the given NetCDF error code.
[in] | e | NetCDF error code |
[in] | s | Error message string |
Definition at line 622 of file nc_io.cc.
Referenced by nc_get_dim(), nca_def_dim(), nca_def_var(), nca_get_data_double(), nca_get_data_int(), nca_get_data_long(), nca_get_data_text(), nca_get_dataa_double(), nca_put_var_ArrayOfIndex(), nca_put_var_Matrix(), nca_put_var_Tensor4(), nca_put_var_Vector(), 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 53 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 70 of file nc_io.cc.
References out_basename, and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().
Referenced by WriteNetCDFIndexed().
void nca_get_data_ArrayOfArrayOfSpeciesTag | ( | 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 438 of file nc_io.cc.
References i, nc_get_dim(), nca_get_data_ArrayOfIndex(), nca_get_data_text(), and Array< base >::nelem().
Referenced by nca_read_from_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.
[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 413 of file nc_io.cc.
References i, nc_get_dim(), nca_get_data_long(), and Absorption::nelem().
Referenced by nca_get_data_ArrayOfArrayOfSpeciesTag(), and nca_read_from_file().
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 359 of file nc_io.cc.
References nca_error().
Referenced by nca_get_data_Matrix(), nca_get_data_Tensor4(), nca_get_data_Vector(), and nca_read_from_file().
void nca_get_data_int | ( | 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 327 of file nc_io.cc.
References nca_error().
void nca_get_data_long | ( | 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 343 of file nc_io.cc.
References nca_error().
Referenced by nca_get_data_ArrayOfIndex(), and nca_read_from_file().
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 497 of file nc_io.cc.
References MatrixView::get_c_array(), nc_get_dim(), nca_get_data_double(), and Matrix::resize().
Referenced by nca_read_from_file().
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 517 of file nc_io.cc.
References Tensor4View::get_c_array(), nc_get_dim(), nca_get_data_double(), and Tensor4::resize().
Referenced by nca_read_from_file().
void nca_get_data_text | ( | 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 395 of file nc_io.cc.
References nca_error().
Referenced by nca_get_data_ArrayOfArrayOfSpeciesTag().
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 478 of file nc_io.cc.
References VectorView::get_c_array(), nc_get_dim(), nca_get_data_double(), Absorption::nelem(), and Vector::resize().
Referenced by nca_read_from_file().
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.
[in] | ncid | NetCDF file descriptor |
[in] | name | Variable name in NetCDF file |
[out] | data | Data read from file |
Definition at line 375 of file nc_io.cc.
References nca_error().
Referenced by nca_read_from_file().
bool nca_put_var_ArrayOfIndex | ( | 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 539 of file nc_io.cc.
References i, nca_error(), and Array< base >::nelem().
Referenced by nca_write_to_file().
bool nca_put_var_Matrix | ( | 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 585 of file nc_io.cc.
References MatrixView::get_c_array(), nca_error(), ConstMatrixView::ncols(), and ConstMatrixView::nrows().
Referenced by nca_write_to_file().
bool nca_put_var_Tensor4 | ( | 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 604 of file nc_io.cc.
References Tensor4View::get_c_array(), ConstTensor4View::nbooks(), nca_error(), ConstTensor4View::ncols(), ConstTensor4View::npages(), and ConstTensor4View::nrows().
Referenced by nca_write_to_file().
bool nca_put_var_Vector | ( | 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 566 of file nc_io.cc.
References VectorView::get_c_array(), nca_error(), and ConstVectorView::nelem().
Referenced by nca_write_to_file().
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 94 of file nc_io.cc.
References CREATE_OUT2, expand_path(), nca_read_from_file(), and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().
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 134 of file nc_io.cc.
References add_basedir(), CREATE_OUT2, nca_write_to_file(), and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().
Referenced by nca_write_to_file(), and WriteNetCDF().