MI - Fimex
Typedefs | Functions
c_fimex.h File Reference
#include <stddef.h>
#include "fimex/CDMconstants.h"
#include "fimex/deprecated.h"

Go to the source code of this file.

Typedefs

typedef struct mifi_cdm_reader mifi_cdm_reader
 
typedef struct mifi_slicebuilder mifi_slicebuilder
 
typedef int(* doubleDatasliceCallbackPtr) (mifi_cdm_reader *reader, const char *varName, size_t unLimDimPos, double *scaledData, size_t dataSize)
 

Functions

void mifi_free_cdm_reader (mifi_cdm_reader *reader)
 
mifi_cdm_readermifi_new_io_reader (int file_type, const char *filename, const char *configFile)
 
 MIFI_DEPRECATED (mifi_cdm_reader *mifi_new_felt_reader(const char *filename, const char *configFile))
 
 MIFI_DEPRECATED (mifi_cdm_reader *mifi_new_netcdf_reader(const char *filename))
 
 MIFI_DEPRECATED (mifi_cdm_reader *mifi_new_ncml_reader(const char *ncmlFile))
 
mifi_cdm_readermifi_new_ncml_modifier (mifi_cdm_reader *reader, const char *ncmlFile)
 
int mifi_netcdf_writer (mifi_cdm_reader *reader, const char *filename, const char *configFile, int version)
 
int mifi_grib_writer (mifi_cdm_reader *reader, const char *filename, const char *configFile, int version)
 
int mifi_nullcdm_writer (mifi_cdm_reader *reader)
 
mifi_cdm_readermifi_new_cdminterpolator (mifi_cdm_reader *reader, int method, const char *proj_input, const char *out_x_axis, const char *out_y_axis, const char *out_x_axis_unit, const char *out_y_axis_unit)
 change the projection of the reader to this new projection More...
 
mifi_cdm_readermifi_new_lonlat_interpolator (mifi_cdm_reader *reader, int method, int n, const double *lonVals, const double *latVals)
 change the projection of the reader to this new projection More...
 
mifi_cdm_readermifi_new_c_reader (mifi_cdm_reader *reader)
 
int mifi_set_callback_double (mifi_cdm_reader *c_reader, const char *varName, doubleDatasliceCallbackPtr callback)
 
size_t mifi_get_variable_number (mifi_cdm_reader *reader)
 
const char * mifi_get_variable_name (mifi_cdm_reader *reader, size_t pos)
 
unsigned int mifi_get_variable_type (mifi_cdm_reader *reader, const char *varName)
 
size_t mifi_get_dimension_number (mifi_cdm_reader *reader)
 
const char * mifi_get_dimension_name (mifi_cdm_reader *reader, size_t pos)
 
size_t mifi_get_dimension_size (mifi_cdm_reader *reader, const char *dimName)
 
const char * mifi_get_unlimited_dimension_name (mifi_cdm_reader *reader)
 
const char * mifi_get_var_longitude (mifi_cdm_reader *reader, const char *varName)
 
int mifi_get_var_longitude_cpy (mifi_cdm_reader *reader, const char *varName, char *lonName, int n)
 
const char * mifi_get_var_latitude (mifi_cdm_reader *reader, const char *varName)
 
int mifi_get_var_latitude_cpy (mifi_cdm_reader *reader, const char *varName, char *latName, int n)
 
mifi_slicebuildermifi_new_slicebuilder (mifi_cdm_reader *reader, const char *varName)
 
int mifi_slicebuilder_has_CS (mifi_slicebuilder *sb)
 
const char * mifi_slicebuilder_get_proj4 (mifi_slicebuilder *sb)
 
int mifi_slicebuilder_get_proj4_cpy (mifi_slicebuilder *sb, char *proj4, int n)
 
int mifi_slicebuilder_ndims (mifi_slicebuilder *sb)
 
const char * mifi_slicebuilder_dimname (mifi_slicebuilder *sb, int pos)
 
