ARTS 2.5.9 (git: 825fa5f2)
nc_io.cc File Reference

This file contains basic functions to handle NetCDF data files. More...

#include "arts.h"
#include "exceptions.h"
#include "file.h"
#include "messages.h"
#include "nc_io.h"
#include "nc_io_types.h"
#include "nc_io_instantiation.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 nca_get_dim (const int ncid, const String &name, const bool noerror)
 Read a dimension from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, int *data)
 Read variable of type int from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, long *data)
 Read variable of type long from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, long long *data)
 Read variable of type long long from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, Numeric *data)
 Read variable of type double from NetCDF file. More...
 
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. More...
 
void nca_get_data (const int ncid, const String &name, char *data)
 Read variable of type array of char from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, ArrayOfIndex &aoi, const bool noerror)
 Read variable of type ArrayOfIndex from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, ArrayOfArrayOfSpeciesTag &aast, const bool noerror)
 Read variable of type ArrayOfArrayOfSpeciesTag from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, Vector &v, const bool noerror)
 Read variable of type Vector from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, Matrix &m, const bool noerror)
 Read variable of type Matrix from NetCDF file. More...
 
void nca_get_data (const int ncid, const String &name, Tensor4 &t, const bool noerror)
 Read variable of type Tensor4 from NetCDF file. More...
 
void nca_put_var (const int ncid, const int varid, const long *ind_arr)
 Write variable of type long* to NetCDF file. More...
 
void nca_put_var (const int ncid, const int varid, const long long *ind_arr)
 Write variable of type long long* to NetCDF file. More...
 
bool nca_put_var (const int ncid, const int varid, const ArrayOfIndex &a)
 Write variable of type ArrayOfIndex to NetCDF file. More...
 
bool nca_put_var (const int ncid, const int varid, const Vector &v)
 Write variable of type Vector to NetCDF file. More...
 
bool nca_put_var (const int ncid, const int varid, const Matrix &m)
 Write variable of type Matrix to NetCDF file. More...
 
bool nca_put_var (const int ncid, const int varid, const Tensor4 &t)
 Write variable of type Tensor4 to NetCDF file. More...
 
void nca_error (const int e, const std::string_view s)
 Throws a runtime error for the given NetCDF error code. More...
 

Detailed Description

This file contains basic functions to handle NetCDF data files.

Author
Oliver Lemke olemk.nosp@m.e@co.nosp@m.re-du.nosp@m.mp.i.nosp@m.nfo
Date
2008-09-12

Definition in file nc_io.cc.

Function Documentation

◆ nca_def_ArrayOfIndex()

int nca_def_ArrayOfIndex ( const int  ncid,
const String name,
const ArrayOfIndex a 
)

Define NetCDF dimensions and variable for an ArrayOfIndex.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]aArrayOfIndex
Returns
Variable handle
Author
Oliver Lemke

Definition at line 207 of file nc_io.cc.

References a, nca_def_dim(), and nca_def_var().

◆ nca_def_dim()

void nca_def_dim ( const int  ncid,
const String name,
const Index  nelem,
int *  ncdim 
)

Define NetCDF dimension.

Parameters
[in]ncidNetCDF file descriptor
[in]nameDimension name
[in]nelemDimension size
[out]ncdimNetCDF dimension handle
Author
Oliver Lemke

Definition at line 173 of file nc_io.cc.

References nca_error().

Referenced by nca_def_ArrayOfIndex(), nca_def_Matrix(), nca_def_Tensor4(), and nca_def_Vector().

◆ nca_def_Matrix()

int nca_def_Matrix ( const int  ncid,
const String name,
const Matrix m 
)

Define NetCDF dimensions and variable for a Matrix.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]mMatrix
Returns
Variable handle
Author
Oliver Lemke

Definition at line 250 of file nc_io.cc.

References nca_def_dim(), nca_def_var(), ConstMatrixView::ncols(), and ConstMatrixView::nrows().

◆ nca_def_Tensor4()

int nca_def_Tensor4 ( const int  ncid,
const String name,
const Tensor4 t 
)

Define NetCDF dimensions and variable for a Tensor4.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]tTensor4
Returns
Variable handle
Author
Oliver Lemke

Definition at line 272 of file nc_io.cc.

References ConstTensor4View::nbooks(), nca_def_dim(), nca_def_var(), ConstTensor4View::ncols(), ConstTensor4View::npages(), and ConstTensor4View::nrows().

◆ 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.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]typeNetCDF type
[in]ndimsNumber of dimensions
[in]dimsPointer to dimensions
[out]varidNetCDF variable handle
Author
Oliver Lemke

Definition at line 191 of file nc_io.cc.

References nca_error().

Referenced by nca_def_ArrayOfIndex(), nca_def_Matrix(), nca_def_Tensor4(), and nca_def_Vector().

◆ nca_def_Vector()

int nca_def_Vector ( const int  ncid,
const String name,
const Vector v 
)

Define NetCDF dimensions and variable for a Vector.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]vVector
Returns
Variable handle
Author
Oliver Lemke

Definition at line 229 of file nc_io.cc.

References nca_def_dim(), nca_def_var(), and v.

◆ nca_error()

void nca_error ( const int  e,
const std::string_view  s 
)

Throws a runtime error for the given NetCDF error code.

Parameters
[in]eNetCDF error code
[in]sError message string
Author
Oliver Lemke

Definition at line 643 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().

◆ nca_filename()

void nca_filename ( String filename,
const String varname 
)

Gives the default filename for the NetCDF formats.

The default name is only used if the filename is empty.

Parameters
filenamefilename
varnamevariable name
Author
Oliver Lemke

Definition at line 53 of file nc_io.cc.

References out_basename.

Referenced by WriteNetCDF().

◆ nca_filename_with_index()

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.

Parameters
[out]filenamefilename
[in]file_indexIndex appended to the filename
[in]varnamevariable name
Author
Oliver Lemke

Definition at line 70 of file nc_io.cc.

References out_basename.

Referenced by WriteNetCDFIndexed().

◆ nca_get_data() [1/11]

void nca_get_data ( const int  ncid,
const String name,
ArrayOfArrayOfSpeciesTag aast,
const bool  noerror 
)

Read variable of type ArrayOfArrayOfSpeciesTag from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]aastData read from file
[in]noerrorReturn empty variable instead of throwing an exception if variable does not exist in file
Author
Oliver Lemke

Definition at line 441 of file nc_io.cc.

References nca_get_data(), nca_get_dim(), and Array< base >::nelem().

◆ nca_get_data() [2/11]

void nca_get_data ( const int  ncid,
const String name,
ArrayOfIndex aoi,
const bool  noerror 
)

Read variable of type ArrayOfIndex from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]aoiData read from file
[in]noerrorReturn empty variable instead of throwing an exception if variable does not exist in file
Author
Oliver Lemke

Definition at line 422 of file nc_io.cc.

References nca_get_data(), and nca_get_dim().

◆ nca_get_data() [3/11]

void nca_get_data ( const int  ncid,
const String name,
char *  data 
)

Read variable of type array of char from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]dataData read from file
Author
Oliver Lemke

Definition at line 404 of file nc_io.cc.

References nca_error().

◆ nca_get_data() [4/11]

void nca_get_data ( const int  ncid,
const String name,
int *  data 
)

Read variable of type int from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]dataData read from file
Author
Oliver Lemke

Definition at line 323 of file nc_io.cc.

References nca_error().

Referenced by nca_get_data(), and nca_read_from_file().

◆ nca_get_data() [5/11]

void nca_get_data ( const int  ncid,
const String name,
long *  data 
)

Read variable of type long from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]dataData read from file
Author
Oliver Lemke

Definition at line 339 of file nc_io.cc.

References nca_error().

◆ nca_get_data() [6/11]

void nca_get_data ( const int  ncid,
const String name,
long long *  data 
)

Read variable of type long long from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]dataData read from file
Author
Oliver Lemke

Definition at line 355 of file nc_io.cc.

References nca_error().

◆ nca_get_data() [7/11]

void nca_get_data ( const int  ncid,
const String name,
Matrix m,
const bool  noerror 
)

Read variable of type Matrix from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]mData read from file
[in]noerrorReturn empty variable instead of throwing an exception if variable does not exist in file
Author
Oliver Lemke

Definition at line 497 of file nc_io.cc.

References ConstMatrixView::get_c_array(), nca_get_data(), nca_get_dim(), and Matrix::resize().

◆ nca_get_data() [8/11]

void nca_get_data ( const int  ncid,
const String name,
Numeric data 
)

Read variable of type double from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]dataData read from file
Author
Oliver Lemke

Definition at line 371 of file nc_io.cc.

References nca_error().

◆ nca_get_data() [9/11]

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.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]dataData read from file
Author
Oliver Lemke

Definition at line 387 of file nc_io.cc.

References nca_error().

◆ nca_get_data() [10/11]

void nca_get_data ( const int  ncid,
const String name,
Tensor4 t,
const bool  noerror 
)

Read variable of type Tensor4 from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]tData read from file
[in]noerrorReturn empty variable instead of throwing an exception if variable does not exist in file
Author
Oliver Lemke

Definition at line 516 of file nc_io.cc.

References Tensor4View::get_c_array(), nca_get_data(), nca_get_dim(), and Tensor4::resize().

◆ nca_get_data() [11/11]

void nca_get_data ( const int  ncid,
const String name,
Vector v,
const bool  noerror 
)

Read variable of type Vector from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[out]vData read from file
[in]noerrorReturn empty variable instead of throwing an exception if variable does not exist in file
Author
Oliver Lemke

Definition at line 479 of file nc_io.cc.

References nca_get_data(), nca_get_dim(), and v.

◆ nca_get_dim()

Index nca_get_dim ( const int  ncid,
const String name,
const bool  noerror 
)

Read a dimension from NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameDimension name in NetCDF file
[in]noerrorReturn 0 instead of throwing an exception if dimension does not exist in file
Returns
Dimension size
Author
Oliver Lemke

Definition at line 296 of file nc_io.cc.

References nca_error().

Referenced by nca_get_data(), and nca_read_from_file().

◆ nca_put_var() [1/6]

bool nca_put_var ( const int  ncid,
const int  varid,
const ArrayOfIndex a 
)

Write variable of type ArrayOfIndex to NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]aData to be written
Returns
True if variable was not empty
Author
Oliver Lemke

Definition at line 566 of file nc_io.cc.

References a, and nca_put_var().

◆ nca_put_var() [2/6]

void nca_put_var ( const int  ncid,
const int  varid,
const long *  ind_arr 
)

Write variable of type long* to NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]aData to be written
Returns
True if variable was not empty
Author
Oliver Lemke

Definition at line 536 of file nc_io.cc.

References nca_error().

Referenced by nca_put_var().

◆ nca_put_var() [3/6]

void nca_put_var ( const int  ncid,
const int  varid,
const long long *  ind_arr 
)

Write variable of type long long* to NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]aData to be written
Returns
True if variable was not empty
Author
Oliver Lemke

Definition at line 551 of file nc_io.cc.

References nca_error().

◆ nca_put_var() [4/6]

bool nca_put_var ( const int  ncid,
const int  varid,
const Matrix m 
)

Write variable of type Matrix to NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]mData to be written
Returns
True if variable was not empty
Author
Oliver Lemke

Definition at line 604 of file nc_io.cc.

References ConstMatrixView::get_c_array(), nca_error(), ConstMatrixView::ncols(), and ConstMatrixView::nrows().

◆ nca_put_var() [5/6]

bool nca_put_var ( const int  ncid,
const int  varid,
const Tensor4 t 
)

Write variable of type Tensor4 to NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]tData to be written
Returns
True if variable was not empty
Author
Oliver Lemke

Definition at line 624 of file nc_io.cc.

References Tensor4View::get_c_array(), ConstTensor4View::nbooks(), nca_error(), ConstTensor4View::ncols(), ConstTensor4View::npages(), and ConstTensor4View::nrows().

◆ nca_put_var() [6/6]

bool nca_put_var ( const int  ncid,
const int  varid,
const Vector v 
)

Write variable of type Vector to NetCDF file.

Parameters
[in]ncidNetCDF file descriptor
[in]nameVariable name in NetCDF file
[in]vData to be written
Returns
True if variable was not empty
Author
Oliver Lemke

Definition at line 584 of file nc_io.cc.

References nca_error(), and v.

◆ nca_read_from_file()

template<typename T >
void nca_read_from_file ( const String filename,
T &  type,
const Verbosity verbosity 
)

Reads a variable from a NetCDF file.

Parameters
[in]filenameNetCDF filename
[out]typeInput variable
[in]verbosityVerbosity
Author
Oliver Lemke

Definition at line 93 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().

◆ nca_write_to_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.

Parameters
[in]filenameNetCDF filename
[in]typeOutput variable
[in]verbosityVerbosity
Author
Oliver Lemke

Definition at line 133 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().