grid.h 5.6 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
33
34
35
  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);
  int (*inqYVals)(grid_t *gridptr, double *yvals);
  const double *(*inqXValsPtr)(grid_t *gridptr);
  const double *(*inqYValsPtr)(grid_t *gridptr);
36
  /* return if for both grids, all xval and all yval are equal */
37
  bool (*compareXYFull)(grid_t *gridRef, grid_t *gridTest);
38
39
  /* return if for both grids, x[0], y[0], x[size-1] and y[size-1] are
   * respectively equal */
40
  bool (*compareXYAO)(grid_t *gridRef, grid_t *gridTest);
41
  void (*inqArea)(grid_t *gridptr, double *area);
42
  const double *(*inqAreaPtr)(grid_t *gridptr);
Thomas Jahns's avatar
Thomas Jahns committed
43
  int (*hasArea)(grid_t *gridptr);
44
45
46
47
48
49
50
51
  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);
};

52
53
struct gridaxis_t {
  char    name[CDI_MAX_NAME];
54
  char    longname[CDI_MAX_NAME];
55
  char    units[CDI_MAX_NAME];
56
  char    dimname[CDI_MAX_NAME];
57
  const char *stdname;
58
  int     size;                  // number of values
59
60
  short   flag;                  // 0: undefined 1:vals 2:first+inc
  double  first, last, inc;
61
  double *vals;
62
  double *bounds;
63
64
};

65
66
67
68
69
// GME Grid
struct grid_gme_t {
  int     nd, ni, ni2, ni3;       /* parameter for GRID_GME         */
};

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
void grid_init(grid_t *gridptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
void cdiGridTypeInit(grid_t *gridptr, int gridtype, int size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
void grid_free(grid_t *gridptr);
119
grid_t *grid_to_pointer(int gridID);
120
extern const struct gridVirtTable cdiGridVtable;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
121

Thomas Jahns's avatar
Thomas Jahns committed
122
unsigned cdiGridCount(void);
123

124
125
void gridVerifyProj(int gridID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
126
127
128
const double *gridInqXvalsPtr(int gridID);
const double *gridInqYvalsPtr(int gridID);

129
130
const double *gridInqXboundsPtr(int gridID);
const double *gridInqYboundsPtr(int gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
131
132
const double *gridInqAreaPtr(int gridID);

133
134
const char *gridInqReferencePtr(int gridID);

135
int gridGenerate(const grid_t *grid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
136

137
138
//int gridIsEqual(int gridID1, int gridID2);

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

141
142
void
gridUnpack(char * unpackBuffer, int unpackBufferSize,
143
           int * unpackBufferPos, int originNamespace, void *context,
144
145
           int force_id);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
146
struct addIfNewRes
147
148
149
150
151
{
  int Id;
  int isNew;
};

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

154
155
156
int gridVerifyGribParamLCC(int gridID, double missval, double *lon_0, double *lat_0, double *lat_1, double *lat_2,
                           double *a, double *rf, double *xval_0, double *yval_0, double *x_0, double *y_0);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
157
#endif
158
159
160
161
162
163
164
165
166
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */