grid.h 6.44 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
65
struct gridaxis_t {
  char    name[CDI_MAX_NAME];
66
  char    longname[CDI_MAX_NAME];
67
  char    units[CDI_MAX_NAME];
68
  char    dimname[CDI_MAX_NAME];
69
  const char *stdname;
70
  size_t  size;                  // number of values
71
72
  short   flag;                  // 0: undefined 1:vals 2:first+inc
  double  first, last, inc;
73
  double *vals;
74
  double *bounds;
75
  cdi_keys_t  keys;
76
#ifndef USE_MPI
Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
78
  int clength;
  char  **cvals;
79
#endif
80
81
};

82
83
84
85
86
// GME Grid
struct grid_gme_t {
  int     nd, ni, ni2, ni3;       /* parameter for GRID_GME         */
};

87
struct grid_t {
88
89
  char    vdimname[CDI_MAX_NAME];
  char   *name;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
90
  int     self;
91
  size_t  size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
92
  int     type;                   /* grid type                      */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
93
  int     datatype;               /* grid data type                 */
94
  int     proj;                   /* grid projection                */
95
  int     projtype;               /* grid projection type           */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
96
97
  mask_t *mask;
  mask_t *mask_gme;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
  double *area;
99
  struct grid_gme_t  gme;
100
  int     number, position;       /* parameter for GRID_REFERENCE   */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
101
102
  int     trunc;                  /* parameter for GRID_SPECTEAL    */
  int     nvertex;
103
104
  char   *reference;
  unsigned char uuid[CDI_UUID_SIZE]; /* uuid for grid reference        */
105
  int    *reducedPoints;
106
  int     reducedPointsSize;
107
  int     np;                     /* number of parallels between a pole and the equator */
108
109
110
111
112
  signed char isCyclic;           /* three possible states:
                                   * -1 if unknown,
                                   * 0 if found not cyclic, or
                                   * 1 for global cyclic grids
                                   */
113
114
  bool    lcomplex;
  bool    hasdims;
115
116
  struct gridaxis_t x;
  struct gridaxis_t y;
117
  const struct gridVirtTable *vtable;
118
119
  cdi_keys_t  keys;
  cdi_atts_t  atts;
120
  int  scanningMode;
Thomas Jahns's avatar
Thomas Jahns committed
121
  bool iScansNegatively, jScansPositively, jPointsAreConsecutive;
122
123
124
125
126
127
  /* 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)        */
128
};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
129
130


Uwe Schulzweida's avatar
Uwe Schulzweida committed
131
void grid_init(grid_t *gridptr);
132
void cdiGridTypeInit(grid_t *gridptr, int gridtype, size_t size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
133
void grid_free(grid_t *gridptr);
134
grid_t *grid_to_pointer(int gridID);
135
extern const struct gridVirtTable cdiGridVtable;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
136

Thomas Jahns's avatar
Thomas Jahns committed
137
unsigned cdiGridCount(void);
138

139
140
void gridVerifyProj(int gridID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
141
142
143
const double *gridInqXvalsPtr(int gridID);
const double *gridInqYvalsPtr(int gridID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
144
145
146
const char **gridInqXCvalsPtr(int gridID);
const char **gridInqYCvalsPtr(int gridID);

147
148
const double *gridInqXboundsPtr(int gridID);
const double *gridInqYboundsPtr(int gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
149
150
const double *gridInqAreaPtr(int gridID);

151
152
const char *gridInqReferencePtr(int gridID);

153
int gridGenerate(const grid_t *grid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
154

155
156
//int gridIsEqual(int gridID1, int gridID2);

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

159
160
void
gridUnpack(char * unpackBuffer, int unpackBufferSize,
161
           int * unpackBufferPos, int originNamespace, void *context,
162
163
           int force_id);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
164
struct addIfNewRes
165
166
167
168
169
{
  int Id;
  int isNew;
};

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

Thomas Jahns's avatar
Thomas Jahns committed
172
int gridVerifyGribParamLCC(double missval, double *lon_0, double *lat_0, double *lat_1, double *lat_2,
173
                           double *a, double *rf, double *xval_0, double *yval_0, double *x_0, double *y_0);
174
175
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);
176

177
178
bool isGaussGrid(size_t ysize, double yinc, const double *yvals);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
179
#endif
180
181
182
183
184
185
186
187
188
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */