IODA Bundle
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
22  { res.Strings.destruct = &ioda_string_ret_t_destruct; }
23 
24  // Dimensions
25  {
26  res.Dimensions.destruct = &ioda_dimensions_destruct;
27  res.Dimensions.getDimCur = &ioda_dimensions_get_dim_cur;
28  res.Dimensions.getDimensionality = &ioda_dimensions_get_dimensionality;
29  res.Dimensions.getDimMax = &ioda_dimensions_get_dim_max;
30  res.Dimensions.getNumElements = &ioda_dimensions_get_num_elements;
31  res.Dimensions.setDimCur = &ioda_dimensions_set_dim_cur;
32  res.Dimensions.setDimensionality = &ioda_dimensions_set_dimensionality;
33  res.Dimensions.setDimMax = &ioda_dimensions_set_dim_max;
34  }
35 
36  // Engines
37  {
38  res.Engines.constructFromCmdLine = &ioda_Engines_constructFromCmdLine;
39  {
40  res.Engines.HH.createFile = &ioda_Engines_HH_createFile;
41  res.Engines.HH.createMemoryFile = &ioda_Engines_HH_createMemoryFile;
42  res.Engines.HH.openFile = &ioda_Engines_HH_openFile;
43  }
44  { res.Engines.ObsStore.createRootGroup = &ioda_Engines_ObsStore_createRootGroup; }
45  }
46 
47  // Groups
48  {
49  // res.Group.atts is considered later.
50  // res.Group.vars is considered later.
51  res.Group.create = &ioda_group_create;
52  res.Group.destruct = &ioda_group_destruct;
53  res.Group.exists = &ioda_group_exists;
54  res.Group.getAtts = &ioda_group_atts;
55  res.Group.getVars = &ioda_group_vars;
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 
86  res.Has_Attributes.destruct = &ioda_has_attributes_destruct;
87  res.Has_Attributes.exists = &ioda_has_attributes_exists;
88  res.Has_Attributes.list = &ioda_has_attributes_list;
89  res.Has_Attributes.open = &ioda_has_attributes_open;
90  res.Has_Attributes.remove = &ioda_has_attributes_remove;
91  res.Has_Attributes.rename_att = &ioda_has_attributes_rename;
92  }
93 
94  // Variable Creation Parameters
95  {
96  res.VariableCreationParams.destruct = &ioda_variable_creation_parameters_destruct;
97  res.VariableCreationParams.create = &ioda_variable_creation_parameters_create;
98  res.VariableCreationParams.clone = &ioda_variable_creation_parameters_clone;
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 
107  res.VariableCreationParams.chunking = &ioda_variable_creation_parameters_chunking;
108  res.VariableCreationParams.noCompress = &ioda_variable_creation_parameters_noCompress;
109  res.VariableCreationParams.compressWithGZIP
111  res.VariableCreationParams.compressWithSZIP
113  }
114 
115  // Variables
116  {
117  res.Variable.destruct = &ioda_variable_destruct;
118  res.Variable.getAtts = &ioda_variable_atts;
119  res.Variable.getDimensions = &ioda_variable_get_dimensions;
120  res.Variable.resize = &ioda_variable_resize;
121  res.Variable.attachDimensionScale = &ioda_variable_attachDimensionScale;
122  res.Variable.detachDimensionScale = &ioda_variable_detachDimensionScale;
123  res.Variable.setDimScale = &ioda_variable_setDimScale;
124  res.Variable.isDimensionScale = &ioda_variable_isDimensionScale;
125  res.Variable.setIsDimensionScale = &ioda_variable_setIsDimensionScale;
126  res.Variable.getDimensionScaleName = &ioda_variable_getDimensionScaleName;
127  res.Variable.isDimensionScaleAttached = &ioda_variable_isDimensionScaleAttached;
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  {
148  res.Has_Variables.destruct = &ioda_has_variables_destruct;
149  res.Has_Variables.list = &ioda_has_variables_list;
150  res.Has_Variables.exists = &ioda_has_variables_exists;
151  res.Has_Variables.remove = &ioda_has_variables_remove;
152  res.Has_Variables.open = &ioda_has_variables_open;
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 
160  res.Has_Variables.VariableCreationParams = res.VariableCreationParams;
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.
IODA_DL void ioda_variable_creation_parameters_compressWithSZIP(struct ioda_variable_creation_parameters *params, unsigned PixelsPerBlock, unsigned options)
Compress with SZIP.
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.
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.
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.
Definition: ioda_c.h:35