NetCDF Assembler documentation 1.0.0
Loading...
Searching...
No Matches
nc_assembler.hh
Go to the documentation of this file.
1/*
2** SEAGNAL PROJECT, 2024
3** netcdf-assembler
4** File description:
5** The header file of the project
6*/
13#include <algorithm>
14#include <cerrno>
15#include <cmath>
16#include <cstdbool>
17#include <cstddef>
18#include <cstdint>
19#include <cstdio>
20#include <cstdlib>
21#include <cstring>
22#include <fcntl.h>
23#include <iostream>
24#include <libgen.h>
25#include <linux/limits.h>
26#include <netcdf.h>
27#include <stdexcept>
28#include <unistd.h>
29#include <variant>
30#include <vector>
31#include <wait.h>
32
33#ifndef NC_ASSEMBLER_HH_
34 #define NC_ASSEMBLER_HH_
35
36 #define RED "\033[0;31m"
37 #define YELLOW "\033[0;33m"
38 #define BOLD "\033[1m"
39 #define UNDERLINE "\033[4m"
40 #define RESET "\033[0m"
41 #ifdef DEBUG_MODE
42 #define DEBUG (std::cout << YELLOW << "FILE: " << __FILE__ << ":" << __LINE__ << ", FUNCTION: " << __PRETTY_FUNCTION__ << RESET << std::endl)
43 #else
44 #define DEBUG
45 #endif
46 #define ERROR(ec) check_error(ec, __FILE__, __LINE__, __PRETTY_FUNCTION__)
47
48/* The variable types */
49using var_type = std::variant<signed char, char, short, int, float, double, unsigned char, unsigned short, unsigned int, long long, unsigned long long, char *>;
50
51/* The dimension information */
53 int32_t i_output_id = -1; /* The output id */
54 char ac_dim_name[NC_MAX_NAME + 1] = {0}; /* The dimension name */
55 size_t i_dim_len = 0; /* The dimension length */
57
58/* The variable information */
59typedef struct variable_information_s {
60 int32_t i_id = 0; /* The variable id */
61 char ac_var_name[NC_MAX_NAME + 1] = {0}; /* The variable name */
62 nc_type i_type = 0; /* The variable type */
63 int32_t i_ndims = 0; /* The number of dimensions */
64 int32_t ai_dimids[NC_MAX_VAR_DIMS] = {0}; /* The dimensions ids */
65 int32_t i_natts = 0; /* The number of attributes */
66 size_t ai_dims_size[NC_MAX_VAR_DIMS] = {0}; /* The dimensions size */
67 size_t i_data_size = 0; /* The data size */
68 int32_t i_dim_id = -1; /* The dimension id (for dimension variable) */
69 int32_t i_output_id = -1; /* The output id */
71
72/* The file information */
73typedef struct file_information_s {
74 char *ac_path = {0}; /* The file path */
75 int32_t i_file_id = 0; /* The file id */
76 int32_t i_nb_dimensions = 0; /* The number of dimensions */
77 int32_t i_nb_variables = 0; /* The number of variables */
78 int32_t i_nb_attributes = 0; /* The number of attributes */
79 int32_t i_first_unlimited_dimensions_id = 0; /* The first unlimited dimension id */
80 std::vector<dimension_information_t> vs_dims; /* The dimensions */
81 std::vector<variable_information_t> vs_variables; /* The variables */
83
84class assembler {
85 protected:
86 std::vector<file_information_t> _vs_input_files;
87 file_information_t _s_output_file = {0};
88
89 public:
93 assembler(int argc, char **argv);
94
98 ~assembler();
99
100
101
102 /* Attributes functions */
103
111 void copy_attributes(int32_t in_i_input_file, variable_information_t & in_s_ref_var,
112 variable_information_t & in_s_fill_var);
113
119 void add_globals_attributes(void);
120
121
122
123 /* Dimensions functions */
124
132 size_t in_i_dim_id);
133
138 void copy_dimensions(void);
139
140
141
142 /* Variables functions */
143
149 void sort_variable(variable_information_t & in_s_current_var);
150
159 size_t *get_start_from_input(size_t in_i_file, variable_information_t & in_s_input_var,
160 variable_information_t & in_s_output_var, size_t *in_ai_input_start);
161
169 void add_data_to_dim_variable(size_t in_i_file,
170 variable_information_t & in_s_input_var,
171 variable_information_t & in_s_output_var);
172
180 void add_data_to_variable(size_t in_i_file,
181 variable_information_t & in_s_input_var,
182 variable_information_t & in_s_output_var);
183
188 void copy_variables(void);
189};
190
191
192
193 /* Generale functions */
194
203void check_error(int in_i_error, const char *in_ac_file,
204 const int in_i_line, const char *in_ac_func);
205
212void open_file(file_information_t & in_s_file_info, int in_i_mode);
213
220void create_file(file_information_t & in_s_file_info, int in_i_mode);
221
227void get_info(file_information_t & in_s_file_info);
228
234void close_file(file_information_t & in_s_file_info);
235
242size_t get_dimension_size(file_information_t & in_s_file_info, size_t in_i_dim_id);
243
244
245
246#endif /* NC_ASSEMBLER_HH_ */
Definition nc_assembler.hh:84
size_t * get_start_from_input(size_t in_i_file, variable_information_t &in_s_input_var, variable_information_t &in_s_output_var, size_t *in_ai_input_start)
Get the output start index from the start index of an input variable.
Definition variables.cc:126
void add_globals_attributes(void)
Add the global attributes to the output file and copy globals attributes from first input file.
Definition attributes.cc:469
void add_data_to_dim_variable(size_t in_i_file, variable_information_t &in_s_input_var, variable_information_t &in_s_output_var)
Add data to a dimension variable from an input dimension variable.
Definition variables.cc:201
void copy_attributes(int32_t in_i_input_file, variable_information_t &in_s_ref_var, variable_information_t &in_s_fill_var)
Copy the attributes from the input file to the output file.
Definition attributes.cc:427
void add_data_to_variable(size_t in_i_file, variable_information_t &in_s_input_var, variable_information_t &in_s_output_var)
Add data to a variable from an input variable.
Definition variables.cc:343
~assembler()
The assembler class destructor.
Definition main.cc:71
void copy_variables(void)
Copy the variables.
Definition variables.cc:439
variable_information_t get_variable_from_dim_id(file_information_t &in_s_file, size_t in_i_dim_id)
Get the variable from the dimension id.
Definition dimensions.cc:40
void sort_variable(variable_information_t &in_s_current_var)
Sort a variable.
Definition sort.cc:319
void copy_dimensions(void)
Copy the dimensions from the input files to the output file.
Definition dimensions.cc:56
assembler(int argc, char **argv)
The assembler class constructor.
Definition main.cc:51
size_t get_dimension_size(file_information_t &in_s_file_info, size_t in_i_dim_id)
Get the dimension size.
Definition dimensions.cc:21
void open_file(file_information_t &in_s_file_info, int in_i_mode)
Open a NetCDF or a GRIB file.
Definition file.cc:21
void get_info(file_information_t &in_s_file_info)
Get the file information.
Definition file.cc:96
void create_file(file_information_t &in_s_file_info, int in_i_mode)
Create a NetCDF file.
Definition file.cc:81
void close_file(file_information_t &in_s_file_info)
Close a NetCDF file.
Definition file.cc:113
void check_error(int in_i_error, const char *in_ac_file, const int in_i_line, const char *in_ac_func)
Check if there is an error.
Definition main.cc:23
Definition nc_assembler.hh:52
Definition nc_assembler.hh:73
Definition nc_assembler.hh:59