grid.h 6.4 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_att.h"
8

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

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

16
17
18
19
20
typedef struct grid_t grid_t;

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

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

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

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


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

Thomas Jahns's avatar
Thomas Jahns committed
133
unsigned cdiGridCount(void);
134

135
136
void gridVerifyProj(int gridID);

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

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

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

147
148
const char *gridInqReferencePtr(int gridID);

149
int gridGenerate(const grid_t *grid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
150

151
152
//int gridIsEqual(int gridID1, int gridID2);

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

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

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

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

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

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:
 */