IODA
ioda_c.cpp
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020-2021 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 /*! \addtogroup ioda_c
8  * @{
9  * \file ioda_c.cpp
10  * \brief C bindings for ioda-engines. Provides a class-like structure.
11  */
12 #include "ioda/C/ioda_c.h"
13 
14 /** \brief Creates and returns a c_ioda struct that has all of the function pointers filled in.
15  *
16  * Unfortunately, you can't have a default initializer in a struct in C.
17  **/
18 extern "C" c_ioda use_c_ioda() {
19  c_ioda res; // NOLINT: Obviously uninitialized. That's the purpose of this function.
20 
21  // Strings
23 
24  // Dimensions
25  {
34  }
35 
36  // Engines
37  {
39  {
43  }
45  }
46 
47  // Groups
48  {
49  // res.Group.atts is considered later.
50  // res.Group.vars is considered later.
56  res.Group.list = &ioda_group_list;
57  res.Group.open = &ioda_group_open;
58  }
59 
60  // Attributes
61  {
62  res.Attribute.destruct = &ioda_attribute_destruct;
63  res.Attribute.getDimensions = &ioda_attribute_get_dimensions;
64 
65 #define IODA_ATTRIBUTE_INST_TEMPLATE(shortnamestr, basenamestr) \
66  res.Attribute.shortnamestr = basenamestr;
67 
68  // res.Attribute.isA_*
70 
71  // res.Attribute.read_*
73 
74  // res.Attribute.write_*
76  }
77 
78  // Has_Attributes
79  {
80 #define IODA_HAS_ATTRIBUTES_INST_TEMPLATE(shortnamestr, basenamestr) \
81  res.Has_Attributes.shortnamestr = basenamestr;
82  // res.Has_Attributes.create_*
83  C_TEMPLATE_FUNCTION_DECLARATION_3(create, ioda_has_attributes_create,
85 
92  }
93 
94  // Variable Creation Parameters
95  {
99 
100 #define IODA_VCP_INST_TEMPLATE(shortnamestr, basenamestr) \
101  res.VariableCreationParams.shortnamestr = basenamestr;
102 
103  // res.VariableCreationParams.setFillValue_*
105  setFillValue, ioda_variable_creation_parameters_setFillValue, IODA_VCP_INST_TEMPLATE);
106 
113  }
114 
115  // Variables
116  {
128 
129 #define IODA_VARIABLE_INST_TEMPLATE(shortnamestr, basenamestr) \
130  res.Variable.shortnamestr = basenamestr;
131 
132  // res.Variable.isA_*
134 
135  // res.Variable.read_*
136  C_TEMPLATE_FUNCTION_DECLARATION_3(read_full, ioda_variable_read_full,
138 
139  // res.Variable.write_*
140  C_TEMPLATE_FUNCTION_DECLARATION_3(write_full, ioda_variable_write_full,
142 
143  res.Variable.atts = res.Has_Attributes;
144  }
145 
146  // Has_Variables
147  {
153 
154 #define IODA_HAS_VARIABLES_INST_TEMPLATE(shortnamestr, basenamestr) \
155  res.Has_Variables.shortnamestr = basenamestr;
156  // res.Has_Variables.create_*
157  C_TEMPLATE_FUNCTION_DECLARATION_3(create, ioda_has_variables_create,
159 
161  }
162 
163  res.Group.atts = res.Has_Attributes;
164  res.Group.vars = res.Has_Variables;
165 
166  return res;
167 }
168 
169 /// @}
IODA_DL struct ioda_dimensions * ioda_attribute_get_dimensions(const struct ioda_attribute *att)
Gets an attribute's dimensions.
IODA_DL void ioda_attribute_destruct(struct ioda_attribute *att)
Deallocates an attribute.
Definition: Attribute_c.cpp:21
#define C_TEMPLATE_FUNCTION_DECLARATION_3_NOSTR(shortname, basename, PATTERN)
#define C_TEMPLATE_FUNCTION_DECLARATION_3(shortname, basename, PATTERN)
c_ioda use_c_ioda()
Creates and returns a c_ioda struct that has all of the function pointers filled in.
Definition: ioda_c.cpp:18
IODA_DL bool ioda_dimensions_get_dim_cur(const struct ioda_dimensions *d, size_t n, ptrdiff_t *val)
Get the current size of the n-th dimension.
IODA_DL bool ioda_dimensions_get_dim_max(const struct ioda_dimensions *d, size_t n, ptrdiff_t *val)
Get the maximum size of the n-th dimension.
IODA_DL bool ioda_dimensions_set_dimensionality(struct ioda_dimensions *d, size_t N)
Set dimensionality of the dimensions container.
IODA_DL bool ioda_dimensions_set_dim_max(struct ioda_dimensions *d, size_t n, ptrdiff_t sz)
Set the maximum size of the n-th dimension.
IODA_DL bool ioda_dimensions_get_dimensionality(const struct ioda_dimensions *d, size_t *val)
Gets dimensionality (i.e. number of dimensions)
IODA_DL bool ioda_dimensions_set_dim_cur(struct ioda_dimensions *d, size_t n, ptrdiff_t sz)
Set the current size of the n-th dimension.
IODA_DL bool ioda_dimensions_get_num_elements(const struct ioda_dimensions *d, size_t *val)
Get the number of distinct elements in the dimensions object (the product of each dimension size).
IODA_DL void ioda_dimensions_destruct(struct ioda_dimensions *d)
Deallocates a dimensions container.
IODA_DL struct ioda_group * ioda_Engines_HH_createMemoryFile(size_t sz_filename, const char *filename, bool flush_on_close, long increment_len_bytes)
Create a new in-memory data store, backed by HDF5.
Definition: Engines_c.cpp:34
IODA_DL struct ioda_group * ioda_Engines_HH_openFile(size_t sz_filename, const char *filename, enum ioda_Engines_BackendOpenModes mode)
Open a handle to a file that is backed by HDF5.
Definition: Engines_c.cpp:47
IODA_DL struct ioda_group * ioda_Engines_ObsStore_createRootGroup()
Create a new ObsStore instance.
Definition: Engines_c.cpp:26
IODA_DL struct ioda_group * ioda_Engines_HH_createFile(size_t sz_filename, const char *filename, enum ioda_Engines_BackendCreateModes mode)
Create a new file using the HDF5 interface.
Definition: Engines_c.cpp:62
IODA_DL struct ioda_group * ioda_Engines_constructFromCmdLine(int argc, char **argv, const char *defaultFilename)
Function used in the ioda C examples and unit tests to construct different backends based on differen...
Definition: Engines_c.cpp:79
IODA_DL void ioda_group_destruct(struct ioda_group *grp)
Frees a ioda_group.
Definition: Group_c.cpp:22
IODA_DL struct ioda_string_ret_t * ioda_group_list(const struct ioda_group *grp)
Lists all one-level child groups.
IODA_DL struct ioda_has_attributes * ioda_group_atts(const struct ioda_group *grp)
Access a group's attributes.
IODA_DL int ioda_group_exists(const struct ioda_group *base, size_t child_sz, const char *child)
Check if a group exists.
IODA_DL struct ioda_group * ioda_group_create(struct ioda_group *base, size_t sz, const char *name)
Create a group.
Definition: Group_c.cpp:46
IODA_DL struct ioda_has_variables * ioda_group_vars(const struct ioda_group *grp)
Access a group's variables.
IODA_DL struct ioda_group * ioda_group_open(const struct ioda_group *base, size_t sz, const char *name)
Open a group.
IODA_DL bool ioda_has_attributes_rename(struct ioda_has_attributes *has_atts, size_t sz_oldname, const char *oldname, size_t sz_newname, const char *newname)
Rename an attribute.
IODA_DL struct ioda_attribute * ioda_has_attributes_open(const struct ioda_has_attributes *has_atts, size_t sz_name, const char *name)
Open (access) an attribute by name.
IODA_DL void ioda_has_attributes_destruct(struct ioda_has_attributes *has_atts)
Deallocates a ioda_has_attributes_object.
IODA_DL struct ioda_string_ret_t * ioda_has_attributes_list(const struct ioda_has_attributes *)
List the names of the attributes associated with an object.
IODA_DL bool ioda_has_attributes_remove(struct ioda_has_attributes *has_atts, size_t sz_name, const char *name)
Remove an attribute.
IODA_DL int ioda_has_attributes_exists(const struct ioda_has_attributes *has_atts, size_t sz_name, const char *name)
Check if an attribute exists.
IODA_DL struct ioda_variable * ioda_has_variables_open(const struct ioda_has_variables *has_vars, size_t sz_name, const char *name)
Open (access) a variable by name.
IODA_DL struct ioda_string_ret_t * ioda_has_variables_list(const struct ioda_has_variables *)
List the names of the variables associated with an object.
IODA_DL bool ioda_has_variables_remove(struct ioda_has_variables *has_vars, size_t sz_name, const char *name)
Remove a variable.
IODA_DL int ioda_has_variables_exists(const struct ioda_has_variables *has_vars, size_t sz_name, const char *name)
Check if a variable exists.
IODA_DL void ioda_has_variables_destruct(struct ioda_has_variables *has_vars)
Deallocates a ioda_has_variables.
IODA_DL void ioda_string_ret_t_destruct(struct ioda_string_ret_t *)
Deallocate a returned string object.
Definition: String_c.cpp:19
IODA_DL void ioda_variable_creation_parameters_compressWithGZIP(struct ioda_variable_creation_parameters *params, int level)
Compress with GZIP.
IODA_DL void ioda_variable_creation_parameters_chunking(struct ioda_variable_creation_parameters *params, bool doChunking, size_t Ndims, const ptrdiff_t *chunks)
Set chunking options.
void(* destruct)(struct ioda_variable_creation_parameters *)
void(* compressWithGZIP)(struct ioda_variable_creation_parameters *, int)
void(* compressWithSZIP)(struct ioda_variable_creation_parameters *, unsigned, unsigned)
IODA_DL void ioda_variable_creation_parameters_compressWithSZIP(struct ioda_variable_creation_parameters *params, unsigned PixelsPerBlock, unsigned options)
Compress with SZIP.
void(* chunking)(struct ioda_variable_creation_parameters *, bool, size_t, const ptrdiff_t *)
struct ioda_variable_creation_parameters *(* clone)(const struct ioda_variable_creation_parameters *)
IODA_DL void ioda_variable_creation_parameters_noCompress(struct ioda_variable_creation_parameters *params)
Disable compression.
IODA_DL void ioda_variable_creation_parameters_destruct(struct ioda_variable_creation_parameters *params)
Deallocates variable creation parameters.
IODA_DL struct ioda_variable_creation_parameters * ioda_variable_creation_parameters_create()
Allocates a new variable creation parameters instance.
struct ioda_variable_creation_parameters *(* create)()
IODA_DL struct ioda_variable_creation_parameters * ioda_variable_creation_parameters_clone(const struct ioda_variable_creation_parameters *source)
Make a copy of an existing variable creation parameters object.
void(* noCompress)(struct ioda_variable_creation_parameters *)
IODA_DL size_t ioda_variable_getDimensionScaleName(const struct ioda_variable *var, size_t len_out, char *out)
Get the name of the dimension scale.
Definition: Variable_c.cpp:109
IODA_DL bool ioda_variable_setDimScale(struct ioda_variable *var, size_t n_dims, const struct ioda_variable *const *dims)
Convenience function to set a sequence of scales on a variable.
Definition: Variable_c.cpp:78
IODA_DL int ioda_variable_isDimensionScale(const struct ioda_variable *var)
Check if a variable acts as a dimension scale.
Definition: Variable_c.cpp:93
IODA_DL struct ioda_dimensions * ioda_variable_get_dimensions(const struct ioda_variable *)
Gets an variable's dimensions.
IODA_DL bool ioda_variable_detachDimensionScale(struct ioda_variable *var, unsigned int DimensionNumber, const struct ioda_variable *scale)
Detach a dimension scale from a variable.
Definition: Variable_c.cpp:69
IODA_DL bool ioda_variable_setIsDimensionScale(struct ioda_variable *var, size_t sz_name, const char *dimensionScaleName)
Convert a variable into a dimension scale.
Definition: Variable_c.cpp:100
IODA_DL void ioda_variable_destruct(struct ioda_variable *var)
Deallocates an variable.
Definition: Variable_c.cpp:24
IODA_DL bool ioda_variable_resize(struct ioda_variable *var, size_t N, const long *newDims)
Resize a variable.
Definition: Variable_c.cpp:50
IODA_DL struct ioda_has_attributes * ioda_variable_atts(const struct ioda_variable *var)
Access a variable's attributes.
IODA_DL int ioda_variable_isDimensionScaleAttached(const struct ioda_variable *var, unsigned int DimensionNumber, const struct ioda_variable *scale)
Is the variable "scale" attached as dimension "DimensionNumber" to variable "var"?
Definition: Variable_c.cpp:123
IODA_DL bool ioda_variable_attachDimensionScale(struct ioda_variable *var, unsigned int DimensionNumber, const struct ioda_variable *scale)
Attach a dimension scale to a variable.
Definition: Variable_c.cpp:60
#define IODA_HAS_VARIABLES_INST_TEMPLATE(shortnamestr, basenamestr)
#define IODA_VARIABLE_INST_TEMPLATE(shortnamestr, basenamestr)
#define IODA_VCP_INST_TEMPLATE(shortnamestr, basenamestr)
#define IODA_HAS_ATTRIBUTES_INST_TEMPLATE(shortnamestr, basenamestr)
#define IODA_ATTRIBUTE_INST_TEMPLATE(shortnamestr, basenamestr)
C bindings for ioda-engines.
bool(* setDimensionality)(struct ioda_dimensions *, size_t)
Definition: Dimensions_c.h:103
bool(* setDimMax)(struct ioda_dimensions *, size_t, ptrdiff_t)
Definition: Dimensions_c.h:108
bool(* getNumElements)(const struct ioda_dimensions *, size_t *)
Definition: Dimensions_c.h:104
bool(* getDimMax)(const struct ioda_dimensions *, size_t, ptrdiff_t *)
Definition: Dimensions_c.h:107
void(* destruct)(struct ioda_dimensions *)
Definition: Dimensions_c.h:101
bool(* getDimensionality)(const struct ioda_dimensions *, size_t *)
Definition: Dimensions_c.h:102
bool(* setDimCur)(struct ioda_dimensions *, size_t, ptrdiff_t)
Definition: Dimensions_c.h:106
bool(* getDimCur)(const struct ioda_dimensions *, size_t, ptrdiff_t *)
Definition: Dimensions_c.h:105
struct ioda_string_ret_t *(* list)(const struct ioda_has_attributes *)
bool(* rename_att)(struct ioda_has_attributes *, size_t, const char *, size_t, const char *)
struct ioda_attribute *(* open)(const struct ioda_has_attributes *, size_t, const char *)
int(* exists)(const struct ioda_has_attributes *, size_t, const char *)
void(* destruct)(struct ioda_has_attributes *)
bool(* remove)(struct ioda_has_attributes *, size_t, const char *)
struct ioda_variable *(* open)(const struct ioda_has_variables *, size_t, const char *)
struct c_variable_creation_parameters VariableCreationParams
struct ioda_string_ret_t *(* list)(const struct ioda_has_variables *)
void(* destruct)(struct ioda_has_variables *)
int(* exists)(const struct ioda_has_variables *, size_t, const char *)
bool(* remove)(struct ioda_has_variables *, size_t, const char *)
struct ioda_group *(* createFile)(size_t, const char *, enum ioda_Engines_BackendCreateModes)
Definition: Engines_c.h:97
struct ioda_group *(* openFile)(size_t, const char *, enum ioda_Engines_BackendOpenModes)
Definition: Engines_c.h:96
struct ioda_group *(* createMemoryFile)(size_t, const char *, bool, long)
Definition: Engines_c.h:94
struct ioda_group *(* createRootGroup)()
Definition: Engines_c.h:90
struct c_ioda_engines_ObsStore ObsStore
Definition: Engines_c.h:104
struct c_ioda_engines_HH HH
Definition: Engines_c.h:103
struct ioda_group *(* constructFromCmdLine)(int, char **, const char *)
Definition: Engines_c.h:101
int(* exists)(const struct ioda_group *, size_t, const char *)
Definition: Group_c.h:100
struct ioda_string_ret_t *(* list)(const struct ioda_group *)
Definition: Group_c.h:99
struct ioda_has_variables *(* getVars)(const struct ioda_group *)
Definition: Group_c.h:104
struct ioda_has_attributes *(* getAtts)(const struct ioda_group *)
Definition: Group_c.h:103
struct ioda_group *(* create)(struct ioda_group *, size_t, const char *)
Definition: Group_c.h:101
struct ioda_group *(* open)(const struct ioda_group *, size_t, const char *)
Definition: Group_c.h:102
struct c_has_attributes atts
Definition: Group_c.h:106
struct c_has_variables vars
Definition: Group_c.h:107
void(* destruct)(struct ioda_group *)
Definition: Group_c.h:98
Definition: ioda_c.h:35
struct c_strings Strings
Definition: ioda_c.h:41
struct c_variable Variable
Definition: ioda_c.h:42
struct c_variable_creation_parameters VariableCreationParams
Definition: ioda_c.h:43
struct c_dimensions Dimensions
Definition: ioda_c.h:40
struct c_attribute Attribute
Definition: ioda_c.h:38
struct c_ioda_engines Engines
Definition: ioda_c.h:36
struct c_has_attributes Has_Attributes
Definition: ioda_c.h:39
struct c_ioda_group Group
Definition: ioda_c.h:37
struct c_has_variables Has_Variables
Definition: ioda_c.h:44
void(* destruct)(struct ioda_string_ret_t *)
Definition: String_c.h:34
int(* isDimensionScale)(const struct ioda_variable *)
Definition: Variable_c.h:272
struct ioda_dimensions *(* getDimensions)(const struct ioda_variable *)
Definition: Variable_c.h:267
struct ioda_has_attributes *(* getAtts)(const struct ioda_variable *)
Definition: Variable_c.h:266
void(* destruct)(struct ioda_variable *)
Definition: Variable_c.h:265
bool(* resize)(struct ioda_variable *, size_t, const long *)
Definition: Variable_c.h:268
size_t(* getDimensionScaleName)(const struct ioda_variable *, size_t, char *)
Definition: Variable_c.h:274
bool(* setDimScale)(struct ioda_variable *, size_t, const struct ioda_variable *const *)
Definition: Variable_c.h:271
bool(* attachDimensionScale)(struct ioda_variable *, unsigned int, const struct ioda_variable *)
Definition: Variable_c.h:269
int(* isDimensionScaleAttached)(const struct ioda_variable *, unsigned int, const struct ioda_variable *)
Definition: Variable_c.h:275
struct c_has_attributes atts
Definition: Variable_c.h:297
bool(* detachDimensionScale)(struct ioda_variable *, unsigned int, const struct ioda_variable *)
Definition: Variable_c.h:270
bool(* setIsDimensionScale)(struct ioda_variable *, size_t, const char *)
Definition: Variable_c.h:273