grid.h 5.75 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
struct gridaxis_t {
65
  const char *stdname;
66
67
68
69
70
  size_t      size;                  // number of values
  short       flag;                  // 0: undefined 1:vals 2:first+inc
  double      first, last, inc;
  double     *vals;
  double     *bounds;
71
  cdi_keys_t  keys;
72
#ifndef USE_MPI
73
74
  int         clength;
  char       **cvals;
75
#endif
76
77
};

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

83
struct grid_t {
84
  char   *name;
85
86
87
88
89
90
91
92
93
  int         self;
  size_t      size;
  int         type;                   /* grid type                      */
  int         datatype;               /* grid data type                 */
  int         proj;                   /* grid projection                */
  int         projtype;               /* grid projection type           */
  mask_t     *mask;
  mask_t     *mask_gme;
  double     *area;
94
  struct grid_gme_t  gme;
95
96
97
98
99
100
101
102
103
104
105
106
107
  int         trunc;                  /* parameter for GRID_SPECTRAL    */
  int         nvertex;
  char       *reference;
  int        *reducedPoints;
  int         reducedPointsSize;
  int         np;                     /* number of parallels between a pole and the equator */
  signed char isCyclic;               /* three possible states:
                                       * -1 if unknown,
                                       *  0 if found not cyclic, or
                                       *  1 for global cyclic grids
                                       */
  bool        lcomplex;
  bool        hasdims;
108
109
  struct gridaxis_t x;
  struct gridaxis_t y;
110
  const struct gridVirtTable *vtable;
111
112
  cdi_keys_t  keys;
  cdi_atts_t  atts;
113
  int         scanningMode;
114
};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
115
116


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

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

125
126
void gridVerifyProj(int gridID);

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
131
132
const char **gridInqXCvalsPtr(int gridID);
const char **gridInqYCvalsPtr(int gridID);

133
134
const double *gridInqXboundsPtr(int gridID);
const double *gridInqYboundsPtr(int gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
135
136
const double *gridInqAreaPtr(int gridID);

137
138
const char *gridInqReferencePtr(int gridID);

139
int gridGenerate(const grid_t *grid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
140

141
142
//int gridIsEqual(int gridID1, int gridID2);

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

145
146
void
gridUnpack(char * unpackBuffer, int unpackBufferSize,
147
           int * unpackBufferPos, int originNamespace, void *context,
148
149
           int force_id);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
150
struct addIfNewRes
151
152
153
154
155
{
  int Id;
  int isNew;
};

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

Thomas Jahns's avatar
Thomas Jahns committed
158
int gridVerifyGribParamLCC(double missval, double *lon_0, double *lat_0, double *lat_1, double *lat_2,
159
                           double *a, double *rf, double *xval_0, double *yval_0, double *x_0, double *y_0);
160
161
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);
162

163
164
bool isGaussGrid(size_t ysize, double yinc, const double *yvals);

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