1 /*
2 This file is part of CDO. CDO is a collection of Operators to manipulate and analyse Climate model Data.
3
4 Author: Uwe Schulzweida
5
6 */
7
8 #include "process_int.h"
9 #include "cdo_zaxis.h"
10 #include <mpim_grid.h>
11
12 void
fld_field_init(Field & field,size_t nmiss,double missval,size_t ngp,double * array,double * w)13 fld_field_init(Field &field, size_t nmiss, double missval, size_t ngp, double *array, double *w)
14 {
15 field.size = ngp;
16 field.nmiss = nmiss;
17 field.missval = missval;
18 if (array != nullptr)
19 for (size_t i = 0; i < ngp; ++i) field.vec_d[i] = array[i];
20 if (w != nullptr)
21 for (size_t i = 0; i < ngp; ++i) field.weightv[i] = w[i];
22 }
23 /*
24 double *
25 fld_weights(int gridID, size_t ngp)
26 {
27 static bool lwarn = true;
28 double *weights = (double *) Malloc(ngp * sizeof(double));
29 for (size_t i = 0; i < ngp; ++i) weights[i] = 1;
30
31 if (ngp > 1)
32 {
33 int wstatus = gridWeights(gridID, weights);
34 if (wstatus != 0 && lwarn)
35 {
36 lwarn = false;
37 cdo_warning("Grid cell bounds not available, using constant grid cell area weights!");
38 }
39 }
40
41 return weights;
42 }
43 */
44
45 void
vert_weights(int zaxisID,size_t nlev,Varray<double> & weights)46 vert_weights(int zaxisID, size_t nlev, Varray<double> &weights)
47 {
48 weights.resize(nlev);
49 std::vector<double> thickness(nlev);
50 for (size_t i = 0; i < nlev; ++i) weights[i] = 1;
51
52 if (nlev > 1)
53 {
54 static bool lwarn = true;
55 int wstatus = get_layer_thickness(1, 0, 0, zaxisID, nlev, thickness.data(), weights.data());
56 if (wstatus == 0 && lwarn && nlev > 1)
57 {
58 lwarn = false;
59 cdo_warning("Layer bounds not available, using constant vertical weights!");
60 }
61 }
62 }
63