Ydrunstat.cc 13.6 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
Uwe Schulzweida's avatar
Uwe Schulzweida committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  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.
*/

/*
   This module contains the following operators:

      Ydrunstat    ydrunmin          Multi-year daily running minimum
      Ydrunstat    ydrunmax          Multi-year daily running maximum
      Ydrunstat    ydrunsum          Multi-year daily running sum
      Ydrunstat    ydrunmean         Multi-year daily running mean
      Ydrunstat    ydrunavg          Multi-year daily running average
Uwe Schulzweida's avatar
Uwe Schulzweida committed
26
      Ydrunstat    ydrunvar          Multi-year daily running variance
Uwe Schulzweida's avatar
Uwe Schulzweida committed
27
      Ydrunstat    ydrunvar1         Multi-year daily running variance [Normalize by (n-1)]
Uwe Schulzweida's avatar
Uwe Schulzweida committed
28
      Ydrunstat    ydrunstd          Multi-year daily running standard deviation
Uwe Schulzweida's avatar
Uwe Schulzweida committed
29
      Ydrunstat    ydrunstd1         Multi-year daily running standard deviation [Normalize by (n-1)]
Uwe Schulzweida's avatar
Uwe Schulzweida committed
30
31
*/

Ralf Mueller's avatar
Ralf Mueller committed
32
#include <cdi.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
33
34
#include "cdo.h"
#include "cdo_int.h"
35
#include "calendar.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
#include "pstream.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
37

Uwe Schulzweida's avatar
Uwe Schulzweida committed
38
39
40

#define NDAY 373

41
42
43
44
45
typedef struct {
  short varID;
  short levelID;
} recinfo_t;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
46
47

typedef struct {
48
49
  int       vdate[NDAY];
  int       vtime[NDAY];  
50
51
  field_type **vars1[NDAY]; 
  field_type **vars2[NDAY];
52
53
  int       nsets[NDAY];
  int       vlist;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
54
55
56
57
58
59
60
}
YDAY_STATS;


static YDAY_STATS *ydstatCreate(int vlistID);
static void ydstatDestroy(YDAY_STATS *stats);
static void ydstatUpdate(YDAY_STATS *stats, int vdate, int vtime, 
61
                         field_type **vars1, field_type **vars2, int nsets, int operfunc);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
62
63
64
65
66
67
static void ydstatFinalize(YDAY_STATS *stats, int operfunc);


void *Ydrunstat(void *argument)
{
  int varID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
  int nrecs;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
69
70
  int levelID;
  int tsID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
71
  int inp, its;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
72
73
74
75
76
77
78
  int nmiss;
    
  cdoInitialize(argument);

  cdoOperatorAdd("ydrunmin",  func_min,  0, NULL);
  cdoOperatorAdd("ydrunmax",  func_max,  0, NULL);
  cdoOperatorAdd("ydrunsum",  func_sum,  0, NULL);
79
  cdoOperatorAdd("ydrunmean", func_mean, 0, NULL);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
  cdoOperatorAdd("ydrunavg",  func_avg,  0, NULL);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
  cdoOperatorAdd("ydrunvar",  func_var,  0, NULL);
82
  cdoOperatorAdd("ydrunvar1", func_var1, 0, NULL);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
83
  cdoOperatorAdd("ydrunstd",  func_std,  0, NULL);
84
  cdoOperatorAdd("ydrunstd1", func_std1, 0, NULL);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
85

Uwe Schulzweida's avatar
Uwe Schulzweida committed
86
87
  int operatorID = cdoOperatorID();
  int operfunc = cdoOperatorF1(operatorID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
89

  operatorInputArg("number of timesteps");
90
  int ndates = parameter2int(operatorArgv()[0]);
91

92
  bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
93
  
Uwe Schulzweida's avatar
Uwe Schulzweida committed
94
  int streamID1 = streamOpenRead(cdoStreamName(0));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
95

Uwe Schulzweida's avatar
Uwe Schulzweida committed
96
97
  int vlistID1 = streamInqVlist(streamID1);
  int vlistID2 = vlistDuplicate(vlistID1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
98

Uwe Schulzweida's avatar
Uwe Schulzweida committed
99
100
  int taxisID1 = vlistInqTaxis(vlistID1);
  int taxisID2 = taxisDuplicate(taxisID1);
101
  if ( taxisHasBounds(taxisID2) ) taxisDeleteBounds(taxisID2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
102
103
  vlistDefTaxis(vlistID2, taxisID2);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
104
105
  int calendar = taxisInqCalendar(taxisID1);
  int dpy      = calendar_dpy(calendar);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
106

Uwe Schulzweida's avatar
Uwe Schulzweida committed
107
  int streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
Uwe Schulzweida's avatar
Uwe Schulzweida committed
108
109
110

  streamDefVlist(streamID2, vlistID2);

111
  int maxrecs = vlistNrecs(vlistID1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
112

113
  recinfo_t *recinfo = (recinfo_t *) Malloc(maxrecs*sizeof(recinfo_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
114

115
  cdo_datetime_t *datetime = (cdo_datetime_t*) Malloc((ndates+1)*sizeof(cdo_datetime_t));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
  
117
  YDAY_STATS *stats = ydstatCreate(vlistID1);
118
119
  field_type ***vars1 = (field_type ***) Malloc((ndates+1)*sizeof(field_type **));
  field_type ***vars2 = NULL;
120
  if ( lvarstd )
121
    vars2 = (field_type ***) Malloc((ndates+1)*sizeof(field_type **));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
122
123
124
  
  for ( its = 0; its < ndates; its++ )
    {
125
      vars1[its] = field_malloc(vlistID1, FIELD_PTR);
126
      if ( lvarstd )
127
	vars2[its] = field_malloc(vlistID1, FIELD_PTR);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
128
129
130
131
132
133
134
135
136
137
138
    }
  
  for ( tsID = 0; tsID < ndates; tsID++ )
    {
      nrecs = streamInqTimestep(streamID1, tsID);
      if ( nrecs == 0 )
	cdoAbort("File has less then %d timesteps!", ndates);

      datetime[tsID].date = taxisInqVdate(taxisID1);
      datetime[tsID].time = taxisInqVtime(taxisID1);
	
139
      for ( int recID = 0; recID < nrecs; recID++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
140
141
142
143
144
	{
	  streamInqRecord(streamID1, &varID, &levelID);

	  if ( tsID == 0 )
	    {
145
146
              recinfo[recID].varID   = varID;
              recinfo[recID].levelID = levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
147
148
	    }
	  
149
          field_type *pvars1 = &vars1[tsID][varID][levelID];
150
          field_type *pvars2 = (vars2 && vars2[tsID]) ? &vars2[tsID][varID][levelID] : NULL;
151
152
153

	  streamReadRecord(streamID1, pvars1->ptr, &nmiss);
	  pvars1->nmiss = nmiss;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
154

155
	  if ( lvarstd )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
	    {
157
	      farmoq(pvars2, *pvars1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
158
159
	      for ( inp = 0; inp < tsID; inp++ )
		{
160
161
		  farsumq(&vars2[inp][varID][levelID], *pvars1);
		  farsum(&vars1[inp][varID][levelID], *pvars1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
162
163
164
165
166
167
		}
	    }
	  else
	    {
	      for ( inp = 0; inp < tsID; inp++ )
		{
168
		  farfun(&vars1[inp][varID][levelID], *pvars1, operfunc);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
170
171
172
173
174
175
176
177
		}
	    }
	}
    }
  
  while ( TRUE )
    {
      datetime_avg(dpy, ndates, datetime);
      
178
179
      int vdate = datetime[ndates].date;
      int vtime = datetime[ndates].time;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
180
      
181
      if ( lvarstd )   
Uwe Schulzweida's avatar
Uwe Schulzweida committed
182
183
184
185
186
187
        ydstatUpdate(stats, vdate, vtime, vars1[0], vars2[0], ndates, operfunc);
      else
        ydstatUpdate(stats, vdate, vtime, vars1[0], NULL, ndates, operfunc);
        
      datetime[ndates] = datetime[0];
      vars1[ndates] = vars1[0];
188
      if ( lvarstd )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
190
191
192
193
194
        vars2[ndates] = vars2[0];

      for ( inp = 0; inp < ndates; inp++ )
	{
	  datetime[inp] = datetime[inp+1];
	  vars1[inp] = vars1[inp+1];
195
	  if ( lvarstd )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
196
197
198
199
200
201
202
203
204
	    vars2[inp] = vars2[inp+1];
	}

      nrecs = streamInqTimestep(streamID1, tsID);
      if ( nrecs == 0 ) break;

      datetime[ndates-1].date = taxisInqVdate(taxisID1);
      datetime[ndates-1].time = taxisInqVtime(taxisID1);

205
      for ( int recID = 0; recID < nrecs; recID++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
206
207
208
	{
	  streamInqRecord(streamID1, &varID, &levelID);
	  
209
          field_type *pvars1 = &vars1[ndates-1][varID][levelID];
210
          field_type *pvars2 = (vars2 && vars2[ndates-1]) ? &vars2[ndates-1][varID][levelID] : NULL;
211
212
213

	  streamReadRecord(streamID1, pvars1->ptr, &nmiss);
	  pvars1->nmiss = nmiss;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
214

215
	  if ( lvarstd )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
216
217
218
	    {
	      for ( inp = 0; inp < ndates-1; inp++ )
		{
219
220
		  farsumq(&vars2[inp][varID][levelID], *pvars1);
		  farsum(&vars1[inp][varID][levelID], *pvars1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
221
		}
222
	      farmoq(pvars2, *pvars1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
223
224
225
226
227
	    }
	  else
	    {
	      for ( inp = 0; inp < ndates-1; inp++ )
		{
228
		  farfun(&vars1[inp][varID][levelID], *pvars1, operfunc);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
229
230
231
232
233
234
235
		}
	    }
	}

      tsID++;
    }

236
237
  /*
  // set the year to the minimum of years found on output timestep
238
  int outyear = 1e9;
239
  int year, month, day;
240
  for ( int dayoy = 0; dayoy < NDAY; dayoy++ )
241
242
243
244
245
    if ( stats->nsets[dayoy] )
      {
	cdiDecodeDate(stats->vdate[dayoy], &year, &month, &day);
	if ( year < outyear ) outyear = year;
      }
246
  for ( int dayoy = 0; dayoy < NDAY; dayoy++ )
247
248
249
    if ( stats->nsets[dayoy] )
      {
	cdiDecodeDate(stats->vdate[dayoy], &year, &month, &day);
250
251
        // printf("vdates[%d] = %d  nsets = %d\n", dayoy, stats->vdate[dayoy], stats->nsets[dayoy]);
	if ( year > outyear ) stats->vdate[dayoy] = cdiEncodeDate(outyear, month, day);
252
      }
253
  */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
254
  ydstatFinalize(stats, operfunc);
255

256
  int otsID = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
257

258
  for ( int dayoy = 0; dayoy < NDAY; dayoy++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
259
260
261
262
    if ( stats->nsets[dayoy] )
      {
	taxisDefVdate(taxisID2, stats->vdate[dayoy]);
	taxisDefVtime(taxisID2, stats->vtime[dayoy]);
263
	streamDefTimestep(streamID2, otsID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
264

265
266
267
268
269
        for ( int recID = 0; recID < maxrecs; recID++ )
          {
            int varID   = recinfo[recID].varID;
            int levelID = recinfo[recID].levelID;
            field_type *pvars1 = &stats->vars1[dayoy][varID][levelID];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
270

Uwe Schulzweida's avatar
Uwe Schulzweida committed
271
	    if ( otsID && vlistInqVarTsteptype(vlistID1, varID) == TSTEP_CONSTANT ) continue;
272
273

	    streamDefRecord(streamID2, varID, levelID);
274
	    streamWriteRecord(streamID2, pvars1->ptr, pvars1->nmiss);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
275
	  }
276
277

	otsID++;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
278
279
280
281
      }
  
  for ( its = 0; its < ndates; its++ )
    {
282
283
      field_free(vars1[its], vlistID1);
      if ( lvarstd ) field_free(vars2[its], vlistID1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
284
285
286
    }
  
  ydstatDestroy(stats);
287
288
  Free(vars1);
  if ( lvarstd ) Free(vars2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
289

290
  if ( datetime ) Free(datetime);
291

292
  Free(recinfo);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
293
294
295
296
297
298

  streamClose(streamID2);
  streamClose(streamID1);

  cdoFinish();

Uwe Schulzweida's avatar
Uwe Schulzweida committed
299
  return 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
300
301
}

302
303
static
YDAY_STATS *ydstatCreate(int vlistID)
304
{  
305
  YDAY_STATS *stats = (YDAY_STATS*) Malloc(sizeof(YDAY_STATS));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
306
  
307
  for ( int dayoy = 0; dayoy < NDAY; dayoy++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
308
309
310
311
312
313
314
    {
      stats->vdate[dayoy] = 0;
      stats->vtime[dayoy] = 0;
      stats->vars1[dayoy] = NULL;
      stats->vars2[dayoy] = NULL;
      stats->nsets[dayoy] = 0;
    }
315

Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
317
318
319
320
  stats->vlist = vlistID;
  
  return stats;
}

321
322
static
void ydstatDestroy(YDAY_STATS *stats)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
323
{
324
  int varID, levelID, nlevels;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
325
326
327
  
  if ( stats != NULL )
    {
328
      int nvars = vlistNvars(stats->vlist);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
329
      
330
      for ( int dayoy = 0; dayoy < NDAY; dayoy++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
331
332
333
334
335
336
337
        {
          if ( stats->vars1[dayoy] != NULL )
            {
              for ( varID = 0; varID < nvars; varID++ )
                {
              	  nlevels = zaxisInqSize(vlistInqVarZaxis(stats->vlist, varID));
              	  for ( levelID = 0; levelID < nlevels; levelID++ )
338
339
              	    Free(stats->vars1[dayoy][varID][levelID].ptr);
              	  Free(stats->vars1[dayoy][varID]);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
340
                }
341
              Free(stats->vars1[dayoy]);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
342
343
344
345
346
347
348
            }
          if ( stats->vars2[dayoy] != NULL )
            {
              for ( varID = 0; varID < nvars; varID++ )
                {
              	  nlevels = zaxisInqSize(vlistInqVarZaxis(stats->vlist, varID));
              	  for ( levelID = 0; levelID < nlevels; levelID++ )
349
350
              	    Free(stats->vars2[dayoy][varID][levelID].ptr);
              	  Free(stats->vars2[dayoy][varID]);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
351
                }
352
              Free(stats->vars2[dayoy]);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
353
354
            }
        }
355
      Free(stats);    
Uwe Schulzweida's avatar
Uwe Schulzweida committed
356
357
358
    }
}

359
360
static
void ydstatUpdate(YDAY_STATS *stats, int vdate, int vtime, 
361
		  field_type **vars1, field_type **vars2, int nsets, int operfunc)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
362
363
{
  int varID, levelID, nvars, nlevels;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
364
  int gridsize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
365
  int year, month, day, dayoy;
366

367
  bool lvarstd = vars2 != NULL;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
369

  nvars = vlistNvars(stats->vlist);
370
371

  cdiDecodeDate(vdate, &year, &month, &day);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
372
373
374
375
376
377
378
379
380
381
382
383
384
385

  if ( month >= 1 && month <= 12 )
    dayoy = (month - 1) * 31 + day;
  else
    dayoy = 0;

  if ( dayoy < 0 || dayoy >= NDAY )
    cdoAbort("day %d out of range!", dayoy);

  stats->vdate[dayoy] = vdate;
  stats->vtime[dayoy] = vtime;

  if ( stats->vars1[dayoy] == NULL )
    {
386
      stats->vars1[dayoy] = field_malloc(stats->vlist, FIELD_PTR);
387
      if ( lvarstd )
388
	stats->vars2[dayoy] = field_malloc(stats->vlist, FIELD_PTR);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
389
390
391
392
    }

  for ( varID = 0; varID  < nvars; varID++ )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
393
      if ( vlistInqVarTsteptype(stats->vlist, varID) == TSTEP_CONSTANT ) continue;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
395
396
397
398
399
400
401
402
403
404
        
      gridsize = gridInqSize(vlistInqVarGrid(stats->vlist, varID));
      nlevels  = zaxisInqSize(vlistInqVarZaxis(stats->vlist, varID));
          
      for ( levelID = 0; levelID < nlevels; levelID++ )
        {
	  if ( stats->nsets[dayoy] == 0 )
	    {
	      memcpy(stats->vars1[dayoy][varID][levelID].ptr, vars1[varID][levelID].ptr, gridsize * sizeof(double));
	      stats->vars1[dayoy][varID][levelID].nmiss = vars1[varID][levelID].nmiss;
	       
405
	      if ( lvarstd )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
406
407
408
409
410
411
412
	        {
	          memcpy(stats->vars2[dayoy][varID][levelID].ptr, vars2[varID][levelID].ptr, gridsize * sizeof(double));
	          stats->vars2[dayoy][varID][levelID].nmiss = vars2[varID][levelID].nmiss;
	        }
	    }
	  else
	    {
413
	      if ( lvarstd )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
	        {
		  farsum(&stats->vars1[dayoy][varID][levelID], vars1[varID][levelID]);
		  farsum(&stats->vars2[dayoy][varID][levelID], vars2[varID][levelID]);
		}
	      else
		{
	          farfun(&stats->vars1[dayoy][varID][levelID], vars1[varID][levelID], operfunc);
		}
	    }
        }
    }

  stats->nsets[dayoy] += nsets;
}

429
430
static
void ydstatFinalize(YDAY_STATS *stats, int operfunc)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
431
432
433
{
  int varID, levelID, nvars, nlevels;
  int dayoy;
Uwe Schulzweida's avatar
cleanup    
Uwe Schulzweida committed
434
  int divisor = operfunc == func_std1 || operfunc == func_var1;
435

Uwe Schulzweida's avatar
Uwe Schulzweida committed
436
437
438
439
440
441
442
  nvars = vlistNvars(stats->vlist);
  
  for ( dayoy = 0; dayoy < NDAY; dayoy++ )
    if ( stats->nsets[dayoy] )
      {
      	switch ( operfunc )
      	  {
443
	    case func_avg:
444
	    case func_mean:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
445
446
	      for ( varID = 0; varID < nvars; varID++ )
	        {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
447
	          if ( vlistInqVarTsteptype(stats->vlist, varID) == TSTEP_CONSTANT ) continue;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
448
449
	          nlevels = zaxisInqSize(vlistInqVarZaxis(stats->vlist, varID));
	          for ( levelID = 0; levelID < nlevels; levelID++ )
450
		    farcdiv(&stats->vars1[dayoy][varID][levelID], (double) stats->nsets[dayoy]);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
451
452
453
454
	        }
	      break;
	      
	    case func_std:
455
	    case func_std1:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
456
457
	      for ( varID = 0; varID < nvars; varID++ )
	        {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
458
	          if ( vlistInqVarTsteptype(stats->vlist, varID) == TSTEP_CONSTANT ) continue;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
459
460
	          nlevels = zaxisInqSize(vlistInqVarZaxis(stats->vlist, varID));
	          for ( levelID = 0; levelID < nlevels; levelID++ )
461
462
		    farcstd(&stats->vars1[dayoy][varID][levelID], stats->vars2[dayoy][varID][levelID],
                            stats->nsets[dayoy], divisor);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
463
464
	        }
	      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
465
466
	      
	    case func_var:
467
	    case func_var1:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
468
469
	      for ( varID = 0; varID < nvars; varID++ )
	        {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
470
	          if ( vlistInqVarTsteptype(stats->vlist, varID) == TSTEP_CONSTANT ) continue;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
471
472
	          nlevels = zaxisInqSize(vlistInqVarZaxis(stats->vlist, varID));
	          for ( levelID = 0; levelID < nlevels; levelID++ )
473
		    farcvar(&stats->vars1[dayoy][varID][levelID], stats->vars2[dayoy][varID][levelID],
474
			    stats->nsets[dayoy], divisor);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
475
476
	        }
	      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
477
478
479
      	  }
      }
}