MeteoIODoc 2.11.0
ncpp Namespace Reference

Enumerations

enum  Dimensions {
  firstdimension =mio::MeteoGrids::lastparam+10 , NONE =firstdimension , TIME , LATITUDE ,
  LONGITUDE , NORTHING , EASTING , STATION ,
  STATSTRLEN , DATESTRLEN , ZREF , UREF ,
  lastdimension =UREF
}
 This enum expands the parameters given in mio::MeteoGrids::Parameters and adds parameters used as dimensions in NetCDF files. More...
 

Functions

std::vector< std::string > initDimensionNames ()
 Set the names of the dimensions. More...
 
const std::vector< std::string > dimnames (initDimensionNames())
 
void open_file (const std::string &filename, const int &omode, int &ncid)
 
void create_file (const std::string &filename, const int &cmode, int &ncid)
 
void add_attribute (const int &ncid, const int &varid, const std::string &attr_name, const double &attr_value, const int &data_type)
 Add an attribute to the file pointed to by ncid. More...
 
void add_attribute (const int &ncid, const int &varid, const std::string &attr_name, const double &attr_value)
 Add an attribute to the file pointed to by ncid. More...
 
void add_attribute (const int &ncid, const int &varid, const std::string &attr_name, const float &attr_value)
 
void add_attribute (const int &ncid, const int &varid, const std::string &attr_name, const int &attr_value)
 
void add_attribute (const int &ncid, const int &varid, const std::string &attr_name, const std::string &attr_value)
 
void writeACDDAttributes (const int &ncid, const mio::ACDD &acdd)
 Add all the ACDD attributes contained in the acdd object to the file pointed to by ncid. More...
 
bool check_attribute (const int &ncid, const int &varid, const std::string &attr_name)
 Check if a variable has a given attribute. More...
 
void overload_attributes (ncpp::nc_variable &var)
 Add attributes to non-standard variables. More...
 
void create_variable (const int &ncid, ncpp::nc_variable &var)
 Write a pre-defined set of attributes for the given variable. More...
 
void file_redef (const std::string &filename, const int &ncid)
 Re-open the file in "definition" mode. More...
 
void end_definitions (const std::string &filename, const int &ncid)
 
void close_file (const std::string &filename, const int &ncid)
 
void read_data (const int &ncid, const nc_variable &var, const size_t &pos, const size_t &nrows, const size_t &ncols, const size_t &pos_i, const size_t &row_i, const size_t &col_i, double *data)
 Read 2D gridded data at the provided time position for a specific variable. More...
 
void read_data_point (const int &ncid, const nc_variable &var, const size_t &row, const size_t &col, const size_t &row_i, const size_t &col_i, double *data)
 Read grid point in 2D gridded data for non time dependent data. More...
 
void read_data_point (const int &ncid, const nc_variable &var, const size_t &pos, const size_t &row, const size_t &col, const size_t &pos_i, const size_t &row_i, const size_t &col_i, double *data)
 Read grid point in 2D gridded data at the provided time position for a specific variable. More...
 
void read_data (const int &ncid, const nc_variable &var, double *data)
 Read all the data for a specific variable. More...
 
void read_data (const int &ncid, const nc_variable &var, int *data)
 Read all the data for a specific variable. More...
 
void readVariableMetadata (const int &ncid, ncpp::nc_variable &var, const bool &readTimeTransform, const double &TZ)
 Read a pre-defined set of attributes for the given variable, from the provided file. More...
 
void write_data (const int &ncid, const nc_variable &var, const size_t &pos, const size_t &nrows, const size_t &ncols, const double *const data)
 Write 2D gridded data at the provided time position for a specific variable. More...
 
void write_1Ddata (const int &ncid, const nc_variable &var, const std::vector< double > &data, const bool &isUnlimited)
 Write a vector of data for a given 1D variable. More...
 
void write_1Ddata (const int &ncid, const nc_variable &var, const std::vector< std::string > &data, const int &strMaxLen)
 Write a vector of strings for a given 1D variable. More...
 
void getAttribute (const int &ncid, const nc_variable &var, const std::string &attr_name, std::string &attr_value)
 Read a given attribute from a variable (if not found, an empty string is returned) More...
 
void getAttribute (const int &ncid, const nc_variable &var, const std::string &attr_name, double &attr_value)
 Read a given attribute from a variable (if not found, attr_value is left unchanged) More...
 
void getGlobalAttribute (const int &ncid, const std::string &attr_name, std::string &attr_value)
 Read a given global attribute (if not found, an empty string is returned) More...
 
void getGlobalAttribute (const int &ncid, const std::string &attr_name, int &attr_value)
 
