afterburner.h 6.14 KB
Newer Older
1
2
3
4
/*
  This file is part of CDO. CDO is a collection of Operators to
  manipulate and analyse Climate model Data.

Uwe Schulzweida's avatar
Uwe Schulzweida committed
5
  Copyright (C) 2003-2020 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
6
7
8
9
10
11
12
13
14
15
16
  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.
*/
17
18
#ifndef AFTERBURNER_H
#define AFTERBURNER_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
19

20
#ifdef HAVE_CONFIG_H
21
22
#include "config.h"
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
23

Uwe Schulzweida's avatar
Uwe Schulzweida committed
24
25
26
27
28
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

29
#include "dmemory.h"
30
#include "process_int.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
31
#include "transform.h"
32
#include "cdo_task.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
33
34
35

#define MaxLevel 1024

36
#define MaxCodes 277
Uwe Schulzweida's avatar
Uwe Schulzweida committed
37

38
#define S_ECHAM5 1
Uwe Schulzweida's avatar
Uwe Schulzweida committed
39
40
41

struct Date
{
42
43
44
45
46
  int yr;
  int mo;
  int dy;
  int hr;
  int mn;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
47
48
};

49
struct AfterControl
Uwe Schulzweida's avatar
Uwe Schulzweida committed
50
{
51
52
53
54
55
56
57
58
59
60
61
62
  int Verbose;

  int Mean;
  int MeanCount0;
  int MeanCount;
  int Multi;
  int Nfiles;
  int TermCount;

  int OutputInterval;
  int EndOfInterval;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
63
64
  int AnalysisData; // 0 = ECHAM Data, 1 = ECMWF Spectral Analyses
  int DayIn;        // day increment of infiles if Multi = true
65
  int Debug;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
66
67
  bool extrapolate;
  bool szip;
68
69

  int istreamID;
70
71
  CdoStreamID ostreamID;
  CdoStreamID ostreamID2;
72
73
74
75
76
  int ivlistID;
  int ovlistID;
  int ovlistID2;
  int taxisID;
  int taxisID2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
78
79
80
81
82

  struct Date NextDate;
  struct Date NewDate;
  struct Date OldDate;
  struct Date StartDate;

83
  int nvct;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
84
85
  double *vct;

86
  int *vert_index;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
87
  size_t *pnmiss;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
89
90
  double *Orography;
  double *p_of_height;

91
92
  int Type;
  int unitsel;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
93

94
95
96
97
98
99
  int Fouriers;
  int Latitudes;
  int Longitudes;
  int HalfLevels;
  int Gaussian;
  int Spectral;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
100

101
102
103
  int Truncation;
  int Waves;

104
105
106
  long Dim3FC, Dim3SP, Dim3GP;
  long DimFC, DimGP, DimSP;
  long DimSP_half;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
107
108
109
110
111
112
113
114
115
116

  double *poli;
  double *pold;
  double *pdev;
  double *pol2;
  double *pol3;

  double *dv2uv_f1;
  double *dv2uv_f2;

117
118
  int NumCodesRequest;

119
120
121
  int NumLevel;
  int NumLevelFound;
  int NumLevelRequest;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
122
123
124
125
126
127
128
  double LevelRequest[MaxLevel];

  double *rcoslat;
  double *coslat;
  double *DerivationFactor;
  double *Field;
};
129

Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
131
struct Variable
{
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  int needed0;  /* var needed for process  */
  int needed;   /* var needed for process  */
  int selected; /* var selected for output */
  int detected; /* var detected in input   */
  int comp;     /* compute var if selected and not detected */
  int sfit;
  int hlev;
  int plev;
  int ivarID;
  int ovarID;  /* 1st variable ID */
  int ovarID2; /* 2nd variable ID used for variance */
  int tableID;
  int igridID;
  int ogridID;
  int izaxisID;
  int ozaxisID;
  size_t nmiss0;
  size_t nmiss;
  double missval;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152
153
154
155
156
157
158
159
160
  double *spectral;
  double *spectral0;
  double *fourier;
  double *hybrid;
  double *hybrid0;
  double *height;
  double *grid;
  double *grid0;
  double *mean;
  double *variance;
161
  int *samp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
162
163
};

164
/* clang-format off */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#define    LOW_CLOUD   34
#define    MID_CLOUD   35
#define    HIH_CLOUD   36
#define    LOW_WATER   37  /* not used ?   */
#define    MID_WATER   38  /* not used ?   */
#define    HIH_WATER   39  /* not used ?   */
#define    ALL_WATER   40  /* not used ?   */

#define GEOPOTENTIAL  129
#define  TEMPERATURE  130
#define       U_WIND  131
#define       V_WIND  132
#define     HUMIDITY  133
#define           PS  134
#define        OMEGA  135
#define    VORTICITY  138
#define           TS  139
#define       STREAM  148
#define      VELOPOT  149
#define          SLP  151
#define         LNPS  152
#define   DIVERGENCE  155
#define GEOPOTHEIGHT  156
#define    RHUMIDITY  157

#define   SW_BOT_CLF  189  /* not used ?   */
#define   LW_BOT_CLF  190  /* not used ?   */
#define   SW_TOP_CLF  191  /* not used ?   */
#define   LW_TOP_CLF  192  /* not used ?   */
#define  NET_TOP_CLF  193  /* not computed */

#define    WINDSPEED  259
#define       PRECIP  260
#define      NET_TOP  261
#define      NET_BOT  262
#define     NET_HEAT  263
#define    NET_WATER  264
#define       SW_CLF  265
#define       LW_CLF  266
#define      NET_CLF  267
#define       SW_ATM  268
#define       LW_ATM  269
#define      NET_ATM  270
#define  SURF_RUNOFF  271
#define        DPSDX  273
#define        DPSDY  274
#define  FRESH_WATER  275
#define      PS_PROG  276  /* PS for prognostic timestep */
#define   HALF_PRESS  277
#define   FULL_PRESS  278
#define       THETAH  279
#define       THETAF  280
217
/* clang-format on */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
218
219
220

void after_read_vct(const char *vctfile, double **vct, int *nvct);

221
void after_gp2sp(AfterControl *globs, struct Variable *vars, int ccode);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
222
223
void after_GP2FC(double *gp, double *fc, long nlat, long nlon, long nlev, long nfc);
void after_FC2GP(double *fc, double *gp, long nlat, long nlon, long nlev, long nfc);
224
225
226
void after_FCrh2FCsh(AfterControl *globs, struct Variable *vars);
void after_SPuv2SPdv(AfterControl *globs, struct Variable *vars);
void after_FCsh2FCrh(AfterControl *globs, struct Variable *vars);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
227

228
229
230
void after_EchamCompGP(AfterControl *globs, struct Variable *vars);
void after_processPL(AfterControl *globs, struct Variable *vars);
void after_processML(AfterControl *globs, struct Variable *vars);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
231

232
void after_AnalysisAddRecord(AfterControl *globs, struct Variable *vars, int code, int gridID, int zaxisID, int levelID,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
233
                             size_t nmiss);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
234
double *after_get_dataptr(struct Variable *vars, int code, int gridID, int zaxisID, int levelID);
235
void after_EchamAddRecord(AfterControl *globs, struct Variable *vars, int code, int gridID, int zaxisID, int levelID,
236
                          size_t nmiss);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
237

238
void after_AnalysisDependencies(struct Variable *vars, int ncodes);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
239
void after_EchamDependencies(struct Variable *vars, int ncodes, int type, int source);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
240

241
void after_legini_setup(AfterControl *globs, struct Variable *vars);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
242

243
244
245
246
template <typename... Args>
void
afterAbort(const std::string &format, Args const &... args)
{
247
  extern cdo::Task *afterReadTask;
248
  extern bool afterReadAsync;
249
  if (afterReadAsync && afterReadTask) afterReadTask->wait();
250
251
252
  cdoAbort(format, args...);
}

253
#endif /* AFTERBURNER_H */