EcaIndices.cc 73.1 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) 2006 Brockmann Consult
6
7
8
9
10
11
12
13
14
15
16
17
  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.
*/

18
// clang-format off
19
20
/*
      MODULE      OPERATOR     INDEX    DESCRIPTION
21

22
      EcaCfd      eca_cfd      CFD      maximum number of consecutive frost days
23
24
25
26
27
28
      EcaCsu      eca_csu      CSU      maximum number of consecutive summer days
      EcaCwdi     eca_cwdi     CWDI     cold wave duration index 
      EcaCwfi     eca_cwfi     CWFI     number of cold-spell days
      EcaEtr      eca_etr      ETR      intra-period extreme temperature range
      EcaFd       eca_fd       FD       number of frost days
      EcaGsl      eca_gsl      GSL      growing season length
29
30
31
32
33
      EcaHd       eca_hd       HD       heating degree days
      EcaHwdi     eca_hwdi     HWDI     heat wave duration index
      EcaHwfi     eca_hwfi     HWFI     number of warm-spell days
      EcaId       eca_id       ID       number of ice days
      EcaSu       eca_su       SU       number of summer days
34
35
36
37
38
39
40
      EcaTg10p    eca_tg10p    TG10p    percent of time TX < 10th percentile of daily mean temperature
      EcaTg90p    eca_tg90p    TG90p    percent of time TX > 90th percentile of daily mean temperature
      EcaTn10p    eca_tn10p    TN10p    percent of time TX < 10th percentile of daily minimum temperature
      EcaTn90p    eca_tn90p    TN90p    percent of time TX > 90th percentile of daily minimum temperature
      EcaTr       eca_tr       TR       number of tropical nights
      EcaTx10p    eca_tx10p    TX10p    percent of time TX < 10th percentile of daily maximum temperature
      EcaTx90p    eca_tx90p    TX90p    percent of time TX > 90th percentile of daily maximum temperature
41
42
43

      EcaCdd      eca_cdd      CDD      maximum number of consecutive dry days
      EcaCwd      eca_cwd      CWD      maximum number of consecutive wet days
44
45
46
47
48
49
50
51
52
53
54
55
      EcaR10mm    eca_r10mm    R10mm    number of days with precipitation >= 10 mm
      EcaR20mm    eca_r20mm    R20mm    number of days with precipitation >= 20 mm
      EcaR75p     eca_r75p     R75p     Percent of time RR > 75th percentile of daily precipitation amount
      EcaR75ptot  eca_r75ptot  R75pTOT  Percentage of annual total precipitation due to events with RR > 75th percentile of daily precipitation amount
      EcaR90p     eca_r90p     R90p     Percent of time RR > 90th percentile of daily precipitation amount
      EcaR90ptot  eca_r90ptot  R90pTOT  Percentage of annual total precipitation due to events with RR > 90th percentile of daily precipitation amount
      EcaR95p     eca_r95p     R95p     Percent of time RR > 95th percentile of daily precipitation amount
      EcaR95ptot  eca_r95ptot  R95pTOT  Percentage of annual total precipitation due to events with RR > 95th percentile of daily precipitation amount
      EcaR99p     eca_r99p     R99p     Percent of time RR > 75th percentile of daily precipitation amount
      EcaR99ptot  eca_r99ptot  R99pTOT  Percentage of annual total precipitation due to events with RR > 99th percentile of daily precipitation amount
      EcaRr1      eca_rr1      RR1      number of wet days
      EcaSdii     eca_sdii     SDII     simple daily intensity index
56
57

      Fdns        fdns                  frost days without surface snow
Uwe Schulzweida's avatar
Uwe Schulzweida committed
58

Uwe Schulzweida's avatar
Uwe Schulzweida committed
59
      Strwin      strwin                number of strong-wind days
60
61
62
      Strbre      strbre                number of strong-breeze days
      Strgal      strgal                number of strong-gale days
      Hurr        hurr                  number of hurricane days
63
*/
64
// clang-format on
65

66
#include "dmemory.h"
67
#include "process_int.h"
Oliver Heidmann's avatar
Oliver Heidmann committed
68
#include "cdo_options.h"
69
#include "param_conversion.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
70
#include "ecacore.h"
71
#include "ecautil.h"
72
#include "util_date.h"
73
#include "pmlist.h"
74

75
#define TO_DEG_CELSIUS(x) ((x) -273.15)
76
77
#define TO_KELVIN(x) ((x) + 273.15)

Uwe Schulzweida's avatar
Uwe Schulzweida committed
78
// clang-format off
79

Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
81
static const char CFD_NAME[]         = "consecutive_frost_days_index_per_time_period";
static const char CFD_LONGNAME[]     = "Consecutive frost days index is the greatest number of consecutive frost days in a given time period. Frost days is the number of days where minimum of temperature is below 0 degree Celsius. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
82
//static const char CFD_UNITS[]        = "No.";
83
84
static const char CFD_NAME2[]        = "number_of_cfd_periods_with_more_than_%ddays_per_time_period";
static const char CFD_LONGNAME2[]    = "Number of cfd periods in given time period with more than %d days. The time period should be defined by the bounds of the time coordinate.";
85
static const char CFD_UNITS2[]       = "No.";
86

Uwe Schulzweida's avatar
Uwe Schulzweida committed
87
88
static const char CSU_NAME[]         = "consecutive_summer_days_index_per_time_period";
static const char CSU_LONGNAME[]     = "Consecutive summer days index is the greatest number of consecutive summer days in a given time period. Summer days is the number of days where maximum of temperature is above 25 degree Celsius. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
//static const char CSU_UNITS[]        = "No.";
90
91
static const char CSU_NAME2[]        = "number_of_csu_periods_with_more_than_%ddays_per_time_period";
static const char CSU_LONGNAME2[]    = "Number of csu periods in given time period with more than %d days. The time period should be defined by the bounds of the time coordinate.";
92
static const char CSU_UNITS2[]       = "No.";
93

Uwe Schulzweida's avatar
Uwe Schulzweida committed
94
95
96
97
98
99
static const char CWDI_NAME[]        = "cold_wave_duration_index_wrt_mean_of_reference_period";
static const char CWDI_LONGNAME[]    = "This is the number of days per time period where in intervals of at least %d consecutive days the daily minimum temperature is more than %1.0f degrees below a reference value. The reference value is calculated  as the mean of minimum temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
static const char CWDI_UNITS[]       = "No.";
static const char CWDI_NAME2[]       = "cold_waves_per_time_period";
static const char CWDI_LONGNAME2[]   = "Number of cold waves per time period. The time period should be defined by the bounds of the time coordinate.";
static const char CWDI_UNITS2[]      = "No.";
100

Uwe Schulzweida's avatar
Uwe Schulzweida committed
101
static const char CWFI_NAME[]        = "cold_spell_days_index_wrt_10th_percentile_of_reference_period";
102
static const char CWFI_NAME_ET[]     = "csdiETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
103
static const char CWFI_LONGNAME[]    = "This is the number of days per time period where in intervals of at least %d consecutive days the daily mean temperature is below a reference value. The reference value is calculated  as the 10th percentile of daily mean temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
104
static const char CWFI_LONGNAME_ET[] = "Cold Spell Duration Index";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
105
static const char CWFI_UNITS[]       = "No.";
106
static const char CWFI_UNITS_ET[]    = "days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
107
108
109
static const char CWFI_NAME2[]       = "cold_spell_periods_per_time_period";
static const char CWFI_LONGNAME2[]   = "Number of cold spell periods per time period. The time period should be defined by the bounds of the time coordinate.";
static const char CWFI_UNITS2[]      = "No.";
110
111

static const char ETR_NAME[]         = "intra_period_extreme_temperature_range";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
112
static const char ETR_LONGNAME[]     = "Difference between the absolute extreme temperatures in observation period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
113
//static const char ETR_UNITS[]        = "K";
114

Uwe Schulzweida's avatar
Uwe Schulzweida committed
115
static const char FD_NAME[]          = "frost_days_index_per_time_period";
116
static const char FD_NAME_ET[]       = "fdETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
static const char FD_LONGNAME[]      = "Frost days index is the number of days where minimum of temperature is below 0 degree Celsius. The time period should be defined by the bounds of the time coordinate.";
118
static const char FD_LONGNAME_ET[]   = "Number of Frost Days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
//static const char FD_UNITS[]         = "No.";
120
static const char FD_UNITS_ET[]      = "days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
121

122
static const char GSL_NAME[]         = "thermal_growing_season_length";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
static const char GSL_LONGNAME[]     = "Counted are the number of days per calendar year between the first occurrence of at least %d consecutive days where the daily mean temperature is above %1.0f degree Celsius and the first occurrence of at least %d consecutive days after 1st of July where the daily mean temperature is below %1.0f degree Celsius. The time period should be defined by the bounds of the time coordinate.";
static const char GSL_UNITS[]        = "No.";
static const char GSL_NAME2[]        = "day_of_year_of_growing_season_start";
static const char GSL_LONGNAME2[]    = "Day of year of growing season start. The time period should be defined by the bounds of the time coordinate.";
static const char GSL_UNITS2[]       = "No.";

static const char HD_NAME[]          = "heating_degree_days_per_time_period";
static const char HD_LONGNAME[]      = "Heating degree days relates the outside temperature with the room temperature during the heating period. It is the sum of the difference between room temperature X and daily mean temperature Y on days where Y is below a given constant A. X is 20 degree Celsius and A is 15 degree Celsius according to VDI guidelines. According to ECAD both X and A are 17 degree Celsius. The time period should be defined by the bounds of the time coordinate.";
static const char HD_UNITS[]         = "No.";

static const char HWDI_NAME[]        = "heat_wave_duration_index_wrt_mean_of_reference_period";
static const char HWDI_LONGNAME[]    = "This is the number of days per time period where in intervals of at least %d consecutive days the daily maximum temperature is more than %1.0f degrees above a reference value. The reference value is calculated  as the mean of maximum temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
static const char HWDI_UNITS[]       = "No.";
static const char HWDI_NAME2[]       = "heat_waves_per_time_period";
static const char HWDI_LONGNAME2[]   = "Number of heat waves per time period. The time period should be defined by the bounds of the time coordinate.";
static const char HWDI_UNITS2[]      = "No.";

static const char HWFI_NAME[]        = "warm_spell_days_index_wrt_90th_percentile_of_reference_period";
141
static const char HWFI_NAME_ET[]     = "wsdiETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
142
static const char HWFI_LONGNAME[]    = "This is the number of days per time period where in intervals of at least %d consecutive days the daily mean temperature is above a reference value. The reference value is calculated  as the 90th percentile of daily mean temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
143
static const char HWFI_LONGNAME_ET[] = "Warm Spell Duration Index";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
144
static const char HWFI_UNITS[]       = "No.";
145
static const char HWFI_UNITS_ET[]    = "days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
146
147
148
149
150
static const char HWFI_NAME2[]       = "warm_spell_periods_per_time_period";
static const char HWFI_LONGNAME2[]   = "Number of warm spell periods per time period. The time period should be defined by the bounds of the time coordinate.";
static const char HWFI_UNITS2[]      = "No.";

static const char ID_NAME[]          = "ice_days_index_per_time_period";
151
static const char ID_NAME_ET[]       = "idETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
152
static const char ID_LONGNAME[]      = "Ice days index is the number of days where maximum of temperature is below 0 degree Celsius. The time period should be defined by the bounds of the time coordinate.";
153
static const char ID_LONGNAME_ET[]   = "Number of Icing Days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
154
static const char ID_UNITS[]         = "No.";
155
static const char ID_UNITS_ET[]      = "days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
157

static const char SU_NAME[]          = "summer_days_index_per_time_period";
158
static const char SU_NAME_ET[]       = "suETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
159
static const char SU_LONGNAME[]      = "Summer days index is the number of days where maximum of temperature is above %1.0f degree Celsius. The time period should be defined by the bounds of the time coordinate.";
160
static const char SU_LONGNAME_ET[]   = "Number of Summer Days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
161
//static const char SU_UNITS[]         = "No.";
162
static const char SU_UNITS_ET[]      = "days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
163
164

static const char TG10P_NAME[]       = "cold_days_percent_wrt_10th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
165
static const char TG10P_LONGNAME[]   = "This is the percent of time per time period where daily mean temperature is below a reference value. The reference value is calculated as the 10th percentile of daily mean temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
166
167
168
static const char TG10P_UNITS[]      = "Percent";

static const char TG90P_NAME[]       = "warm_days_percent_wrt_90th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
static const char TG90P_LONGNAME[]   = "This is the percent of time per time period where daily mean temperature is above a reference value. The reference value is calculated as the 90th percentile of daily mean temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
170
171
172
static const char TG90P_UNITS[]      = "Percent";

static const char TN10P_NAME[]       = "cold_nights_percent_wrt_10th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
173
static const char TN10P_LONGNAME[]   = "This is the percent of time per time period where daily minimum temperature is below a reference value. The reference value is calculated as the 10th percentile of daily minimum temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
174
175
176
static const char TN10P_UNITS[]      = "Percent";

static const char TN90P_NAME[]       = "warm_nights_percent_wrt_90th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
177
static const char TN90P_LONGNAME[]   = "This is the percent of time per time period where daily minimum temperature is above a reference value. The reference value is calculated as the 90th percentile of daily minimum temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
178
179
180
static const char TN90P_UNITS[]      = "Percent";

static const char TR_NAME[]          = "tropical_nights_index_per_time_period";
181
static const char TR_NAME_ET[]       = "trETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
182
static const char TR_LONGNAME[]      = "Tropical nights index is the number of days where minimum of temperature is above %1.0f degree Celsius. The time period should be defined by the bounds of the time coordinate.";
183
static const char TR_LONGNAME_ET[]   = "Number of Tropical Nights";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
184
static const char TR_UNITS[]         = "No.";
185
static const char TR_UNITS_ET[]      = "days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
186
187

static const char TX10P_NAME[]       = "very_cold_days_percent_wrt_10th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
188
static const char TX10P_LONGNAME[]   = "This is the percent of time per time period where daily maximum temperature is below a reference value. The reference value is calculated as the 10th percentile of daily maximum temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
190
191
static const char TX10P_UNITS[]      = "Percent";

static const char TX90P_NAME[]       = "very_warm_days_percent_wrt_90th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
192
static const char TX90P_LONGNAME[]   = "This is the percent of time per time period where daily maximum temperature is above a reference value. The reference value is calculated as the 90th percentile of daily maximum temperatures of a five day window centred on each calendar day of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
193
194
195
static const char TX90P_UNITS[]      = "Percent";

static const char CDD_NAME[]         = "consecutive_dry_days_index_per_time_period";
196
static const char CDD_NAME_ET[]      = "cddETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
197
static const char CDD_LONGNAME[]     = "Consecutive dry days is the greatest number of consecutive days per time period with daily precipitation amount below %g mm. The time period should be defined by the bounds of the time coordinate.";
198
static const char CDD_LONGNAME_ET[]  = "Maximum Number of Consecutive Days with Less Than 1mm of Precipitation [days]";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
199
static const char CDD_UNITS[]        = "No.";
200
static const char CDD_UNITS_ET[]      = "days";
201
202
static const char CDD_NAME2[]        = "number_of_cdd_periods_with_more_than_%ddays_per_time_period";
static const char CDD_LONGNAME2[]    = "Number of cdd periods in given time period with more than %d days. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
203
204
205
static const char CDD_UNITS2[]       = "No.";

static const char CWD_NAME[]         = "consecutive_wet_days_index_per_time_period";
206
static const char CWD_NAME_ET[]      = "cwdETCCDI";
207
static const char CWD_LONGNAME[]     = "Consecutive wet days is the greatest number of consecutive days per time period with daily precipitation above %g mm. The time period should be defined by the bounds of the time coordinate.";
208
static const char CWD_LONGNAME_ET[]  = "Maximum Number of Consecutive Days with At Least 1mm of Precipitation";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
209
static const char CWD_UNITS[]        = "No.";
210
static const char CWD_UNITS_ET[]     = "days";
211
212
static const char CWD_NAME2[]        = "number_of_cwd_periods_with_more_than_%ddays_per_time_period";
static const char CWD_LONGNAME2[]    = "Number of cwd periods in given time period with more than %d days. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
213
214
static const char CWD_UNITS2[]       = "No.";

215
static const char PD_NAME[]          = "precipitation_days_index_per_time_period";
216
static const char PD_NAME_ET[]       = "r1mmETCCDI";
217
static const char PD_LONGNAME[]      = "precipitation days is the number of days per time period with daily precipitation sum exceeding %g mm. The time period should be defined by the bounds of the time coordinate.";
218
static const char PD_LONGNAME_ET[]   = "Count of Days with At Least 1mm of Precipitation";
219
static const char PD_UNITS[]         = "No.";
220
static const char PD_UNITS_ET[]      = "days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
221

Uwe Schulzweida's avatar
Uwe Schulzweida committed
222
static const char R10MM_NAME[]       = "heavy_precipitation_days_index_per_time_period";
223
static const char R10MM_NAME_ET[]    = "r10mmETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
224
static const char R10MM_LONGNAME[]   = "Heavy precipitation days is the number of days per time period with daily precipitation sum exceeding 10 mm. The time period should be defined by the bounds of the time coordinate.";
225
static const char R10MM_LONGNAME_ET[]= "Count of Days with At Least 10mm of Precipitation";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
226
static const char R10MM_UNITS[]      = "No.";
227
static const char R10MM_UNITS_ET[]   = "days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
228
229

static const char R20MM_NAME[]       = "very_heavy_precipitation_days_index_per_time_period";
230
static const char R20MM_NAME_ET[]    = "r20mmETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
231
static const char R20MM_LONGNAME[]   = "Very heavy precipitation days is the number of days with daily precipitation sum exceeding 20 mm. The time period should be defined by the bounds of the time coordinate.";
232
static const char R20MM_LONGNAME_ET[]= "Count of Days with At Least 20mm of Precipitation";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
233
static const char R20MM_UNITS[]      = "No.";
234
static const char R20MM_UNITS_ET[]   = "days";
235
236

static const char R75P_NAME[]        = "moderate_wet_days_wrt_75th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
237
static const char R75P_LONGNAME[]    = "This is the percent of time per time period of wet days (daily sum at least 1 mm / day) where daily precipitation amount of a wet day is above a reference value. The reference value is calculated as the 75th percentile of all wet days of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
238
static const char R75P_UNITS[]       = "Percent";
239

Uwe Schulzweida's avatar
Uwe Schulzweida committed
240
static const char R75PTOT_NAME[]     = "precipitation_percent_due_to_R75p_days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
241
static const char R75PTOT_LONGNAME[] = "Percentage of total precipitation amount per time period due to moderate_wet_days_wrt_75th_percentile_of_reference_period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
242
static const char R75PTOT_UNITS[]    = "Percent";
243

Uwe Schulzweida's avatar
Uwe Schulzweida committed
244
static const char R90P_NAME[]        = "wet_days_wrt_90th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
245
static const char R90P_LONGNAME[]    = "This is the percent of time per time period of wet days (daily sum at least 1 mm / day) where daily precipitation amount of a wet day is above a reference value. The reference value is calculated as the 90th percentile of all wet days of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
246
static const char R90P_UNITS[]       = "Percent";
247

Uwe Schulzweida's avatar
Uwe Schulzweida committed
248
static const char R90PTOT_NAME[]     = "precipitation_percent_due_to_R90p_days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249
static const char R90PTOT_LONGNAME[] = "Percentage of total precipitation amount per time period due towet_days_wrt_90th_percentile_of_reference_period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250
static const char R90PTOT_UNITS[]    = "Percent";
251
252

static const char R95P_NAME[]        = "very_wet_days_wrt_95th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
static const char R95P_LONGNAME[]    = "This is the percent of time per time period of wet days (daily sum at least 1 mm / day) where daily precipitation amount of a wet day is above a reference value. The reference value is calculated as the 95th percentile of all wet days of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
254
static const char R95P_UNITS[]       = "Percent";
255

Uwe Schulzweida's avatar
Uwe Schulzweida committed
256
static const char R95PTOT_NAME[]     = "precipitation_percent_due_to_R95p_days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
257
static const char R95PTOT_LONGNAME[] = "Percentage of total precipitation amount per time period due to very_wet_days_wrt_95th_percentile_of_reference_period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
static const char R95PTOT_UNITS[]    = "Percent";
259
260

static const char R99P_NAME[]        = "extremely_wet_days_wrt_99th_percentile_of_reference_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
261
static const char R99P_LONGNAME[]    = "This is the percent of time per time period of wet days (daily sum at least 1 mm / day) where daily precipitation amount of a wet day is above a reference value. The reference value is calculated as the 99th percentile of all wet days of a given 30 year climate reference period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
262
263
264
static const char R99P_UNITS[]       = "Percent";

static const char R99PTOT_NAME[]     = "precipitation_percent_due_to_R99p_days";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
265
static const char R99PTOT_LONGNAME[] = "percentage of total  precipitation amount per time period due to extremely_wet_days_wrt_99th_percentile_of_reference_period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
266
//static const char R99PTOT_UNITS[]    = "Percent";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
267
268

static const char RR1_NAME[]         = "wet_days_index_per_time_period";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
269
static const char RR1_LONGNAME[]     = "Wet days index is the number of days per time period with daily precipitation of at least %g mm. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
270
271
272
static const char RR1_UNITS[]        = "No.";

static const char RX1DAY_NAME[]      = "highest_one_day_precipitation_amount_per_time_period";
273
static const char RX1DAY_NAME_ET[]   = "rx1dayETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
274
static const char RX1DAY_LONGNAME[]  = "Highest one day precipitation is the maximum of one day precipitation amount in a given time period. The time period should be defined by the bounds of the time coordinate.";
275
static const char RX1DAY_LONGNAME_ET[]= "Maximum 1-day Precipitation";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
276
static const char RX1DAY_UNITS[]     = "mm per day";
277
static const char RX1DAY_UNITS_ET[]  = "mm";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
278
279

static const char RX5DAY_NAME[]      = "highest_five_day_precipitation_amount_per_time_period";
280
static const char RX5DAY_NAME_ET[]   = "rx5dayETCCDI";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
281
static const char RX5DAY_LONGNAME[]  = "Highest precipitation amount for five day interval (including the calendar day as the last day). The time period should be defined by the bounds of the time coordinate.";
282
static const char RX5DAY_LONGNAME_ET[]= "Maximum Consecutive 5-day Precipitation";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
283
static const char RX5DAY_UNITS[]     = "mm per 5 day";
284
static const char RX5DAY_UNITS_ET[]  = "mm";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
285
286
287
288
static const char RX5DAY_NAME2[]     = "number_of_5day_heavy_precipitation_periods_per_time_period";
static const char RX5DAY_LONGNAME2[] = "Number of 5day periods in given time period with precipitation amount exceeding %1.0f mm / 5 days. The time period should be defined by the bounds of the time coordinate.";
static const char RX5DAY_UNITS2[]    = "No.";

289
static const char SDII_NAME[]        = "simple_daily_intensity_index_per_time_period";
290
static const char SDII_NAME_ET[]     = "sdiiETCCDI";
291
static const char SDII_LONGNAME[]    = "Simple daily intensity index is the mean of precipitation amount on wet days. A wet day is a day with precipitation sum of at least %g mm. The time period should be defined by the bounds of the time coordinate.";
292
static const char SDII_LONGNAME_ET[] = "Simple Precipitation Intensity Index";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
293
static const char SDII_UNITS[]       = "mm";
294
static const char SDII_UNITS_ET[]    = "mm d-1";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
295

Uwe Schulzweida's avatar
Uwe Schulzweida committed
296
297
static const char FDNS_NAME[]        = "frost_days_where_no_snow_index_per_time_period";
static const char FDNS_LONGNAME[]    = "Frost days where no snow index is the number of days without snowcover and where the minimum of temperature is below 0 degree Celsius. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
298
299
300
301
302
303
304
305
306
307
308
309
310
311
static const char FDNS_UNITS[]       = "No.";

static const char STRWIN_NAME[]      = "strong_wind_days_index_per_time_period";
static const char STRWIN_LONGNAME[]  = "Strong wind days index is the number of days per time period where maximum wind speed is above %1.0f m/s. The time period should be defined by the bounds of the time coordinate.";
static const char STRWIN_UNITS[]     = "No.";
static const char STRWIN_NAME2[]     = "consecutive_strong_wind_days_index_per_time_period";
static const char STRWIN_LONGNAME2[] = "Greatest number of consecutive strong wind days per time period. The time period should be defined by the bounds of the time coordinate.";
static const char STRWIN_UNITS2[]    = "No.";

static const char STRBRE_NAME[]      = "strong_breeze_days_index_per_time_period";
static const char STRBRE_LONGNAME[]  = "Strong breeze days index is the number of days per time period where maximum wind speed is above 10.5 m/s. The time period should be defined by the bounds of the time coordinate.";
static const char STRBRE_NAME2[]     = "consecutive_strong_breeze_days_index_per_time_period";
static const char STRBRE_LONGNAME2[] = "Greatest number of consecutive strong breeze days per time period. The time period should be defined by the bounds of the time coordinate.";

Uwe Schulzweida's avatar
Uwe Schulzweida committed
312
313
314
315
//static const char STRGAL_NAME[]      = "strong_gale_days_index_per_time_period";
//static const char STRGAL_LONGNAME[]  = "Strong gale days index is the number of days per time period where maximum wind speed is above 20.5 m/s. The time period should be defined by the bounds of the time coordinate.";
//static const char STRGAL_NAME2[]     = "consecutive_strong_gale_days_index_per_time_period";
//static const char STRGAL_LONGNAME2[] = "Greatest number of consecutive strong gale days per time period. The time period should be defined by the bounds of the time coordinate.";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
317
318
319
320

static const char HURR_NAME[]        = "hurricane_days_index_per_time_period";
static const char HURR_LONGNAME[]    = "Hurricane days index is the number of days per time period where maximum wind speed is above 32.5 m/s. The time period should be defined by the bounds of the time coordinate.";
static const char HURR_NAME2[]       = "consecutive_hurricane_days_index_per_time_period";
static const char HURR_LONGNAME2[]   = "Greatest number of consecutive hurricane days per time period. The time period should be defined by the bounds of the time coordinate.";
321

Uwe Schulzweida's avatar
Uwe Schulzweida committed
322
323
// clang-format on

324
325
/* ECA temperature indices */

326
static int addWithFrequency(std::vector<std::string> &params, const char *operatorName, size_t defaultDays)
327
328
{
  KVList kvlist;
329
  int opID = 0;
330
331
332
333
334
  if (kvlist.parseArguments(1, params) != 0) cdoAbort("Argument parse error!"); 
  auto kv = kvlist.search("freq");
  if (kv && kv->nvalues > 0 )
    { 
      if ( kv->values[0].compare("month") == 0 )
335
        opID = cdoOperatorAdd(operatorName, 0, 8, nullptr);
336
      else if ( kv->values[0].compare("year") == 0 )
337
        opID = cdoOperatorAdd(operatorName, 0, 10, nullptr);
338
339
      else
        cdoAbort("Frequency '%s' unknown.", kv->values[0]);
340
341
    }
  else
342
343
    opID = cdoOperatorAdd(operatorName, 0, defaultDays, nullptr);
  return opID;
344
}
345

346
void *EcaCfd(void *process)
347
348
{
  ECA_REQUEST_1 request;
349
350
351
  int ndays = 5;
  char cfd_longname2[1024];
  char cfd_name2[1024];
352
  
353
  cdoInitialize(process);
354
355
356
357
358
359

  if ( operatorArgc() > 2 ) cdoAbort("Too many arguments!");
  if ( operatorArgc() > 1 )
    {
      auto params = cdoGetOperArgv();
      params = std::vector<std::string>(params.begin() + 1, params.end());
360
      addWithFrequency(params, "eca_cfd", 31);
361
362
363
364
365
366
    }
  else
    {
      if ( operatorArgc() > 0 ) ndays = parameter2int(cdoOperatorArgv(0));
      cdoOperatorAdd("eca_cfd", 0, 31, nullptr);
    }
367
368
369
370

  sprintf(cfd_longname2, CFD_LONGNAME2, ndays);
  sprintf(cfd_name2,     CFD_NAME2, ndays);

371
372
  request.var1.name     = CFD_NAME;
  request.var1.longname = CFD_LONGNAME;
373
  request.var1.refdate  = 19550101;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
374
  request.var1.units    = nullptr;
375
  request.var1.f1       = vfarselltc;
376
  request.var1.f1arg    = TO_KELVIN(0.0);
377
378
  request.var1.f2       = vfarnum2;
  request.var1.f3       = vfarmax;
379
380
  request.var1.mulc     = 0.0;
  request.var1.addc     = 0.0;
381
  request.var1.epilog   = ECA_NONE;
382
383
  request.var2.name     = cfd_name2;
  request.var2.longname = cfd_longname2;
384
  request.var2.units    = CFD_UNITS2;
385
  request.var2.h1       = vfarseleqc;
386
  request.var2.h1arg    = ndays+1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
387
  request.var2.h2       = nullptr;
388
  request.var2.h3       = vfarnum;
389
390
391
392
   
  eca1(&request);
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
393
  return 0;
394
395
396
}


397
void *EcaCsu(void *process)
398
399
{
  ECA_REQUEST_1 request;
400
401
402
403
  double argT = 25.0;
  int ndays = 5;
  char csu_longname2[1024];
  char csu_name2[1024];
404
  
405
  cdoInitialize(process);
406

407
408
409
410
411
  if ( operatorArgc() > 3 ) cdoAbort("Too many arguments!");
  if ( operatorArgc() > 2 )
    {
      auto params = cdoGetOperArgv();
      params = std::vector<std::string>(params.begin() + 2, params.end());
412
      addWithFrequency(params, "eca_csu", 31);
413
    }
414
415
  else if ( operatorArgc() > 0 ) 
    {
416
      cdoOperatorAdd("eca_csu", 0, 31, nullptr);
417
418
      argT = parameter2double(cdoOperatorArgv(0));
      if ( operatorArgc() == 2 ) ndays = parameter2int(cdoOperatorArgv(1));
419
    }
420
421
  else
    cdoOperatorAdd("eca_csu", 0, 31, nullptr);
422
423
424
  
  sprintf(csu_longname2, CSU_LONGNAME2, ndays);
  sprintf(csu_name2,     CSU_NAME2, ndays);
425
426

  request.var1.name     = CSU_NAME;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
427
  request.var1.longname = CSU_LONGNAME;
428
  request.var1.refdate  = 19550101;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
429
  request.var1.units    = nullptr;
430
  request.var1.f1       = vfarselgtc;
431
  request.var1.f1arg    = TO_KELVIN(argT);
432
433
  request.var1.f2       = vfarnum2;
  request.var1.f3       = vfarmax;
434
435
  request.var1.mulc     = 0.0;
  request.var1.addc     = 0.0;
436
  request.var1.epilog   = ECA_NONE;
437
438
  request.var2.name     = csu_name2;
  request.var2.longname = csu_longname2;
439
  request.var2.units    = CSU_UNITS2;
440
  request.var2.h1       = vfarseleqc;
441
  request.var2.h1arg    = ndays+1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
442
  request.var2.h2       = nullptr;
443
  request.var2.h3       = vfarnum;
444
445
  
  eca1(&request);
446
  
447
448
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
449
  return 0;
450
451
452
}


453
void *EcaCwdi(void *process)
454
455
456
457
458
459
{
  char *longname;
  int argN = 6;
  double argT = 5.0;
  ECA_REQUEST_2 request;
  
460
  cdoInitialize(process);
461

462
463
464
465
  if ( operatorArgc() > 2 )
    {
      auto params = cdoGetOperArgv();
      params = std::vector<std::string>(params.begin() + 2, params.end());
466
      addWithFrequency(params, "eca_cwdi", 31);
467
468
469
470
471
472
473
474
475
476
      argT = parameter2double(cdoOperatorArgv(1));
      argN = parameter2int(cdoOperatorArgv(0));
    }
  else
    {
      if ( operatorArgc() > 1 ) argT = parameter2double(cdoOperatorArgv(1));
      else if ( operatorArgc() > 0 ) argN = parameter2int(cdoOperatorArgv(0));
      cdoOperatorAdd("eca_cwdi", 0, 31, nullptr);
    } 
 
477
  longname = (char*) Malloc(strlen(CWDI_LONGNAME) + 80);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
478
  sprintf(longname, CWDI_LONGNAME, argN, argT);
479
480
481

  request.var1.name     = CWDI_NAME;
  request.var1.longname = longname;
482
  request.var1.refdate  = 19550101;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
483
  request.var1.units    = CWDI_UNITS;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
484
  request.var1.f1       = nullptr;
485
  request.var1.f2       = vfarcsub;
486
  request.var1.f2arg    = argT;
487
488
489
  request.var1.f3       = vfarsellt;
  request.var1.f4       = vfarnum2;
  request.var1.f5       = vfarnum3;
490
  request.var1.f5arg    = argN;
491
  request.var1.epilog   = ECA_NONE;
492
493
  request.var2.name     = CWDI_NAME2;
  request.var2.longname = CWDI_LONGNAME2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
494
  request.var2.units    = CWDI_UNITS2;
495
  request.var2.h1       = vfarseleqc;
496
  request.var2.h1arg    = argN;
497
  request.var2.h2       = vfarnum;
498
499
500
   
  eca2(&request);
  
501
  Free(longname);
502
503
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
504
  return 0;
505
506
507
}


508
void *EcaCwfi(void *process)
509
510
511
512
{
  int argN = 6;
  ECA_REQUEST_2 request;
  
513
  cdoInitialize(process);
514

515
  int OPID_ECA = 0, OPID_ETC = 0;
516
517
518
519
  if ( operatorArgc() > 1 )
    {
      auto params = cdoGetOperArgv();
      params = std::vector<std::string>(params.begin() + 1, params.end());
520
521
      OPID_ECA = addWithFrequency(params, "eca_cwfi", 31);
      OPID_ETC = addWithFrequency(params, "etccdi_csdi", 10);
522
523
524
525
526
      argN = parameter2int(cdoOperatorArgv(0));
    }
  else
    {
      if ( operatorArgc() > 0 ) argN = parameter2int(cdoOperatorArgv(0));
527
528
      OPID_ECA = cdoOperatorAdd("eca_cwfi", 0, 31, nullptr);
      OPID_ETC = cdoOperatorAdd("etccdi_csdi", 0, 10, nullptr);
529
    }
530

531

532
  char *longname = (char*) Malloc(strlen(CWFI_LONGNAME) + 40);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
533
534
  sprintf(longname, CWFI_LONGNAME, argN);

535

Uwe Schulzweida's avatar
Uwe Schulzweida committed
536
  if (OPID_ECA == cdoOperatorID())
537
538
539
540
541
542
    {
      request.var1.name     = CWFI_NAME;
      request.var1.longname = longname;
      request.var1.refdate  = 19550101;
      request.var1.units    = CWFI_UNITS;
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
543
  else if (OPID_ETC == cdoOperatorID())
544
545
546
547
548
549
550
    {
      request.var1.name     = CWFI_NAME_ET;
      request.var1.longname = CWFI_LONGNAME_ET;
      request.var1.units    = CWFI_UNITS_ET;
      request.var1.refdate  = 18500101;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
551
  request.var1.units    = CWFI_UNITS;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
552
553
  request.var1.f1       = nullptr;
  request.var1.f2       = nullptr;
554
555
556
  request.var1.f3       = vfarsellt;
  request.var1.f4       = vfarnum2;
  request.var1.f5       = vfarnum3;
557
  request.var1.f5arg    = argN;
558
  request.var1.epilog   = ECA_NONE;
559
560
  request.var2.name     = CWFI_NAME2;
  request.var2.longname = CWFI_LONGNAME2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
561
  request.var2.units    = CWFI_UNITS2;
562
  request.var2.h1       = vfarseleqc;
563
  request.var2.h1arg    = argN;
564
  request.var2.h2       = vfarnum;
565
566
   
  eca2(&request);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
567
  
568
  Free(longname);
569
570
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
571
  return 0;
572
573
574
}


575
void *EcaEtr(void *process)
576
577
578
{
  ECA_REQUEST_3 request;
  
579
  cdoInitialize(process);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
580
  cdoOperatorAdd("eca_etr", 0, 31, nullptr);
581
582
583
  
  request.name     = ETR_NAME;
  request.longname = ETR_LONGNAME;
584
  request.refdate  = 19550101;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
585
  request.units    = nullptr;
586
587
588
  request.f1       = vfarmax; 
  request.f2       = vfarmin;
  request.f3       = vfarsub;
589
590
591
592
   
  eca3(&request);
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
593
  return 0;
594
595
596
}


597
void *EcaFd(void *process)
598
599
600
{
  ECA_REQUEST_1 request;
  
601
  cdoInitialize(process);
602

603
  int OPID_ECA = 0, OPID_ETC = 0;
604
605
606
  if ( operatorArgc() > 0 )
    {
      auto params = cdoGetOperArgv();
607
608
      OPID_ECA = addWithFrequency(params, "eca_fd", 31);
      OPID_ETC = addWithFrequency(params, "etccdi_fd", 10);
609
610
    }
  else
611
612
613
614
    {
      OPID_ECA = cdoOperatorAdd("eca_fd", 0, 31, nullptr);
      OPID_ETC = cdoOperatorAdd("etccdi_fd", 0, 10, nullptr);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
615

616
617
618
619
620
621
622
  if (  OPID_ECA == cdoOperatorID() ) 
    {
      request.var1.name     = FD_NAME;
      request.var1.longname = FD_LONGNAME;
      request.var1.refdate  = 19550101;
      request.var1.units    = nullptr;
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
623
  else if (OPID_ETC == cdoOperatorID())
624
625
626
627
628
629
    {
      request.var1.name     = FD_NAME_ET;
      request.var1.longname = FD_LONGNAME_ET;
      request.var1.refdate  = 18500101;
      request.var1.units    = FD_UNITS_ET;
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
630

631
  request.var1.f1       = vfarselltc; 
632
  request.var1.f1arg    = TO_KELVIN(0.0);
633
  request.var1.f2       = vfarnum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
634
  request.var1.f3       = nullptr;
635
636
  request.var1.mulc     = 0.0;    
  request.var1.addc     = 0.0;
637
  request.var1.epilog   = ECA_NONE;    
Uwe Schulzweida's avatar
Uwe Schulzweida committed
638
639
  request.var2.h2       = nullptr; 
  request.var2.h3       = nullptr; 
640
641
642
643
   
  eca1(&request);
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
644
  return 0;
645
646
647
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
648
/*
649
650
651
652
 * Definition of GSL: (Thermal) Growing Season Length start at the first span
 * of at least 6 (argN) days with T > 5.0°C (argT) in first half of the year
 * and ends at the first span of ar least 6 (argN) days with T < 5.0°C (argT)
 * in the second half.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
653
654
 * ATTENTION: Year of the northern hemisphere starts in january to
 * december, whereas for the southern hemisphere is goes from july to june!
655
656
 * Hence, at least 18 Month of data is needed for computing the gsl of the
 * whole earth.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
657
*/
658
void *EcaGsl(void *process)
659
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
660
  int argN = 6; 
661
  double argT = 5.0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662
  double minLandFraction = 0.5;
663
664
  ECA_REQUEST_4 request;
  
665
  cdoInitialize(process);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
666
  cdoOperatorAdd("eca_gsl", 0, 10, nullptr);
667
  
668
669
670
  if ( operatorArgc() > 0 ) argN = parameter2int(cdoOperatorArgv(0));
  if ( operatorArgc() > 1 ) argT = parameter2double(cdoOperatorArgv(1));
  if ( operatorArgc() > 2 ) minLandFraction = parameter2double(cdoOperatorArgv(2));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
671

672
  char *longname = (char*) Malloc(strlen(GSL_LONGNAME) + 160);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
673
  sprintf(longname, GSL_LONGNAME, argN, argT, argN, argT);
674

675
  request.name      = GSL_NAME;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
676
677
  request.longname  = longname;
  request.units     = GSL_UNITS;
678
679
  request.name2     = GSL_NAME2;
  request.longname2 = GSL_LONGNAME2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
680
  request.units2    = GSL_UNITS2;
681
  request.s1        = vfarselgtc; 
682
  request.s1arg     = TO_KELVIN(argT);
683
  request.s2        = vfarselltc;
684
  request.s2arg     = TO_KELVIN(argT);
685
  request.s3        = vfarselgec;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
686
  request.s3arg     = minLandFraction;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
687
  request.consecutiveDays = argN;    
688
689
   
  eca4(&request);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
690
  
691
  Free(longname);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
692

693
694
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
695
  return 0;
696
697
698
}


699
void *EcaHd(void *process)
700
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
701
702
  double argX = 17.0;
  double argA = 17.0;
703
704
  ECA_REQUEST_1 request;
  
705
  cdoInitialize(process);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
706
  cdoOperatorAdd("eca_hd", 0, 31, nullptr);
707
708
709

  if ( operatorArgc() > 0 ) 
    {
710
      argX = parameter2double(cdoOperatorArgv(0));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
711
      argA = argX;
712
713
    }
  if ( operatorArgc() > 1 ) 
714
    argA = parameter2double(cdoOperatorArgv(1));
715
716
717
  
  request.var1.name     = HD_NAME;
  request.var1.longname = HD_LONGNAME;
718
  request.var1.refdate  = 19550101;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
719
  request.var1.units    = HD_UNITS;
720
  request.var1.f1       = vfarselltc; 
Uwe Schulzweida's avatar
Uwe Schulzweida committed
721
  request.var1.f1arg    = TO_KELVIN(argA);
722
  request.var1.f2       = vfarsum;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
723
  request.var1.f3       = nullptr;
724
  request.var1.mulc     = -1.0;    
Uwe Schulzweida's avatar
Uwe Schulzweida committed
725
  request.var1.addc     = TO_KELVIN(argX);
726
  request.var1.epilog   = ECA_NONE;    
Uwe Schulzweida's avatar
Uwe Schulzweida committed
727
728
  request.var2.h2       = nullptr; 
  request.var2.h3       = nullptr; 
729
730
   
  eca1(&request);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
731

732
733
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
734
  return 0;
735
736
737
}


738
void *EcaHwdi(void *process)
739
740
741
742
743
{
  int argN = 6;
  double argT = 5.0;
  ECA_REQUEST_2 request;
  
744
  cdoInitialize(process);
745

746
747
748
749
  if ( operatorArgc() > 2 )
    {
      auto params = cdoGetOperArgv();
      params = std::vector<std::string>(params.begin() + 2, params.end());
750
      addWithFrequency(params, "eca_hwdi", 31);
751
752
753
754
755
756
757
758
759
      argN = parameter2int(cdoOperatorArgv(0));
      argT = parameter2double(cdoOperatorArgv(1));
    }
  else
    {
      if ( operatorArgc() > 0 ) argN = parameter2int(cdoOperatorArgv(0));
      if ( operatorArgc() > 1 ) argT = parameter2double(cdoOperatorArgv(1));
      cdoOperatorAdd("eca_hwdi", 0, 31, nullptr);
    }
760
  
761
  char *longname = (char*) Malloc(strlen(HWDI_LONGNAME) + 80);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
762
  sprintf(longname, HWDI_LONGNAME, argN, argT);
763
764
765
  
  request.var1.name     = HWDI_NAME;
  request.var1.longname = longname;
766
  request.var1.refdate  = 19550101;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
767
  request.var1.units    = HWDI_UNITS;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
768
  request.var1.f1       = nullptr;
769
  request.var1.f2       = vfarcadd;
770
  request.var1.f2arg    = argT;
771
772
773
  request.var1.f3       = vfarselgt;
  request.var1.f4       = vfarnum2;
  request.var1.f5       = vfarnum3;
774
  request.var1.f5arg    = argN;
775
  request.var1.epilog   = ECA_NONE;
776
777
  request.var2.name     = HWDI_NAME2;
  request.var2.longname = HWDI_LONGNAME2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
778
  request.var2.units    = HWDI_UNITS2;
779
  request.var2.h1       = vfarseleqc;
780
  request.var2.h1arg    = argN;
781
  request.var2.h2       = vfarnum;
782
783
784
   
  eca2(&request);
  
785
  Free(longname);
786
787
  cdoFinish();
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
788
  return 0;
789
790
791
}


792
void *EcaHwfi(void *process)
793
794
795
796
{
  int argN = 6;
  ECA_REQUEST_2 request;
  
797
  cdoInitialize(process);
798

799
  int OPID_ECA = 0, OPID_ETC = 0;
800
801
802
803
  if ( operatorArgc() > 1 )
    {
      auto params = cdoGetOperArgv();
      params = std::vector<std::string>(params.begin() + 1, params.end());
804
805
      OPID_ECA = addWithFrequency(params, "eca_hwfi", 31);
      OPID_ETC = addWithFrequency(params, "etccdi_wsdi", 10);
806
807
808
809
810
      argN = parameter2int(cdoOperatorArgv(0));
    }
  else
    {
      if ( operatorArgc() > 0 ) argN = parameter2int(cdoOperatorArgv(0));
811
812
      OPID_ECA = cdoOperatorAdd("eca_hwfi", 0, 31, nullptr);
      OPID_ETC = cdoOperatorAdd("etccdi_wsdi", 0, 10, nullptr);
813
    }
814

815
  char *longname = (char*) Malloc(strlen(HWFI_LONGNAME) + 40);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
816
817
  sprintf(longname, HWFI_LONGNAME, argN);

818
819
820
821
822
823
824
  if (  OPID_ECA == cdoOperatorID() ) 
    {
      request.var1.name     = HWFI_NAME;
      request.var1.longname = longname;
      request.var1.refdate  = 19550101;
      request.var1.units    = HWFI_UNITS;
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
825
  else if (OPID_ETC == cdoOperatorID())
826
827
828
829
830
831
832
    {
      request.var1.name     = HWFI_NAME_ET;
      request.var1.longname = HWFI_LONGNAME_ET;
      request.var1.refdate  = 18500101;
      request.var1.units    = HWFI_UNITS_ET;
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
833
834
  request.var1.f1       = nullptr;
  request.var1.f2       = nullptr;
835
836
837
  request.var1.f3       = vfarselgt;
  request.var1.f4       = vfarnum2;
  request.var1.f5       = vfarnum3;
838
  request.var1.f5arg    = argN;
839
  request.var1.epilog   = ECA_NONE;
840
841
  request.var2.name     = HWFI_NAME2;
  request.var2.longname = HWFI_LONGNAME2;