1 #ifndef AFTERBURNER_H
2 #define AFTERBURNER_H
3
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <stdarg.h>
12
13 #include "dmemory.h"
14 #include "process_int.h"
15 #include "transform.h"
16 #include "cdo_task.h"
17
18 #define MaxLevel 1024
19
20 #define MaxCodes 277
21
22 #define S_ECHAM5 1
23
24 struct Date
25 {
26 int yr;
27 int mo;
28 int dy;
29 int hr;
30 int mn;
31 };
32
33 struct AfterControl
34 {
35 int Verbose;
36
37 int Mean;
38 int MeanCount0;
39 int MeanCount;
40 int Multi;
41 int Nfiles;
42 int TermCount;
43
44 int OutputInterval;
45 int EndOfInterval;
46
47 int AnalysisData; // 0 = ECHAM Data, 1 = ECMWF Spectral Analyses
48 int DayIn; // day increment of infiles if Multi = true
49 int Debug;
50 bool extrapolate;
51 bool szip;
52
53 int istreamID;
54 CdoStreamID ostreamID;
55 CdoStreamID ostreamID2;
56 int ivlistID;
57 int ovlistID;
58 int ovlistID2;
59 int taxisID;
60 int taxisID2;
61
62 struct Date NextDate;
63 struct Date NewDate;
64 struct Date OldDate;
65 struct Date StartDate;
66
67 int nvct;
68 double *vct;
69
70 int *vertIndex;
71 size_t *pnmiss;
72 double *Orography;
73 double *p_of_height;
74
75 int Type;
76 int unitsel;
77
78 int Fouriers;
79 int Latitudes;
80 int Longitudes;
81 int HalfLevels;
82 int Gaussian;
83 int Spectral;
84
85 int Truncation;
86 int Waves;
87
88 long Dim3FC, Dim3SP, Dim3GP;
89 long DimFC, DimGP, DimSP;
90 long DimSP_half;
91
92 double *poli;
93 double *pold;
94 double *pdev;
95 double *pol2;
96 double *pol3;
97
98 double *dv2uv_f1;
99 double *dv2uv_f2;
100
101 int NumCodesRequest;
102
103 int NumLevel;
104 int NumLevelFound;
105 int NumLevelRequest;
106 double LevelRequest[MaxLevel];
107
108 double *rcoslat;
109 double *coslat;
110 double *DerivationFactor;
111 double *Field;
112 };
113
114 struct Variable
115 {
116 int needed0; // var needed for process
117 int needed; // var needed for process
118 int selected; // var selected for output
119 int detected; // var detected in input
120 int comp; // compute var if selected and not detected
121 int sfit;
122 int hlev;
123 int plev;
124 int ivarID;
125 int ovarID; // 1st variable ID
126 int ovarID2; // 2nd variable ID used for variance
127 int tableID;
128 int igridID;
129 int ogridID;
130 int izaxisID;
131 int ozaxisID;
132 size_t nmiss0;
133 size_t nmiss;
134 double missval;
135 double *spectral;
136 double *spectral0;
137 double *fourier;
138 double *hybrid;
139 double *hybrid0;
140 double *height;
141 double *grid;
142 double *grid0;
143 double *mean;
144 double *variance;
145 int *samp;
146 };
147
148 /* clang-format off */
149 #define LOW_CLOUD 34
150 #define MID_CLOUD 35
151 #define HIH_CLOUD 36
152 #define LOW_WATER 37 /* not used ? */
153 #define MID_WATER 38 /* not used ? */
154 #define HIH_WATER 39 /* not used ? */
155 #define ALL_WATER 40 /* not used ? */
156
157 #define GEOPOTENTIAL 129
158 #define TEMPERATURE 130
159 #define U_WIND 131
160 #define V_WIND 132
161 #define HUMIDITY 133
162 #define PS 134
163 #define OMEGA 135
164 #define VORTICITY 138
165 #define TS 139
166 #define STREAM 148
167 #define VELOPOT 149
168 #define SLP 151
169 #define LNPS 152
170 #define DIVERGENCE 155
171 #define GEOPOTHEIGHT 156
172 #define RHUMIDITY 157
173
174 #define SW_BOT_CLF 189 /* not used ? */
175 #define LW_BOT_CLF 190 /* not used ? */
176 #define SW_TOP_CLF 191 /* not used ? */
177 #define LW_TOP_CLF 192 /* not used ? */
178 #define NET_TOP_CLF 193 /* not computed */
179
180 #define WINDSPEED 259
181 #define PRECIP 260
182 #define NET_TOP 261
183 #define NET_BOT 262
184 #define NET_HEAT 263
185 #define NET_WATER 264
186 #define SW_CLF 265
187 #define LW_CLF 266
188 #define NET_CLF 267
189 #define SW_ATM 268
190 #define LW_ATM 269
191 #define NET_ATM 270
192 #define SURF_RUNOFF 271
193 #define DPSDX 273
194 #define DPSDY 274
195 #define FRESH_WATER 275
196 #define PS_PROG 276 /* PS for prognostic timestep */
197 #define HALF_PRESS 277
198 #define FULL_PRESS 278
199 #define THETAH 279
200 #define THETAF 280
201 /* clang-format on */
202
203 void after_read_vct(const char *vctfile, double **vct, int *nvct);
204
205 void after_gp2sp(const AfterControl &globs, struct Variable *vars, int ccode);
206 void after_GP2FC(double *gp, double *fc, long nlat, long nlon, long nlev, long nfc);
207 void after_FC2GP(double *fc, double *gp, long nlat, long nlon, long nlev, long nfc);
208 void after_FCrh2FCsh(const AfterControl &globs, struct Variable *vars);
209 void after_SPuv2SPdv(const AfterControl &globs, struct Variable *vars);
210 void after_FCsh2FCrh(const AfterControl &globs, struct Variable *vars);
211
212 void after_EchamCompGP(const AfterControl &globs, struct Variable *vars);
213 void after_processPL(AfterControl &globs, struct Variable *vars);
214 void after_processML(AfterControl &globs, struct Variable *vars);
215
216 void after_AnalysisAddRecord(const AfterControl *globs, struct Variable *vars, int code, int gridID, int zaxisID, int levelID,
217 size_t nmiss);
218 double *after_get_dataptr(struct Variable *vars, int code, int gridID, int zaxisID, int levelID);
219 void after_EchamAddRecord(const AfterControl *globs, struct Variable *vars, int code, int gridID, int zaxisID, int levelID,
220 size_t nmiss);
221
222 void after_AnalysisDependencies(struct Variable *vars, int ncodes);
223 void after_EchamDependencies(struct Variable *vars, int ncodes, int type, int source);
224
225 void after_legini_setup(AfterControl &globs, struct Variable *vars);
226
227 template <typename... Args>
228 void
afterAbort(const std::string & format,Args const &...args)229 afterAbort(const std::string &format, Args const &... args)
230 {
231 extern cdo::Task *afterReadTask;
232 extern bool afterReadAsync;
233 if (afterReadAsync && afterReadTask) afterReadTask->wait();
234 cdo_abort(format, args...);
235 }
236
237 #endif /* AFTERBURNER_H */
238