gribapi.h 4.87 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
#ifndef _GRIBAPI_H
#define _GRIBAPI_H

4
#ifdef HAVE_LIBGRIB_API
5
#include <grib_api.h>
6
#ifndef  ERROR_H
7
8
#include "error.h"
#endif
9
10
#endif

11
#ifndef  _CDI_INT_H
12
#include "cdi_int.h"
13
#endif
14

Uwe Schulzweida's avatar
Uwe Schulzweida committed
15
16
#define  GRIBAPI_MISSVAL  -9.E33

Uwe Schulzweida's avatar
Uwe Schulzweida committed
17
18
/* GRIB2 Level Types */
#define  GRIB2_LTYPE_SURFACE               1
19
20
#define  GRIB2_LTYPE_CLOUD_BASE            2
#define  GRIB2_LTYPE_CLOUD_TOP             3
21
#define  GRIB2_LTYPE_ISOTHERM0             4
22
#define  GRIB2_LTYPE_TOA                   8
23
24
#define  GRIB2_LTYPE_SEA_BOTTOM            9
#define  GRIB2_LTYPE_ATMOSPHERE           10
Uwe Schulzweida's avatar
Uwe Schulzweida committed
25
26
27
28
29
30
31
32
#define  GRIB2_LTYPE_ISOBARIC            100
#define  GRIB2_LTYPE_MEANSEA             101
#define  GRIB2_LTYPE_ALTITUDE            102
#define  GRIB2_LTYPE_HEIGHT              103
#define  GRIB2_LTYPE_SIGMA               104
#define  GRIB2_LTYPE_HYBRID              105
#define  GRIB2_LTYPE_LANDDEPTH           106
#define  GRIB2_LTYPE_ISENTROPIC          107
33
#define  GRIB2_LTYPE_SNOW                114
Uwe Schulzweida's avatar
Uwe Schulzweida committed
34
#define  GRIB2_LTYPE_REFERENCE           150
35
36
37
38
39
40
#define  GRIB2_LTYPE_SEADEPTH            160  /* Depth Below Sea Level                                 */
#define  GRIB2_LTYPE_LAKE_BOTTOM         162  /* Lake or River Bottom                                  */
#define  GRIB2_LTYPE_SEDIMENT_BOTTOM     163  /* Bottom Of Sediment Layer                              */
#define  GRIB2_LTYPE_SEDIMENT_BOTTOM_TA  164  /* Bottom Of Thermally Active Sediment Layer             */
#define  GRIB2_LTYPE_SEDIMENT_BOTTOM_TW  165  /* Bottom Of Sediment Layer Penetrated By Thermal Wave   */
#define  GRIB2_LTYPE_MIX_LAYER           166  /* Mixing Layer                                          */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
41

Uwe Schulzweida's avatar
Uwe Schulzweida committed
42
/* GRIB2 Data representation type (Grid Type) */
43
44
45
46
47
48
49
50
51
52
53
#define  GRIB2_GTYPE_LATLON                0  /*  latitude/longitude                                   */
#define  GRIB2_GTYPE_LATLON_ROT            1  /*  rotated latitude/longitude                           */
#define  GRIB2_GTYPE_LATLON_STR            2  /*  stretched latitude/longitude                         */
#define  GRIB2_GTYPE_LATLON_ROTSTR         3  /*  rotated and stretched latitude/longitude             */
#define  GRIB2_GTYPE_GAUSSIAN             40  /*  gaussian grid                                        */
#define  GRIB2_GTYPE_GAUSSIAN_ROT         41  /*  rotated gaussian grid                                */
#define  GRIB2_GTYPE_GAUSSIAN_STR         42  /*  stretched gaussian grid                              */
#define  GRIB2_GTYPE_GAUSSIAN_ROTSTR      43  /*  rotated and stretched gaussian grid                  */
#define  GRIB2_GTYPE_LCC                  30  /*  Lambert conformal                                    */
#define  GRIB2_GTYPE_SPECTRAL             50  /*  spherical harmonics                                  */
#define  GRIB2_GTYPE_GME                 100  /*  hexagonal GME grid                                   */
54
#define  GRIB2_GTYPE_UNSTRUCTURED        101  /*  General Unstructured Grid                            */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
55

56
const char *gribapiLibraryVersionString(void);
57
58
void gribContainersNew(stream_t * streamptr);
void gribContainersDelete(stream_t * streamptr);
59

60
#ifdef HAVE_LIBGRIB_API
61
62
static inline void *gribHandleNew(int editionNumber)
{
63
  void *gh = (void *)grib_handle_new_from_samples(NULL, (editionNumber == 1) ? "GRIB1" : "GRIB2");
64
65

  if ( gh == NULL ) Error("grib_handle_new_from_samples failed!");
66

67
68
69
  return gh;
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
70
71
72
73
74
static inline int my_grib_set_double(grib_handle* h, const char* key, double val)
{
  if ( cdiGribApiDebug )
    fprintf(stderr, "grib_set_double(\tgrib_handle* h, \"%s\", %f)\n", key, val);

75
76
77
78
  int ret_val = grib_set_double(h, key, val);
  if (ret_val != 0)
    fprintf(stderr, "!!! failed call to grib_set_double(\tgrib_handle* h, \"%s\", %f) !!!\n", key, val);
  return ret_val;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
79
80
81
82
83
84
85
}

static inline int my_grib_set_long(grib_handle* h, const char* key, long val)
{
  if ( cdiGribApiDebug )
    fprintf(stderr, "grib_set_long(  \tgrib_handle* h, \"%s\", %ld)\n", key, val);

86
87
88
89
  int ret_val = grib_set_long(h, key, val);
  if (ret_val != 0)
    fprintf(stderr, "!!! failed call to grib_set_long(  \tgrib_handle* h, \"%s\", %ld) !!!\n", key, val);
  return ret_val;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
90
91
92
93
94
95
96
}

static inline int my_grib_set_string(grib_handle* h, const char* key, const char* val, size_t* length)
{
  if ( cdiGribApiDebug )
    fprintf(stderr, "grib_set_string(\tgrib_handle* h, \"%s\", \"%s\")\n", key, val);

97
98
99
100
  int ret_val = grib_set_string(h, key, val, length);
  if (ret_val != 0)
    fprintf(stderr, "!!! grib_set_string(\tgrib_handle* h, \"%s\", \"%s\") !!!\n", key, val);
  return ret_val;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
101
102
}

103
104
static inline void gribHandleDelete(void *gh)
{
105
  grib_handle_delete((struct grib_handle *)gh);
106
107
108
109
110
}
#else
#define gribHandleNew(editionNumber) (NULL)
#define gribHandleDelete(gh)
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
111

Uwe Schulzweida's avatar
Uwe Schulzweida committed
112
typedef struct {
113
  bool init;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
114
115
116
117
  void *gribHandle;
}
gribContainer_t;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
#endif  /* _GRIBAPI_H */
119
120
121
122
123
124
125
126
127
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */