grid.h 6.21 KB
Newer Older
1
2
#ifndef  GRID_H
#define  GRID_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
3

4
#include "cdi.h"
5
#include <stdbool.h>
6

7
#include "cdi_key.h"
8
#include "cdi_att.h"
9

10
extern int (*proj_lonlat_to_lcc_func)();
11
extern int (*proj_lcc_to_lonlat_func)();
12
13
extern int (*proj_lonlat_to_stere_func)();
extern int (*proj_stere_to_lonlat_func)();
14

Uwe Schulzweida's avatar
Uwe Schulzweida committed
15
typedef unsigned char mask_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
16

17
18
19
20
21
typedef struct grid_t grid_t;

struct gridVirtTable
{
  void (*destroy)(grid_t *gridptr);
Thomas Jahns's avatar
Thomas Jahns committed
22
23
24
  grid_t *(*copy)(grid_t *gridptr);
  void (*copyScalarFields)(grid_t *gridptrOrig, grid_t *gridptrDup);
  void (*copyArrayFields)(grid_t *gridptrOrig, grid_t *gridptrDup);
25
26
27
28
29
30
31
  void (*defXVals)(grid_t *gridptr, const double *xvals);
  void (*defYVals)(grid_t *gridptr, const double *yvals);
  void (*defMask)(grid_t *gridptr, const int *mask);
  void (*defMaskGME)(grid_t *gridptr, const int *mask);
  void (*defXBounds)(grid_t *gridptr, const double *xbounds);
  void (*defYBounds)(grid_t *gridptr, const double *ybounds);
  void (*defArea)(grid_t *gridptr, const double *area);
32
33
  double (*inqXVal)(grid_t *gridptr, size_t index);
  double (*inqYVal)(grid_t *gridptr, size_t index);
34
  size_t (*inqXVals)(grid_t *gridptr, double *xvals);
35
  size_t (*inqXValsPart)(grid_t *gridptr, int start, size_t length, double *xvals);
36
  size_t (*inqYVals)(grid_t *gridptr, double *yvals);
37
  size_t (*inqYValsPart)(grid_t *gridptr, int start, size_t length, double *yvals);
38
39
  const double *(*inqXValsPtr)(grid_t *gridptr);
  const double *(*inqYValsPtr)(grid_t *gridptr);
40
41
42
43
44
45
#ifndef USE_MPI
  int (*inqXIsc)(grid_t *gridptr);
  int (*inqYIsc)(grid_t *gridptr);
  size_t (*inqXCvals)(grid_t *gridptr, char **xcvals);
  size_t (*inqYCvals)(grid_t *gridptr, char **ycvals);
  const char **(*inqXCvalsPtr)(grid_t *gridptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
46
  const char **(*inqYCvalsPtr)(grid_t *gridptr);
47
#endif
48
  /* return if for both grids, all xval and all yval are equal */
49
  bool (*compareXYFull)(grid_t *gridRef, grid_t *gridTest);
50
51
  /* return if for both grids, x[0], y[0], x[size-1] and y[size-1] are
   * respectively equal */
52
  bool (*compareXYAO)(grid_t *gridRef, grid_t *gridTest);
53
  void (*inqArea)(grid_t *gridptr, double *area);
54
  const double *(*inqAreaPtr)(grid_t *gridptr);
Thomas Jahns's avatar
Thomas Jahns committed
55
  int (*hasArea)(grid_t *gridptr);
56
  size_t (*inqMask)(grid_t *gridptr, int *mask);
57
  int (*inqMaskGME)(grid_t *gridptr, int *mask_gme);
58
59
  size_t (*inqXBounds)(grid_t *gridptr, double *xbounds);
  size_t (*inqYBounds)(grid_t *gridptr, double *ybounds);
60
61
62
63
  const double *(*inqXBoundsPtr)(grid_t *gridptr);
  const double *(*inqYBoundsPtr)(grid_t *gridptr);
};

64
struct gridaxis_t {
65
  const char *stdname;
66
  size_t  size;                  // number of values
67
68
  short   flag;                  // 0: undefined 1:vals 2:first+inc
  double  first, last, inc;
69
  double *vals;
70
  double *bounds;
71
  cdi_keys_t  keys;
72
#ifndef USE_MPI
Uwe Schulzweida's avatar
Uwe Schulzweida committed
73
74
  int clength;
  char  **cvals;
75
#endif
76
77
};

78
79
80
81
82
// GME Grid
struct grid_gme_t {
  int     nd, ni, ni2, ni3;       /* parameter for GRID_GME         */
};

83
struct grid_t {
84
  char   *name;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
85
  int     self;
86
  size_t  size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
87
  int     type;                   /* grid type                      */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
  int     datatype;               /* grid data type                 */
89
  int     proj;                   /* grid projection                */
90
  int     projtype;               /* grid projection type           */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
91
92
  mask_t *mask;
  mask_t *mask_gme;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
93
  double *area;
94
  struct grid_gme_t  gme;
95
  int     number, position;       /* parameter for GRID_REFERENCE   */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
96
97
  int     trunc;                  /* parameter for GRID_SPECTEAL    */
  int     nvertex;
98
  char   *reference;
99
  int    *reducedPoints;
100
  int     reducedPointsSize;
101
  int     np;                     /* number of parallels between a pole and the equator */
102
103
104
105
106
  signed char isCyclic;           /* three possible states:
                                   * -1 if unknown,
                                   * 0 if found not cyclic, or
                                   * 1 for global cyclic grids
                                   */
107
108
  bool    lcomplex;
  bool    hasdims;
109
110
  struct gridaxis_t x;
  struct gridaxis_t y;
111
  const struct gridVirtTable *vtable;
112
113
  cdi_keys_t  keys;
  cdi_atts_t  atts;
114
  int  scanningMode;
Thomas Jahns's avatar
Thomas Jahns committed
115
  bool iScansNegatively, jScansPositively, jPointsAreConsecutive;
116
117
118
119
120
121
  /* scanningMode  = 128 * iScansNegatively + 64 * jScansPositively + 32 * jPointsAreConsecutive;
               64  = 128 * 0                + 64 *        1         + 32 * 0
               00  = 128 * 0                + 64 *        0         + 32 * 0
               96  = 128 * 0                + 64 *        1         + 32 * 1
     Default / implicit scanning mode is 64:
                        i and j scan positively, i points are consecutive (row-major)        */
122
};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
124


Uwe Schulzweida's avatar
Uwe Schulzweida committed
125
void grid_init(grid_t *gridptr);
126
void cdiGridTypeInit(grid_t *gridptr, int gridtype, size_t size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
127
void grid_free(grid_t *gridptr);
128
grid_t *grid_to_pointer(int gridID);
129
extern const struct gridVirtTable cdiGridVtable;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130

Thomas Jahns's avatar
Thomas Jahns committed
131
unsigned cdiGridCount(void);
132

133
134
void gridVerifyProj(int gridID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
135
136
137
const double *gridInqXvalsPtr(int gridID);
const double *gridInqYvalsPtr(int gridID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
138
139
140
const char **gridInqXCvalsPtr(int gridID);
const char **gridInqYCvalsPtr(int gridID);

141
142
const double *gridInqXboundsPtr(int gridID);
const double *gridInqYboundsPtr(int gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
143
144
const double *gridInqAreaPtr(int gridID);

145
146
const char *gridInqReferencePtr(int gridID);

147
int gridGenerate(const grid_t *grid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148

149
150
//int gridIsEqual(int gridID1, int gridID2);

Thomas Jahns's avatar
Thomas Jahns committed
151
void cdiGridGetIndexList(unsigned, int * );
Uwe Schulzweida's avatar
Uwe Schulzweida committed
152

153
154
void
gridUnpack(char * unpackBuffer, int unpackBufferSize,
155
           int * unpackBufferPos, int originNamespace, void *context,
156
157
           int force_id);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
158
struct addIfNewRes
159
160
161
162
163
{
  int Id;
  int isNew;
};

Uwe Schulzweida's avatar
Uwe Schulzweida committed
164
struct addIfNewRes cdiVlistAddGridIfNew(int vlistID, grid_t *grid, int mode);
165

Thomas Jahns's avatar
Thomas Jahns committed
166
int gridVerifyGribParamLCC(double missval, double *lon_0, double *lat_0, double *lat_1, double *lat_2,
167
                           double *a, double *rf, double *xval_0, double *yval_0, double *x_0, double *y_0);
168
169
int gridVerifyGribParamSTERE(double missval, double *lon_0, double *lat_ts, double *lat_0,
                             double *a, double *xval_0, double *yval_0, double *x_0, double *y_0);
170

171
172
bool isGaussGrid(size_t ysize, double yinc, const double *yvals);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
173
#endif
174
175
176
177
178
179
180
181
182
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */