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

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

7
#include "cdi_att.h"
8

9
extern double grid_missval;
10
extern int (*proj_lonlat_to_lcc_func)();
11
extern int (*proj_lcc_to_lonlat_func)();
12

Uwe Schulzweida's avatar
Uwe Schulzweida committed
13
typedef unsigned char mask_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
14

15
16
17
18
19
typedef struct grid_t grid_t;

struct gridVirtTable
{
  void (*destroy)(grid_t *gridptr);
Thomas Jahns's avatar
Thomas Jahns committed
20
21
22
  grid_t *(*copy)(grid_t *gridptr);
  void (*copyScalarFields)(grid_t *gridptrOrig, grid_t *gridptrDup);
  void (*copyArrayFields)(grid_t *gridptrOrig, grid_t *gridptrDup);
23
24
25
26
27
28
29
30
31
32
  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);
  double (*inqXVal)(grid_t *gridptr, int index);
  double (*inqYVal)(grid_t *gridptr, int index);
  int (*inqXVals)(grid_t *gridptr, double *xvals);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
33
34
  int (*inqXCvals)(grid_t *gridptr, char **xcvals);
  int (*inqXIsc)(grid_t *gridptr);
35
  int (*inqYVals)(grid_t *gridptr, double *yvals);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
37
  int (*inqYCvals)(grid_t *gridptr, char **ycvals);
  int (*inqYIsc)(grid_t *gridptr);
38
  const double *(*inqXValsPtr)(grid_t *gridptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
39
  const char **(*inqXCvalsPtr)(grid_t *gridptr);
40
  const double *(*inqYValsPtr)(grid_t *gridptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
41
  const char **(*inqYCvalsPtr)(grid_t *gridptr);
42
  /* return if for both grids, all xval and all yval are equal */
43
  bool (*compareXYFull)(grid_t *gridRef, grid_t *gridTest);
44
45
  /* return if for both grids, x[0], y[0], x[size-1] and y[size-1] are
   * respectively equal */
46
  bool (*compareXYAO)(grid_t *gridRef, grid_t *gridTest);
47
  void (*inqArea)(grid_t *gridptr, double *area);
48
  const double *(*inqAreaPtr)(grid_t *gridptr);
Thomas Jahns's avatar
Thomas Jahns committed
49
  int (*hasArea)(grid_t *gridptr);
50
51
52
53
54
55
56
57
  int (*inqMask)(grid_t *gridptr, int *mask);
  int (*inqMaskGME)(grid_t *gridptr, int *mask_gme);
  int (*inqXBounds)(grid_t *gridptr, double *xbounds);
  int (*inqYBounds)(grid_t *gridptr, double *ybounds);
  const double *(*inqXBoundsPtr)(grid_t *gridptr);
  const double *(*inqYBoundsPtr)(grid_t *gridptr);
};

58
59
struct gridaxis_t {
  char    name[CDI_MAX_NAME];
60
  char    longname[CDI_MAX_NAME];
61
  char    units[CDI_MAX_NAME];
62
  char    dimname[CDI_MAX_NAME];
63
  const char *stdname;
64
  int     size;                  // number of values
65
66
  short   flag;                  // 0: undefined 1:vals 2:first+inc
  double  first, last, inc;
67
  double *vals;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
69
  int clength;
  char  **cvals;
70
  double *bounds;
71
72
};

73
74
75
76
77
// GME Grid
struct grid_gme_t {
  int     nd, ni, ni2, ni3;       /* parameter for GRID_GME         */
};

78
struct grid_t {
79
80
81
82
  char    vdimname[CDI_MAX_NAME];
  char    mapname[CDI_MAX_NAME];
  char    mapping[CDI_MAX_NAME];
  char   *name;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
83
  int     self;
Thomas Jahns's avatar
Thomas Jahns committed
84
  int     size;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
85
86
  int     type;                   /* grid type                      */
  int     prec;                   /* grid precision                 */
87
  int     proj;                   /* grid projection                */
88
  int     projtype;               /* grid projection type           */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
90
  mask_t *mask;
  mask_t *mask_gme;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
91
  double *area;
92
  struct grid_gme_t  gme;
93
  int     number, position;       /* parameter for GRID_REFERENCE   */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
94
95
  int     trunc;                  /* parameter for GRID_SPECTEAL    */
  int     nvertex;
96
97
  char   *reference;
  unsigned char uuid[CDI_UUID_SIZE]; /* uuid for grid reference        */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
99
  int    *rowlon;
  int     nrowlon;
100
  int     np;                     /* number of parallels between a pole and the equator */
101
102
103
104
105
  signed char isCyclic;           /* three possible states:
                                   * -1 if unknown,
                                   * 0 if found not cyclic, or
                                   * 1 for global cyclic grids
                                   */
106
107
  bool    lcomplex;
  bool    hasdims;
108
  bool uvRelativeToGrid;  /* Some models deliver wind U,V relative to the grid-cell */
109
110
  struct gridaxis_t x;
  struct gridaxis_t y;
111
  const struct gridVirtTable *vtable;
112
  cdi_atts_t atts;
113
  int  scanningMode;
Thomas Jahns's avatar
Thomas Jahns committed
114
  bool iScansNegatively, jScansPositively, jPointsAreConsecutive;
115
116
117
118
119
120
  /* 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)        */
121
};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
122
123


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

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

132
133
void gridVerifyProj(int gridID);

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

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

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

144
145
const char *gridInqReferencePtr(int gridID);

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

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

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

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

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

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
168
#endif
169
170
171
172
173
174
175
176
177
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */