grid.h 5.15 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
8
#include "vlist_att.h"

Uwe Schulzweida's avatar
Uwe Schulzweida committed
9
typedef unsigned char mask_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
10

11
12
13
14
15
typedef struct grid_t grid_t;

struct gridVirtTable
{
  void (*destroy)(grid_t *gridptr);
Thomas Jahns's avatar
Thomas Jahns committed
16
17
18
  grid_t *(*copy)(grid_t *gridptr);
  void (*copyScalarFields)(grid_t *gridptrOrig, grid_t *gridptrDup);
  void (*copyArrayFields)(grid_t *gridptrOrig, grid_t *gridptrDup);
19
20
21
22
23
24
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);
  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);
32
  /* return if for both grids, all xval and all yval are equal */
33
  bool (*compareXYFull)(grid_t *gridRef, grid_t *gridTest);
34
35
  /* return if for both grids, x[0], y[0], x[size-1] and y[size-1] are
   * respectively equal */
36
  bool (*compareXYAO)(grid_t *gridRef, grid_t *gridTest);
37
  void (*inqArea)(grid_t *gridptr, double *area);
38
  const double *(*inqAreaPtr)(grid_t *gridptr);
Thomas Jahns's avatar
Thomas Jahns committed
39
  int (*hasArea)(grid_t *gridptr);
40
41
42
43
44
45
46
47
  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);
};

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

61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Lambert Conformal Conic
struct grid_lcc_t {
  double  originLon;
  double  originLat;
  double  lonParY;
  double  lat1;
  double  lat2;
  double  xinc;
  double  yinc;
  int     projflag;
  int     scanflag;
  short   defined;
};

75
76
77
78
79
80
81
// Lambert Conformal Conic 2
struct grid_lcc2_t {
  double  lon_0;
  double  lat_0;
  double  lat_1;
  double  lat_2;
  double  a;
82
  short   defined;
83
84
};

85
86
87
88
89
90
91
92
// Lambert Azimuthal Equal Area
struct grid_laea_t {
  double  lon_0;
  double  lat_0;
  double  a;
  short   defined;
};

93
94
95
96
97
// GME Grid
struct grid_gme_t {
  int     nd, ni, ni2, ni3;       /* parameter for GRID_GME         */
};

Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
99
100
101
102
// Rotated LonLat
struct grid_rll_t {
  double  xpole, ypole, angle;    /* rotated north pole             */
};

103
struct grid_t {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
104
105
106
  int     self;
  int     type;                   /* grid type                      */
  int     prec;                   /* grid precision                 */
107
  int     proj;                   /* grid projection                */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
108
109
  mask_t *mask;
  mask_t *mask_gme;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
  double *area;
111
  struct grid_lcc_t  lcc;
112
  struct grid_lcc2_t lcc2;
113
  struct grid_laea_t laea;
114
  struct grid_gme_t  gme;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
115
  struct grid_rll_t  rll;
116
117
  short   isCyclic;               /* TRUE for global cyclic grids   */
  short   isRotated;              /* TRUE for rotated grids         */
118
  int     number, position;       /* parameter for GRID_REFERENCE   */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
120
  int     trunc;                  /* parameter for GRID_SPECTEAL    */
  int     nvertex;
121
122
  char   *reference;
  unsigned char uuid[CDI_UUID_SIZE]; /* uuid for grid reference        */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
124
125
  int    *rowlon;
  int     nrowlon;
  int     size;
126
  int     np;                     /* number of parallels between a pole and the equator */
127
128
  bool    lcomplex;
  bool    hasdims;
129
  char    vdimname[CDI_MAX_NAME];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
  char    mapname[CDI_MAX_NAME];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
131
  char    mapping[CDI_MAX_NAME];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
  char   *name;
133
134
  struct gridaxis_t x;
  struct gridaxis_t y;
135
  const struct gridVirtTable *vtable;
136
  cdi_atts_t atts;
137
};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
138
139


Uwe Schulzweida's avatar
Uwe Schulzweida committed
140
void grid_init(grid_t *gridptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
141
void cdiGridTypeInit(grid_t *gridptr, int gridtype, int size);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
142
void grid_free(grid_t *gridptr);
143
grid_t *gridID2Ptr(int gridID);
144
extern const struct gridVirtTable cdiGridVtable;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
145

Thomas Jahns's avatar
Thomas Jahns committed
146
unsigned cdiGridCount(void);
147

Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
149
150
const double *gridInqXvalsPtr(int gridID);
const double *gridInqYvalsPtr(int gridID);

151
152
const double *gridInqXboundsPtr(int gridID);
const double *gridInqYboundsPtr(int gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
153
154
const double *gridInqAreaPtr(int gridID);

155
156
157
const char *gridInqXnamePtr(int gridID);
const char *gridInqYnamePtr(int gridID);

158
159
const char *gridInqReferencePtr(int gridID);

160
int gridGenerate(const grid_t *grid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
161

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

164
165
void
gridUnpack(char * unpackBuffer, int unpackBufferSize,
166
           int * unpackBufferPos, int originNamespace, void *context,
167
168
           int force_id);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
struct addIfNewRes
170
171
172
173
174
{
  int Id;
  int isNew;
};

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

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