int mifi_slicebuilder_dimname_cpy (mifi_slicebuilder *sb, int pos, char *dimName, int n)
 
int mifi_slicebuilder_get_start_size (mifi_slicebuilder *sb, unsigned int *start, unsigned int *size)
 
int mifi_slicebuilder_get_axistype (mifi_slicebuilder *sb, int *axistype)
 
int mifi_slicebuilder_set_dim_start_size (mifi_slicebuilder *sb, const char *dimName, unsigned int start, unsigned int size)
 
void mifi_free_slicebuilder (mifi_slicebuilder *sb)
 
int mifi_get_double_dataslice (mifi_cdm_reader *reader, const char *varName, size_t unLimDimPos, double **data, size_t *size)
 
int mifi_get_double_data (mifi_cdm_reader *reader, const char *varName, double **data, size_t *size)
 
int mifi_fill_scaled_double_dataslice (mifi_cdm_reader *reader, const char *varName, mifi_slicebuilder *sb, const char *units, double *data, size_t *size)
 
int mifi_write_scaled_double_dataslice (mifi_cdm_reader *rwreader, const char *varName, mifi_slicebuilder *sb, const char *units, double *data, size_t size)
 
double mifi_get_unique_forecast_reference_time (mifi_cdm_reader *reader, const char *units)
 

Typedef Documentation

typedef int(* doubleDatasliceCallbackPtr) (mifi_cdm_reader *reader, const char *varName, size_t unLimDimPos, double *scaledData, size_t dataSize)

Function pointer as used for the get_double_dataslice callback function

Returns
0 on success, error otherwise

This is the public C-Api for fimex. It is a wrapper api for the underlying C++ api.

Function Documentation

MIFI_DEPRECATED ( mifi_cdm_reader mifi_new_felt_readerconst char *filename, const char *configFile)

Get a new reader from a felt file.

Parameters
filenamename of the felt-file
configFileconfiguration file for the felt-file
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
Deprecated:
use mifi_new_io_reader()

Get a new reader from a grib1/2 file.

Parameters
filenamename of the grib-file
configFileconfiguration file for the grib-file
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
Deprecated:
use mifi_new_io_reader()
MIFI_DEPRECATED ( mifi_cdm_reader mifi_new_netcdf_readerconst char *filename)

Get a new reader from a netcdf file.

Parameters
filenamename of the netcdf-file
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
Deprecated:
use mifi_new_io_reader()
MIFI_DEPRECATED ( mifi_cdm_reader mifi_new_ncml_readerconst char *ncmlFile)

Get a new reader from a ncml file.

Parameters
ncmlFilename of the ncml config file
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
Deprecated:
use mifi_new_io_reader()
int mifi_fill_scaled_double_dataslice ( mifi_cdm_reader reader,
const char *  varName,
mifi_slicebuilder sb,
const char *  units,
double *  data,
size_t *  size 
)

Read information from the readers variable to the pre-allocated data-variable.

Parameters
readerthe data-source
varNamevariable-name to read
sbThe slicebuilder to restrict dimensions. It is possible to reuse a slicebuilder for several variables with the same dimensions.
unitsUnits of the data. Scaling and unit-conversion will be done automatically. Use units = "" if you don't want any units-conversion. Units need to be udunits-compatible.
dataPreallocated data. The total size must be identical to the slicebuilders total size.
sizeThe actually read data. This might be <= the requested data if data not available.
Returns
0 on success
void mifi_free_cdm_reader ( mifi_cdm_reader reader)

Free the reader. This won't free the resources immediately, but reduce the reference counter. It is therefore possible to free a reader, while it still is used within another part of the fimex-chain.

void mifi_free_slicebuilder ( mifi_slicebuilder sb)

Free the memory allocated for the slicebuilder.

Parameters
sb
const char* mifi_get_dimension_name ( mifi_cdm_reader reader,
size_t  pos 
)

Get the name of a dimension from the reader.

Parameters
readerthe data source
posthe position number of the dimensin, should be between 0 and size-1
Returns
the dimension name, or "" on failure
size_t mifi_get_dimension_number ( mifi_cdm_reader reader)

Get the number of the dimensions from the reader.

Parameters
readerthe data source
Returns
the number of dimension
size_t mifi_get_dimension_size ( mifi_cdm_reader reader,
const char *  dimName 
)

Get the size of a dimension

Parameters
readerthe data source
dimNamethe name of the dimension
Returns
the size of the dimension, or 0 if dimension does not exist
int mifi_get_double_data ( mifi_cdm_reader reader,
const char *  varName,
double **  data,
size_t *  size 
)

get all the data from the dataReader

Parameters
readerdataReader to read the data from
varNamevariable name associated with the data
datathe returned data. It will be allocated automatically, it is the task of the user to free it. Undefined values will be NaN.
sizethe size of the returned data.
Returns
0 on success
int mifi_get_double_dataslice ( mifi_cdm_reader reader,
const char *  varName,
size_t  unLimDimPos,
double **  data,
size_t *  size 
)

get a slice of data from the dataReader

Parameters
readerdataReader to read the data from
varNamevariable name associated with the data
unLimDimPosunlimited dimension of the slice
datathe returned data. It will be allocated automatically, it is the task of the user to free it. Undefined values will be NaN.
sizethe size of the returned data.
Returns
0 on success
double mifi_get_unique_forecast_reference_time ( mifi_cdm_reader reader,
const char *  units 
)

get the unique forecast reference time in a unit

Parameters
reader
unitsa unit for point in time, e.g. "seconds since 1970-01-01"
Returns
time in the given unit, or NaN
const char* mifi_get_unlimited_dimension_name ( mifi_cdm_reader reader)

Get the name of the unlimited dimension

Parameters
reader
Returns
name of unlimited dimension, or ""
const char* mifi_get_var_latitude ( mifi_cdm_reader reader,
const char *  varName 
)

Get the name of the latitude variable belonging to a parameter. The latitude variable might be a dimension (1D), or an 2D field.

Parameters
reader
varNameThe name of a parameter.
Returns
latitude-variable name, which must be free'd, or NULL
int mifi_get_var_latitude_cpy ( mifi_cdm_reader reader,
const char *  varName,
char *  latName,
int  n 
)

Get the name of the latitude variable belonging to a parameter. This function is similar to mifi_get_var_longitude, except that the name is copied to lonName which is expected to have a capacity of n.

Parameters
reader
varNameThe name of a parameter.
latNameThe place to copy the longitude name to.
nThe capacity of latName – 10 means at most 9 characters plus a final 0 byte.
Returns
-1 if no longitude-latitude variables found; 0 if n is too small, else the number of characters copied to latName, including final NUL.
const char* mifi_get_var_longitude ( mifi_cdm_reader reader,
const char *  varName 
)

Get the name of the longitude variable belonging to a parameter. The longitude variable might be a dimension (1D), or an 2D field.

Parameters
reader
varNameThe name of a parameter.
Returns
longitude-variable name, which must be free'd, or NULL
int mifi_get_var_longitude_cpy ( mifi_cdm_reader reader,
const char *  varName,
char *  lonName,
int  n 
)

Get the name of the latitude variable belonging to a parameter. This function is similar to mifi_get_var_longitude, except that the name is copied to lonName which is expected to have a capacity of n.

Parameters
reader
varNameThe name of a parameter.
lonNameThe place to copy the longitude name to.
nThe capacity of lonName – 10 means at most 9 characters plus a final 0 byte.
Returns
-1 if no longitude-latitude variables found; 0 if n is too small, else the number of characters copied to lonName, including final NUL.
const char* mifi_get_variable_name ( mifi_cdm_reader reader,
size_t  pos 
)

Get the name of a variable from the reader.

Parameters
readerthe data source
posthe position number of the variable, should be between 0 and size-1
Returns
the variable name, or "" on failure
size_t mifi_get_variable_number ( mifi_cdm_reader reader)

Get the number of the variables from the reader.

Parameters
readerthe data source
Returns
the number of variables
unsigned int mifi_get_variable_type ( mifi_cdm_reader reader,
const char *  varName 
)

Get the MetNoFimex::CDMDataType datatype for a variable.

Parameters
readerthe data source
varNamename of the variable
Returns
datatype, or CDM_NAT=0 on error
int mifi_grib_writer ( mifi_cdm_reader reader,
const char *  filename,
const char *  configFile,
int  version 
)

Write the content of the reader to the filename as gribfile.

Parameters
readerthe data source
filenamethe name of the grib-file to write
configFilean optional configFile, use "" or 0 if not needed
versionthe version of the grib-edition. Implemented are 1 or 2.
Returns
0 on success.
int mifi_netcdf_writer ( mifi_cdm_reader reader,
const char *  filename,
const char *  configFile,
int  version 
)

Write the content of the reader to the filename.

Parameters
readerthe data source
filenamethe name of the netcdf-file to write
configFilean optional configFile, use "" or 0 if not needed
versionthe version of the netcdf-file. Implemented are 3 or 4.
Returns
0 on success.
mifi_cdm_reader* mifi_new_c_reader ( mifi_cdm_reader reader)

Get a new reader which allows setting c-callback functions.

Parameters
readerthe original data-source
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
mifi_cdm_reader* mifi_new_cdminterpolator ( mifi_cdm_reader reader,
int  method,
const char *  proj_input,
const char *  out_x_axis,
const char *  out_y_axis,
const char *  out_x_axis_unit,
const char *  out_y_axis_unit 
)

change the projection of the reader to this new projection

Parameters
readerthe original data-source
methodInterpolation method
proj_inputinput-string for proj4, used as output projection
out_x_axisconfig-string for x_axis, either '1,2,...,5' or 'auto' or 'auto,distance=3.5'
out_y_axisconfig-string for y_axis, either '1,2,...,5' or 'auto' or 'auto,distance=3.5'
out_x_axis_unitunit of the output x-axis
out_y_axis_unitunit of the output y-axis
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
mifi_cdm_reader* mifi_new_io_reader ( int  file_type,
const char *  filename,
const char *  configFile 
)

Get a new reader from a file.

Parameters
file_typemifi_filetype constant. To get a CDMReaderWriter, use MIFI_FILETYPE_NETCDF|MIFI_FILETYPE_RW.
filenamename of the felt-file
configFileconfiguration file for the felt-file
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
mifi_cdm_reader* mifi_new_lonlat_interpolator ( mifi_cdm_reader reader,
int  method,
int  n,
const double *  lonVals,
const double *  latVals 
)

change the projection of the reader to this new projection

Parameters
readerthe original data-source
methodInterpolation method
nnumber of latitude-longitude points
lonValsarray of size n with longitude positions
latValsarray of size n with latitude positions
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
mifi_cdm_reader* mifi_new_ncml_modifier ( mifi_cdm_reader reader,
const char *  ncmlFile 
)

Modify a reader using a ncml file.

Parameters
readerthe data/cdm source
ncmlFilename of the ncml config file
Returns
the reader object-pointer, use mifi_free_cdm_reader to free, or NULL on error.
mifi_slicebuilder* mifi_new_slicebuilder ( mifi_cdm_reader reader,
const char *  varName 
)

Create a new slice_builder for the reader and the variable. It will try to attach a coordinate-system if possible

Parameters
reader
varName
Returns
a slicebuilder handle
int mifi_nullcdm_writer ( mifi_cdm_reader reader)

Fetch the whole data belonging to the cdm, but don't write it anywhere.

Parameters
readerthe data source
Returns
0 on success.
int mifi_set_callback_double ( mifi_cdm_reader c_reader,
const char *  varName,
doubleDatasliceCallbackPtr  callback 
)

Add a callback for a variable. The variable will be converted to datatype double.

Parameters
c_readerthe reader as created by mifi_new_c_reader
varNamethe name of the variable
callbacka function-ptr to the callback function
Returns
0 on success, else error
Warning
the callback function will only be able to modify data which is available in the reader. It cannot change any information the writer request, but the reader doesn't now about. This data will continue to be undefined!
const char* mifi_slicebuilder_dimname ( mifi_slicebuilder sb,
int  pos 
)

Get the name of the dimension of the slicebuilder at a certain position.

Parameters
sb
pos
Returns
dimension's name or empty string, which both must be free'd
int mifi_slicebuilder_dimname_cpy ( mifi_slicebuilder sb,
int  pos,
char *  dimName,
int  n 
)

Get the projection of the slicebuilder. This function is similar to mifi_slicebuilder_get_proj4, except that the name is copied to proj4 which is expected to have a capacity of n.

Parameters
sb
pos
dimNameThe place to copy the dimension name to.
nThe capacity of dimName – 10 means at most 9 characters plus a final 0 byte.
Returns
0 if n is too small, else the number of characters copied to dimName, including final NUL.
int mifi_slicebuilder_get_axistype ( mifi_slicebuilder sb,
int *  axistype 
)
const char* mifi_slicebuilder_get_proj4 ( mifi_slicebuilder sb)

Get the projection of the slicebuilder, if it belongs to a coordinate-system with projection.

Parameters
sb
Returns
proj4 string or empty string, which both must be free'd
int mifi_slicebuilder_get_proj4_cpy ( mifi_slicebuilder sb,
char *  proj4,
int  n 
)

Get the projection of the slicebuilder. This function is similar to mifi_slicebuilder_get_proj4, except that the name is copied to proj4 which is expected to have a capacity of n.

Parameters
sb
proj4The place to copy the projection information to.
nThe capacity of proj4 – 10 means at most 9 characters plus a final 0 byte.
Returns
0 if n is too small, else the number of characters copied to proj4, including final NUL.
int mifi_slicebuilder_get_start_size ( mifi_slicebuilder sb,
unsigned int *  start,
unsigned int *  size 
)

Get the current start positions and dimension-sizes for all dimensions.

Parameters
sb
startpre-allocated array of size ndims
sizepre-allocated array of size ndims
Returns
0 on success, < 0 on failure
int mifi_slicebuilder_has_CS ( mifi_slicebuilder sb)

Check if the slicebuilder is connected to a coordinate-system.

Parameters
sb
Returns
1 on success, 0 on failure
int mifi_slicebuilder_ndims ( mifi_slicebuilder sb)

Get the number of dimensions (i.e. the rank) of the slicebuilder.

Parameters
sb
Returns
rank
int mifi_slicebuilder_set_dim_start_size ( mifi_slicebuilder sb,
const char *  dimName,
unsigned int  start,
unsigned int  size 
)

Set the start-position (starting with 0) and size of a named dimension.

Parameters
sb
dimName
start
size
Returns
0 on success, < 0 on failure
int mifi_write_scaled_double_dataslice ( mifi_cdm_reader rwreader,
const char *  varName,
mifi_slicebuilder sb,
const char *  units,
double *  data,
size_t  size 
)

Write data to the variable on disk

Parameters
rwreaderthe data-sink, should be opened with mifi_new_io_reader() with MIFI_FILETYPE_RW|MIFI_FILETYPE_NETCDF
varNamevariable-name to read
sbThe slicebuilder to restrict dimensions. It is possible to reuse a slicebuilder for several variables with the same dimensions.
unitsUnits of the data. Scaling and unit-conversion will be done automatically. Use units = "" if you don't want any units-conversion. Units need to be udunits-compatible.
dataPreallocated data. The total size must be identical to the slicebuilders total size.
sizeThe size of data.
Returns
0 on success