void getTimeTransform (const std::string &time_units, const double &i_TZ, double &o_time_offset, double &o_time_divisor)
 Parse a time unit specification. More...
 
void createDimension (const int &ncid, ncpp::nc_dimension &dimension, const size_t &length)
 Create a new dimension. More...
 
void fill2DGrid (mio::Grid2DObject &grid, const double data[], const double &nodata, const bool &normal_Xorder, const bool &normal_Yorder)
 Fill a Grid2DObject with 2D gridded data as read from a NetCDF file. More...
 
std::string getParameterName (const size_t &param)
 Given a parameter index, return its associated name. More...
 
std::string getParameterDescription (const size_t &param)
 
std::string getParameterUnits (const size_t &param)
 
size_t getParameterIndex (const std::string &param)
 Given a parameter name, return its associated index. More...
 
std::string generateHistoryAttribute ()
 Build a CF-1 history string (date of creation, creator, software version) More...
 
void createDimension (const int &ncid, nc_dimension &dimension, const size_t &length)
 

Enumeration Type Documentation

◆ Dimensions

This enum expands the parameters given in mio::MeteoGrids::Parameters and adds parameters used as dimensions in NetCDF files.

Enumerator
firstdimension 
NONE 
TIME 
LATITUDE 
LONGITUDE 
NORTHING 
EASTING 
STATION 
STATSTRLEN 
DATESTRLEN 
ZREF 
UREF 
lastdimension 

Function Documentation

◆ add_attribute() [1/5]

void ncpp::add_attribute ( const int &  ncid,
const int &  varid,
const std::string &  attr_name,
const double &  attr_value 
)

Add an attribute to the file pointed to by ncid.

In the target NetCDF file, the attribute will have the same type as the provided attribute value argument provided in this call

Parameters
[in]ncidfile ID
[in]varidID of the variable this attribute belongs to
[in]attr_namename of the attribute
[in]attr_valuevalue of the attribute

◆ add_attribute() [2/5]

void ncpp::add_attribute ( const int &  ncid,
const int &  varid,
const std::string &  attr_name,
const double &  attr_value,
const int &  data_type 
)

Add an attribute to the file pointed to by ncid.

The provided attribute value will be casted to the data type that is provided as argument.

Parameters
[in]ncidfile ID
[in]varidID of the variable this attribute belongs to
[in]attr_namename of the attribute
[in]attr_valuevalue of the attribute (represented as a double)
[in]data_typedata type to cast the value to (according to NetCDF's external data types)

◆ add_attribute() [3/5]

void ncpp::add_attribute ( const int &  ncid,
const int &  varid,
const std::string &  attr_name,
const float &  attr_value 
)

◆ add_attribute() [4/5]

void ncpp::add_attribute ( const int &  ncid,
const int &  varid,
const std::string &  attr_name,
const int &  attr_value 
)

◆ add_attribute() [5/5]

void ncpp::add_attribute ( const int &  ncid,
const int &  varid,
const std::string &  attr_name,
const std::string &  attr_value 
)

◆ check_attribute()

bool ncpp::check_attribute ( const int &  ncid,
const int &  varid,
const std::string &  attr_name 
)

Check if a variable has a given attribute.

Parameters
[in]ncidfile ID
[in]varidID of the variable those attributes should be checked
[in]attr_namename of the attribute to check
Returns
true if the variable has the given attribute, false otherwise

◆ close_file()

void ncpp::close_file ( const std::string &  filename,
const int &  ncid 
)

◆ create_file()

void ncpp::create_file ( const std::string &  filename,
const int &  cmode,
int &  ncid 
)

◆ create_variable()

void ncpp::create_variable ( const int &  ncid,
ncpp::nc_variable &  var 
)

Write a pre-defined set of attributes for the given variable.

Please note that during this call, a variable will be created, therefore the nc_variable structure will get a positive varid. If the variable already exists, it will return without doing anything.

Parameters
[in]ncidfile ID
[in,out]varvariable whose attributes should be set.

◆ createDimension() [1/2]

void ncpp::createDimension ( const int &  ncid,
nc_dimension dimension,
const size_t &  length 
)

◆ createDimension() [2/2]

void ncpp::createDimension ( const int &  ncid,
ncpp::nc_dimension &  dimension,
const size_t &  length 
)

Create a new dimension.

If the requested dimension already exists, nothing is done

Parameters
[in]ncidfile ID
[in]dimensiondimension to create
[in]lengthlength to set for this dimension (for the unlimited dimension, this will be ignored)

◆ dimnames()

const std::vector< std::string > ncpp::dimnames ( initDimensionNames()  )

◆ end_definitions()

void ncpp::end_definitions ( const std::string &  filename,
const int &  ncid 
)

◆ file_redef()

void ncpp::file_redef ( const std::string &  filename,
const int &  ncid 
)

Re-open the file in "definition" mode.

Parameters
[in]filenamefilename to use when reporting errors
[in]ncidfile ID

◆ fill2DGrid()

void ncpp::fill2DGrid ( mio::Grid2DObject grid,
const double  data[],
const double &  nodata,
const bool &  normal_Xorder,
const bool &  normal_Yorder 
)

Fill a Grid2DObject with 2D gridded data as read from a NetCDF file.

The provided Grid2DObject must have been properly initialized before (ie proper Nx, Ny). Grids whose llcorner/urcorner have been reversed are properly handled by providing the normal_Xorder and/or normal_Yorder booleans (as well as any combination).

Parameters
[out]gridgrid to populate
[in]dataserialized data, as read from the NetCDF file
[in]nodatavalue that indicates nodata
[in]normal_Xorderset to false if the X coordinate is reversed
[in]normal_Yorderset to false if the Y coordinate is reversed

◆ generateHistoryAttribute()

std::string ncpp::generateHistoryAttribute ( )

Build a CF-1 history string (date of creation, creator, software version)

Returns
string describing the file creation metadata

◆ getAttribute() [1/2]

void ncpp::getAttribute ( const int &  ncid,
const nc_variable var,
const std::string &  attr_name,
double &  attr_value 
)

Read a given attribute from a variable (if not found, attr_value is left unchanged)

Parameters
[in]ncidfile ID
[in]varvariable properties
[in]attr_nameattribute name
[out]attr_valueattribute value as read

◆ getAttribute() [2/2]

void ncpp::getAttribute ( const int &  ncid,
const nc_variable var,
const std::string &  attr_name,
std::string &  attr_value 
)

Read a given attribute from a variable (if not found, an empty string is returned)

Parameters
[in]ncidfile ID
[in]varvariable properties
[in]attr_nameattribute name
[out]attr_valueattribute value as read

◆ getGlobalAttribute() [1/2]

void ncpp::getGlobalAttribute ( const int &  ncid,
const std::string &  attr_name,
int &  attr_value 
)

◆ getGlobalAttribute() [2/2]

void ncpp::getGlobalAttribute ( const int &  ncid,
const std::string &  attr_name,
std::string &  attr_value 
)

Read a given global attribute (if not found, an empty string is returned)

Parameters
[in]ncidfile ID
[in]attr_nameattribute name
[out]attr_valueattribute value as read

◆ getParameterDescription()

std::string ncpp::getParameterDescription ( const size_t &  param)

◆ getParameterIndex()

size_t ncpp::getParameterIndex ( const std::string &  param)

Given a parameter name, return its associated index.

Since the MeteoGrids::Parameters have been extended inncpp, this method had to be redefined.

Parameters
[in]paramparameter name to get the index for
Returns
parameter index

◆ getParameterName()

std::string ncpp::getParameterName ( const size_t &  param)

Given a parameter index, return its associated name.

Since the MeteoGrids::Parameters have been extended inncpp, this method had to be redefined.

Parameters
[in]paramparameter index to get the name for
Returns
parameter name

◆ getParameterUnits()

std::string ncpp::getParameterUnits ( const size_t &  param)

◆ getTimeTransform()

void ncpp::getTimeTransform ( const std::string &  time_units,
const double &  i_TZ,
double &  o_time_offset,
double &  o_time_divisor 
)

Parse a time unit specification.

Time is often defined as a number of intervals (hours, seconds, etc) from a reference date. This call parses such as specification string and return the necessary offset and multiplier compared to julian date.

Parameters
[in]time_unitstime specification string
[in]i_TZtimezone to use to interpret the reference date
[out]o_time_offsetoffset to apply to convert the packed values to julian date
[out]o_time_divisormultiplier to apply to convert the packed values to julian date

◆ initDimensionNames()

std::vector< std::string > ncpp::initDimensionNames ( )
inline

Set the names of the dimensions.

Returns
vector of names that should be in the same order as the enum

◆ open_file()

void ncpp::open_file ( const std::string &  filename,
const int &  omode,
int &  ncid 
)

◆ overload_attributes()

void ncpp::overload_attributes ( ncpp::nc_variable &  var)
inline

Add attributes to non-standard variables.

Parameters
[in,out]varvariable whose attributes should be set.

◆ read_data() [1/3]

void ncpp::read_data ( const int &  ncid,
const nc_variable var,
const size_t &  pos,
const size_t &  nrows,
const size_t &  ncols,
const size_t &  pos_i,
const size_t &  row_i,
const size_t &  col_i,
double *  data 
)

Read 2D gridded data at the provided time position for a specific variable.

Parameters
[in]ncidfile ID
[in]varvariable to read
[in]postime index in the file
[in]nrowsnumber of rows
[in]ncolsnumber of columns
[in]pos_idimension index of time
[in]row_idimension index of the rows
[in]col_idimension index of the columns
[out]datadata extracted from the file

◆ read_data() [2/3]

void ncpp::read_data ( const int &  ncid,
const nc_variable var,
double *  data 
)

Read all the data for a specific variable.

Parameters
[in]ncidfile ID
[in]varvariable to read
[out]datadata extracted from the file

◆ read_data() [3/3]

void ncpp::read_data ( const int &  ncid,
const nc_variable var,
int *  data 
)

Read all the data for a specific variable.

Parameters
[in]ncidfile ID
[in]varvariable to read
[out]datadata extracted from the file

◆ read_data_point() [1/2]

void ncpp::read_data_point ( const int &  ncid,
const nc_variable var,
const size_t &  pos,
const size_t &  row,
const size_t &  col,
const size_t &  pos_i,
const size_t &  row_i,
const size_t &  col_i,
double *  data 
)

Read grid point in 2D gridded data at the provided time position for a specific variable.

Parameters
[in]ncidfile ID
[in]varvariable to read
[in]postime index in the file
[in]rowrow index to read
[in]colcolumn index to read
[in]pos_idimension index of time
[in]row_idimension index of the rows
[in]col_idimension index of the columns
[out]datadata extracted from the file

◆ read_data_point() [2/2]

void ncpp::read_data_point ( const int &  ncid,
const nc_variable var,
const size_t &  row,
const size_t &  col,
const size_t &  row_i,
const size_t &  col_i,
double *  data 
)

Read grid point in 2D gridded data for non time dependent data.

Parameters
[in]ncidfile ID
[in]varvariable to read
[in]rowrow index to read
[in]colcolumn index to read
[in]row_idimension index of the rows
[in]col_idimension index of the columns
[out]datadata extracted from the file

◆ readVariableMetadata()

void ncpp::readVariableMetadata ( const int &  ncid,
ncpp::nc_variable &  var,
const bool &  readTimeTransform,
const double &  TZ 
)

Read a pre-defined set of attributes for the given variable, from the provided file.

Please note that during this call, the nc_variable structure will get a positive varid. If any of the predefined set of attribute does not exist, it will be silently skipped. The attributes structure of the variable var will then be populated by what has been read.

Parameters
[in]ncidfile ID
[in,out]varvariable whose attributes should be read.
[in]readTimeTransformshould the time-parsing arguments (offset and scale from a reference date and units) be read? default=false
[in]TZtimezone to use when/if reading a date

◆ write_1Ddata() [1/2]

void ncpp::write_1Ddata ( const int &  ncid,
const nc_variable var,
const std::vector< double > &  data,
const bool &  isUnlimited 
)

Write a vector of data for a given 1D variable.

Parameters
[in]ncidfile ID
[in]varvariable to write out
[in]datavector that has to be written
[in]isUnlimitedIs the variable the associated variable of an unlimited dimension? (default: false)

◆ write_1Ddata() [2/2]

void ncpp::write_1Ddata ( const int &  ncid,
const nc_variable var,
const std::vector< std::string > &  data,
const int &  strMaxLen 
)

Write a vector of strings for a given 1D variable.

Parameters
[in]ncidfile ID
[in]varvariable properties
[in]datavector that has to be written
[in]strMaxLenmaximum length of the strings in the vector (this MUST have been defined as a dimension before)

◆ write_data()

void ncpp::write_data ( const int &  ncid,
const nc_variable var,
const size_t &  pos,
const size_t &  nrows,
const size_t &  ncols,
const double *const  data 
)

Write 2D gridded data at the provided time position for a specific variable.

Parameters
[in]ncidfile ID
[in]varvariable to write out
[in]nrowsnumber of rows
[in]ncolsnumber of columns
[in]postime index in the file (IOUtils::npos for a variable that is not time dependent)
[in]datadata to write to the file

◆ writeACDDAttributes()

void ncpp::writeACDDAttributes ( const int &  ncid,
const mio::ACDD acdd 
)

Add all the ACDD attributes contained in the acdd object to the file pointed to by ncid.

Parameters
[in]ncidfile ID
[in]acddACDD object containing all ACDD attributes (only those that have a value will be written)