ARTS  2.2.66
nc_io.h File Reference

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

#include "arts.h"
#include <netcdf.h>
#include "mystring.h"
#include "exceptions.h"
#include "messages.h"
#include "abs_species_tags.h"
Include dependency graph for nc_io.h:
This graph shows which files directly or indirectly include this file:

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

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

Function Documentation

◆ nc_get_dim()

Index nc_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 334 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().

◆ 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 234 of file nc_io.cc.

References nca_def_dim(), nca_def_var(), and Array< base >::nelem().

Referenced by nca_write_to_file().

◆ 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 197 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().

◆ 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 282 of file nc_io.cc.

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

Referenced by nca_write_to_file().

◆ 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 307 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().

◆ 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 216 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().

◆ 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 258 of file nc_io.cc.

References nca_def_dim(), nca_def_var(), and ConstVectorView::nelem().

Referenced by nca_write_to_file().

◆ nca_error()

void nca_error ( const int  e,
const String  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 671 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().

◆ 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 55 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 76 of file nc_io.cc.

References out_basename.

Referenced by WriteNetCDFIndexed().

◆ nca_get_data_ArrayOfArrayOfSpeciesTag()

void nca_get_data_ArrayOfArrayOfSpeciesTag ( 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 480 of file nc_io.cc.

References nc_get_dim(), nca_get_data_ArrayOfIndex(), nca_get_data_text(), and Array< base >::nelem().

Referenced by nca_read_from_file().

◆ nca_get_data_ArrayOfIndex()

void nca_get_data_ArrayOfIndex ( 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 454 of file nc_io.cc.

References nc_get_dim(), and nca_get_data_long().

Referenced by nca_get_data_ArrayOfArrayOfSpeciesTag(), and nca_read_from_file().

◆ nca_get_data_double()

void nca_get_data_double ( 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 397 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().

◆ nca_get_data_int()

void nca_get_data_int ( 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 361 of file nc_io.cc.

References nca_error().

◆ nca_get_data_long()

void nca_get_data_long ( 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 379 of file nc_io.cc.

References nca_error().

Referenced by nca_get_data_ArrayOfIndex(), and nca_read_from_file().

◆ nca_get_data_Matrix()

void nca_get_data_Matrix ( 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 539 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().

◆ nca_get_data_Tensor4()

void nca_get_data_Tensor4 ( 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 558 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().

◆ nca_get_data_text()

void nca_get_data_text ( 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 434 of file nc_io.cc.

References nca_error().

Referenced by nca_get_data_ArrayOfArrayOfSpeciesTag().

◆ nca_get_data_Vector()

void nca_get_data_Vector ( 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 521 of file nc_io.cc.

References VectorView::get_c_array(), nc_get_dim(), nca_get_data_double(), and Vector::resize().

Referenced by nca_read_from_file().

◆ nca_get_dataa_double()

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.

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

Definition at line 415 of file nc_io.cc.

References nca_error().

Referenced by nca_read_from_file().

◆ nca_put_var_ArrayOfIndex()

bool nca_put_var_ArrayOfIndex ( 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 578 of file nc_io.cc.

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

Referenced by nca_write_to_file().

◆ nca_put_var_Matrix()

bool nca_put_var_Matrix ( 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 629 of file nc_io.cc.

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

Referenced by nca_write_to_file().

◆ nca_put_var_Tensor4()

bool nca_put_var_Tensor4 ( 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 651 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().

◆ nca_put_var_Vector()

bool nca_put_var_Vector ( 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 607 of file nc_io.cc.

References VectorView::get_c_array(), nca_error(), and ConstVectorView::nelem().

Referenced by nca_write_to_file().

◆ 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 105 of file nc_io.cc.

References 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 151 of file nc_io.cc.

References add_basedir(), CREATE_OUT2, and nca_write_to_file().

Referenced by nca_write_to_file(), and WriteNetCDF().