grid.h 5.3 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
10
extern double grid_missval;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
11
typedef unsigned char mask_t;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
12

13
14
15
16
17
typedef struct grid_t grid_t;

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

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

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

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


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

Thomas Jahns's avatar
Thomas Jahns committed
120
unsigned cdiGridCount(void);
121

122
123
void gridVerifyProj(int gridID);

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

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

131
132
const char *gridInqReferencePtr(int gridID);

133
int gridGenerate(const grid_t *grid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
134

135
136
//int gridIsEqual(int gridID1, int gridID2);

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

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

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
152
#endif
153
154
155
156
157
158
159
160
161
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */