ecacore.h 7.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
  This file is part of CDO. CDO is a collection of Operators to
  manipulate and analyse Climate model Data.

  Copyright (C) 2006 Brockmann Consult
  See COPYING file for copying and redistribution conditions.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

#ifndef ECA_H_
#define ECA_H_

21
22
#include "field.h"

Uwe Schulzweida's avatar
Uwe Schulzweida committed
23
enum ECA_EPILOG
Uwe Schulzweida's avatar
Uwe Schulzweida committed
24
{
25
  ECA_NONE,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
26
27
28
  MEAN,
  PERCENT_OF_TIME,
  PERCENT_OF_TOTAL_AMOUNT
Uwe Schulzweida's avatar
Uwe Schulzweida committed
29
};
30

Uwe Schulzweida's avatar
Uwe Schulzweida committed
31
32
33
using ECA_FUNC_1 = void (*)(Field &, double);
using ECA_FUNC_2 = void (*)(Field &, const Field &);
using ECA_FUNC_3 = void (*)(Field &, const Field &, double);
34
35
36

/**
 * Structure describing a processing request of the form
37
 *
38
 * o = F3(F2(a * F1(i) + b))
39
 *
40
41
 * where i and o denote the input and output fields, and
 * F1, F2 and F3 are field operators.
42
 *
43
 * The structure contains the following elements:
44
 *
45
46
47
48
49
50
51
52
53
54
 * name      the name of the output variable
 * longname  the longname of the output variable
 * units     the units of the output variable
 * f1        the 1st field operator
 * f1arg     the argument of the 1st field operator
 * f2        the 2nd field operator
 * f3        the 3rd field operator
 * mulc      the multiplier a
 * addc      the addend b
 * epilog    the final operation carried out after processing
55
 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
56
struct ECA_MAJOR_REQUEST_ELEMENT_1
57
{
58
59
60
  const char *name = nullptr;
  const char *longname = nullptr;
  const char *units = nullptr;
61
  int refdate;
62
  ECA_FUNC_1 f1 = nullptr;
63
  double f1arg;
64
65
  ECA_FUNC_2 f2 = nullptr;
  ECA_FUNC_2 f3 = nullptr;
66
67
  double mulc;
  double addc;
68
  ECA_EPILOG epilog = ECA_NONE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
69
};
70
71
72

/**
 * Structure describing a processing request of the form
73
 *
74
 * o = H3(H2(H1(i)))
75
 *
76
77
 * where i and o denote the input and output fields, and
 * H1, H2 and H3 are field operators.
78
 *
79
 * The structure contains the following elements:
80
 *
81
82
83
84
85
86
 * name      the name of the output variable
 * longname  the longname of the output variable
 * h1        the 1st field operator
 * h1arg     the argument of the 1st field operator
 * h2        the 2nd field operator
 * h3        the 3rd field operator
87
 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
struct ECA_MINOR_REQUEST_ELEMENT_1
89
{
90
91
92
93
  const char *name = nullptr;
  const char *longname = nullptr;
  const char *units = nullptr;
  ECA_FUNC_1 h1 = nullptr;
94
  double h1arg;
95
96
  ECA_FUNC_2 h2 = nullptr;
  ECA_FUNC_2 h3 = nullptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
97
};
98

Uwe Schulzweida's avatar
Uwe Schulzweida committed
99
struct ECA_REQUEST_1
100
{
101
102
  ECA_MAJOR_REQUEST_ELEMENT_1 var1;
  ECA_MINOR_REQUEST_ELEMENT_1 var2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
103
};
104
105
106

/**
 * Structure describing a processing request of the form
107
 *
108
 * o = F5(F4(F3(F1(i1), F2(i2))))
109
 *
110
111
 * where i1, i2 and o denote the input and output fields,
 * and F1, F2, F3, F4 and F3 are field operators.
112
 *
113
 * The structure contains the following elements:
114
 *
115
116
117
118
119
120
121
122
123
124
125
126
 * name      the name of the output variable
 * longname  the longname of the output variable
 * units     the units of the output variable
 * f1        the 1st field operator
 * f1arg     the argument of the 1st field operator
 * f2        the 2nd field operator
 * f2arg     the argument of the 2nd field operator
 * f3        the 3rd field operator
 * f4        the 4th field operator
 * f5        the 5th field operator
 * f5arg     the argument of the 5th field operator
 * epilog    the final operation carried out after processing
127
 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
128
struct ECA_MAJOR_REQUEST_ELEMENT_2
129
{
130
131
132
  const char *name = nullptr;
  const char *longname = nullptr;
  const char *units = nullptr;
133
  int refdate;
134
  ECA_FUNC_1 f1 = nullptr;
135
  double f1arg;
136
  ECA_FUNC_1 f2 = nullptr;
137
  double f2arg;
138
139
140
  ECA_FUNC_2 f3 = nullptr;
  ECA_FUNC_2 f4 = nullptr;
  ECA_FUNC_3 f5 = nullptr;
141
  double f5arg;
142
  ECA_EPILOG epilog = ECA_NONE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
143
};
144
145
146

/**
 * Structure describing a processing request of the form
147
 *
148
 * o = H2(H1(i))
149
 *
150
151
 * where i and o denote the input and output fields, and
 * H1, and H2 are field operators.
152
 *
153
 * The structure contains the following elements:
154
 *
155
156
 * name      the name of the output variable
 * longname  the longname of the output variable
Uwe Schulzweida's avatar
Uwe Schulzweida committed
157
 * units     the units of the output variable
158
159
160
 * h1        the 1st field operator
 * h1arg     the argument of the 1st field operator
 * h2        the 2nd field operator
161
 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
162
struct ECA_MINOR_REQUEST_ELEMENT_2
163
{
164
165
166
167
  const char *name = nullptr;
  const char *longname = nullptr;
  const char *units = nullptr;
  ECA_FUNC_1 h1 = nullptr;
168
  double h1arg;
169
  ECA_FUNC_2 h2 = nullptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
170
};
171

Uwe Schulzweida's avatar
Uwe Schulzweida committed
172
struct ECA_REQUEST_2
173
{
174
175
  ECA_MAJOR_REQUEST_ELEMENT_2 var1;
  ECA_MINOR_REQUEST_ELEMENT_2 var2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
176
};
177
178
179

/**
 * Structure describing a processing request of the form
180
 *
181
 * o = F3(F1(i1), F2(i2))
182
 *
183
184
 * where i1, i2 and o denote the input and output fields,
 * and F1, F2 and F3 are field operators.
185
 *
186
 * The structure contains the following elements:
187
 *
188
189
190
191
192
193
 * name      the name of the output variable
 * longname  the longname of the output variable
 * units     the units of the output variable
 * f1        the 1st field operator
 * f2        the 2nd field operator
 * f3        the 3rd field operator
194
 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
195
struct ECA_REQUEST_3
196
{
197
198
199
  const char *name = nullptr;
  const char *longname = nullptr;
  const char *units = nullptr;
200
  int refdate;
201
202
203
  ECA_FUNC_2 f1 = nullptr;
  ECA_FUNC_2 f2 = nullptr;
  ECA_FUNC_2 f3 = nullptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
204
};
205
206
207
208

/**
 * Structure describing a GSL-like processing request. The structure
 * contains the following elements:
209
 *
210
211
212
213
214
215
216
217
218
219
220
221
222
223
 * name       the name of the 1st output variable
 * longname   the longname of the 1st output variable
 * units      the units of the 1st output variable
 * name2      the name of the 2nd output variable
 * longname2  the longname of the 2nd output variable
 * units2     the units of the 2nd output variable
 * name3      the name of the 3rd output variable
 * longname3  the longname of the 3rd output variable
 * units3     the units of the 3rd output variable
 * s1         the 1st field selector
 * s1arg      argument of the 1st field selector
 * s2         the 2nd field selector
 * s2arg      argument of the 2nd field selector
 * consecutiveDays  the number od concecutive days
224
 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
225
struct ECA_REQUEST_4
226
{
227
228
229
230
231
232
233
  const char *name = nullptr;
  const char *longname = nullptr;
  const char *units = nullptr;
  const char *name2 = nullptr;
  const char *longname2 = nullptr;
  const char *units2 = nullptr;
  ECA_FUNC_1 s1 = nullptr;
234
  double s1arg;
235
  ECA_FUNC_1 s2 = nullptr;
236
  double s2arg;
237
  ECA_FUNC_1 s3 = nullptr;
238
239
  double s3arg;
  int consecutiveDays;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
240
};
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/**
 * Structure describing an ETCCDI index processing request. The structure
 * contains the following elements:
 *
 * name       the name of the output variable
 * longname   the longname of the output variable
 * units      the units of the output variable
 * pn         the percentile for the threshold
 * ndates     the window size
 * startboot  the begin year of the bootstrapping interval
 * endboot    the end year of the bootstrapping interval
 * func2      either func_sum or func_average
 */

struct ETCCDI_REQUEST
{
258
259
260
  const char *name = nullptr;
  const char *longname = nullptr;
  const char *units = nullptr;
261
262
263
264
265
266
267
  int pn;
  int ndates;
  int startboot;
  int endboot;
  int func2;
};

268
269
/**
 * Function processing a request of type 1.
270
 *
271
 * @param request the processing request
272
 */
273
274
275
276
void eca1(const ECA_REQUEST_1 *request);

/**
 * Function processing a request of type 2.
277
 *
278
 * @param request the processing request
279
 */
280
281
282
283
void eca2(const ECA_REQUEST_2 *request);

/**
 * Function processing a request of type 3.
284
 *
285
 * @param request the processing request
286
 */
287
288
289
290
void eca3(const ECA_REQUEST_3 *request);

/**
 * Function processing a request of type 4.
291
 *
292
 * @param request the processing request
293
 */
294
295
void eca4(const ECA_REQUEST_4 *request);

296
297
298
299
300
301
302
303
/**
 * Function processing a etccdi request.
 *
 * @param request the processing request
 */

void etccdi_op(ETCCDI_REQUEST *request);

304
#endif /* ECA_H_ */