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


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

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

138
139
void gridVerifyProj(int gridID);

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

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

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

150
151
const char *gridInqReferencePtr(int gridID);

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

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

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

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

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

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

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

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

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