NCEPLIBS-g2c  1.7.0
grib2.h
Go to the documentation of this file.
1 
17 #ifndef _grib2_H
18 #define _grib2_H
19 #include <stdio.h>
20 #include <stdint.h>
21 
22 #define G2_VERSION "1.7.0"
24 #define G2_PNG_ENABLED 1
25 #define G2_JPEG2000_ENABLED 1
28 typedef int64_t g2int;
29 
32 typedef uint64_t g2intu;
33 
36 typedef float g2float;
37 
41 struct gribfield
42 {
45 
49 
97 
100 
103  unsigned char *local;
104 
107 
110 
117 
120 
125 
130 
136 
141 
145 
149 
153 
157 
161 
165 
168 
172  float *coord_list;
173 
176 
180 
183 
187 
191 
200 
208 
212 
214  float *fld;
215 };
216 
217 typedef struct gribfield gribfield;
219 /* Prototypes for unpacking sections API */
220 g2int g2_unpack1(unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen);
221 g2int g2_unpack2(unsigned char *cgrib, g2int *iofst, g2int *lencsec2,
222  unsigned char **csec2);
223 g2int g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl,
224  g2int *mapgridlen, g2int **ideflist, g2int *idefnum);
225 g2int g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl,
226  g2int *mappdslen, float **coordlist, g2int *numcoord);
227 g2int g2_unpack5(unsigned char *cgrib, g2int *iofst, g2int *ndpts, g2int *idrsnum,
228  g2int **idrstmpl, g2int *mapdrslen);
229 g2int g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap,
230  g2int **bmap);
231 g2int g2_unpack7(unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstmpl,
232  g2int idrsnum, g2int *idrstmpl, g2int ndpts, float **fld);
233 
234 /* Prototypes for unpacking API */
235 void seekgb(FILE *lugb, g2int iseek, g2int mseek, g2int *lskip,
236  g2int *lgrib);
237 g2int g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1,
238  g2int *numfields, g2int *numlocal);
239 g2int g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand,
240  gribfield **gfld);
241 void g2_free(gribfield *gfld);
242 
243 /* Prototypes for packing API */
244 g2int g2_create(unsigned char *cgrib, g2int *listsec0, g2int *listsec1);
245 g2int g2_addlocal(unsigned char *cgrib, unsigned char *csec2, g2int lcsec2);
246 g2int g2_addgrid(unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist,
247  g2int idefnum);
248 g2int g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl,
249  float *coordlist, g2int numcoord, g2int idrsnum, g2int *idrstmpl,
250  float *fld, g2int ngrdpts, g2int ibmap, g2int *bmap);
251 g2int g2_gribend(unsigned char *cgrib);
252 
253 /* Compression. */
254 void pngpack(float *fld, g2int width, g2int height, g2int *idrstmpl,
255  unsigned char *cpack, g2int *lcpack);
256 g2int pngunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
257  float *fld);
258 void pngpackd(double *fld, g2int width, g2int height, g2int *idrstmpl,
259  unsigned char *cpack, g2int *lcpack);
260 g2int pngunpackd(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
261  double *fld);
262 void jpcpack(float *fld, g2int width, g2int height, g2int *idrstmpl,
263  unsigned char *cpack, g2int *lcpack);
264 g2int jpcunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
265  float *fld);
266 void jpcpackd(double *fld, g2int width, g2int height, g2int *idrstmpl,
267  unsigned char *cpack, g2int *lcpack);
268 g2int jpcunpackd(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
269  double *fld);
270 
271 /* Logging, for debugging purposes. */
272 int g2c_set_log_level(int new_level);
273 
274 /* Error codes for G2 API. */
275 #define G2_NO_ERROR 0
276 #define G2_CREATE_GRIB_VERSION -1
277 #define G2_INFO_NO_GRIB 1
278 #define G2_INFO_GRIB_VERSION 2
279 #define G2_INFO_NO_SEC1 3
280 #define G2_INFO_WRONG_END 4
281 #define G2_INFO_BAD_END 5
282 #define G2_INFO_INVAL_SEC 6
283 #define G2_GETFLD_NO_GRIB 1
284 #define G2_GETFLD_GRIB_VERSION 2
285 #define G2_GETFLD_INVAL 3
286 #define G2_GETFLD_WRONG_END 4
287 #define G2_GETFLD_WRONG_NFLDS 6
288 #define G2_GETFLD_BAD_END 7
289 #define G2_GETFLD_INVAL_SEC 8
290 #define G2_GETFLD_NO_DRT 9
291 #define G2_GETFLD_BAD_SEC1 15
292 #define G2_GETFLD_BAD_SEC2 16
293 #define G2_GETFLD_BAD_SEC3 10
294 #define G2_GETFLD_BAD_SEC4 11
295 #define G2_GETFLD_BAD_SEC5 12
296 #define G2_GETFLD_BAD_SEC6 13
297 #define G2_GETFLD_BAD_SEC7 14
298 #define G2_GETFLD_NO_BITMAP 17
299 #define G2_GRIBEND_MSG_INIT -1
300 #define G2_BAD_SEC -4
301 #define G2_UNPACK_BAD_SEC 2
302 #define G2_UNPACK_NO_MEM 6
303 #define G2_UNPACK3_BAD_GDT 5
304 #define G2_UNPACK4_BAD_PDT 5
305 #define G2_UNPACK5_BAD_DRT 7
306 #define G2_UNPACK6_BAD_BITMAP 4
307 #define G2_UNPACK7_CORRUPT_SEC 7
308 #define G2_UNPACK7_WRONG_GDT 5
309 #define G2_UNPACK7_BAD_DRT 4
310 #define G2_ADD_MSG_INIT -1
311 #define G2_ADD_MSG_COMPLETE -2
312 #define G2_BAD_SEC_COUNTS -3
313 #define G2_ADDFIELD_BAD_PDT -5
314 #define G2_ADDFIELD_BAD_GDS -6
315 #define G2_ADDFIELD_BAD_DRT -7
316 #define G2_ADDFIELD_BAD_BITMAP -8
317 #define G2_ADDFIELD_BAD_GDT -9
318 #define G2_ADDFIELD_ERR -10
319 #define G2_ADDGRID_BAD_GDT -5
320 #define G2_JPCUNPACK_MEM 1
321 #define G2_SPECUNPACK_TYPE -3
322 #define G2_JASPER_INIT -2
323 #define G2_JASPER_ENCODE -3
324 #define G2_JASPER_DECODE -3
325 #define G2_JASPER_DECODE_COLOR -5
327 /* These are the new error codes. */
328 #define G2C_NO_ERROR 0
329 #define G2C_NOT_GRIB -50
330 #define G2C_MSG_COMPLETE -51
332 #endif /* _grib2_H */
g2_unpack1
g2int g2_unpack1(unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen)
This subroutine unpacks Section 1 - Identification Section as defined in GRIB Edition 2.
Definition: g2_unpack1.c:55
g2_create
g2int g2_create(unsigned char *cgrib, g2int *listsec0, g2int *listsec1)
This routine initializes a new GRIB2 message and packs GRIB2 Section 0 (Indicator Section) and Sectio...
Definition: g2_create.c:68
gribfield::igdtmpl
g2int * igdtmpl
Contains the data values for the Grid Definition Template specified by igdtnum.
Definition: grib2.h:152
pngunpack
g2int pngunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld)
This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB...
Definition: pngunpack.c:105
g2_unpack5
g2int g2_unpack5(unsigned char *cgrib, g2int *iofst, g2int *ndpts, g2int *idrsnum, g2int **idrstmpl, g2int *mapdrslen)
This subroutine unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2.
Definition: g2_unpack5.c:42
g2float
float g2float
Float type.
Definition: grib2.h:36
jpcpackd
void jpcpackd(double *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a data field into a JPEG2000 code stream.
Definition: jpcpack.c:294
g2_unpack7
g2int g2_unpack7(unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstmpl, g2int idrsnum, g2int *idrstmpl, g2int ndpts, float **fld)
This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2.
Definition: g2_unpack7.c:55
gribfield::ngrdpts
g2int ngrdpts
Number of grid points in the defined grid.
Definition: grib2.h:119
gribfield::unpacked
g2int unpacked
Logical value indicating whether the bitmap and data values were unpacked.
Definition: grib2.h:190
g2_free
void g2_free(gribfield *gfld)
This routine frees up memory that was allocated for struct gribfield.
Definition: g2_free.c:24
gribfield::ifldnum
g2int ifldnum
Field number within GRIB message.
Definition: grib2.h:109
g2_addgrid
g2int g2_addgrid(unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist, g2int idefnum)
This routine packs up a Grid Definition Section (Section 3) and adds it to a GRIB2 message.
Definition: g2_addgrid.c:70
gribfield::idrtlen
g2int idrtlen
Number of elements in idrtmpl.
Definition: grib2.h:182
gribfield::ibmap
g2int ibmap
Bitmap indicator (see Table 6.0).
Definition: grib2.h:207
gribfield::griddef
g2int griddef
Source of grid definition (see Table 3.0).
Definition: grib2.h:116
g2_unpack4
g2int g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, g2int *mappdslen, float **coordlist, g2int *numcoord)
This subroutine unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2.
Definition: g2_unpack4.c:46
seekgb
void seekgb(FILE *lugb, g2int iseek, g2int mseek, g2int *lskip, g2int *lgrib)
This subprogram searches a file for the next GRIB Message.
Definition: seekgb.c:39
gribfield::numoct_opt
g2int numoct_opt
Number of octets needed for each additional grid points definition.
Definition: grib2.h:124
g2_addfield
g2int g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, float *coordlist, g2int numcoord, g2int idrsnum, g2int *idrstmpl, float *fld, g2int ngrdpts, g2int ibmap, g2int *bmap)
This routine packs up Sections 4 through 7 for a given field and adds them to a GRIB2 message.
Definition: g2_addfield.c:98
pngunpackd
g2int pngunpackd(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, double *fld)
This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB...
Definition: pngunpack.c:128
g2_info
g2int g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1, g2int *numfields, g2int *numlocal)
This subroutine searches through a GRIB2 message and returns the number of gridded fields found in th...
Definition: g2_info.c:67
gribfield::idsect
g2int * idsect
Contains the entries in the Identification Section (Section 1).
Definition: grib2.h:96
g2_unpack6
g2int g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap, g2int **bmap)
This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.
Definition: g2_unpack6.c:33
g2c_set_log_level
int g2c_set_log_level(int new_level)
Use this to set the global log level.
Definition: util.c:124
g2_gribend
g2int g2_gribend(unsigned char *cgrib)
This routine finalizes a GRIB2 message after all grids and fields have been added.
Definition: g2_gribend.c:37
g2_getfld
g2int g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, gribfield **gfld)
This subroutine returns all the metadata, template values, bit-map (if applicable),...
Definition: g2_getfld.c:91
pngpack
void pngpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a float data field into PNG image format.
Definition: pngpack.c:224
gribfield::idrtmpl
g2int * idrtmpl
Contains the data values for the Data Representation Template specified by idrtnum.
Definition: grib2.h:186
jpcunpack
g2int jpcunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld)
Unpack JPEG2000 compressed data into an array of floats, using info from the GRIB2 Data Representatio...
Definition: jpcunpack.c:108
gribfield::interp_opt
g2int interp_opt
Interpretation of list for optional points definition.
Definition: grib2.h:129
gribfield::ipdtlen
g2int ipdtlen
Number of elements in ipdtmpl - i.e.
Definition: grib2.h:160
g2_unpack2
g2int g2_unpack2(unsigned char *cgrib, g2int *iofst, g2int *lencsec2, unsigned char **csec2)
This subroutine unpacks Section 2 (Local Use Section) as defined in GRIB Edition 2.
Definition: g2_unpack2.c:38
pngpackd
void pngpackd(double *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a double data field into PNG image format.
Definition: pngpack.c:259
gribfield::discipline
g2int discipline
Message Discipline (see Table 0.0).
Definition: grib2.h:48
gribfield::num_opt
g2int num_opt
(Used if numoct_opt .ne.
Definition: grib2.h:135
gribfield::coord_list
float * coord_list
Array containing floating point values intended to document the vertical discretisation associated to...
Definition: grib2.h:172
gribfield::ipdtnum
g2int ipdtnum
Product Definition Template Number (see Table 4.0).
Definition: grib2.h:156
g2int
int64_t g2int
Long integer type.
Definition: grib2.h:28
g2_unpack3
g2int g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, g2int *mapgridlen, g2int **ideflist, g2int *idefnum)
This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.
Definition: g2_unpack3.c:57
gribfield::fld
float * fld
Array of ndpts unpacked data points.
Definition: grib2.h:214
gribfield::local
unsigned char * local
Pointer to character array containing contents of Local Section 2, if included.
Definition: grib2.h:103
gribfield::idrtnum
g2int idrtnum
Data Representation Template Number (see Table 5.0).
Definition: grib2.h:179
gribfield::num_coord
g2int num_coord
Number of values in array coord_list.
Definition: grib2.h:167
gribfield::expanded
g2int expanded
Logical value indicating whether the data field was expanded to the grid in the case where a bit-map ...
Definition: grib2.h:199
gribfield
Struct for GRIB field.
Definition: grib2.h:41
gribfield::version
g2int version
GRIB edition number (2).
Definition: grib2.h:44
gribfield::locallen
g2int locallen
Length of array local.
Definition: grib2.h:106
gribfield::ndpts
g2int ndpts
Number of data points unpacked and returned.
Definition: grib2.h:175
gribfield::igdtlen
g2int igdtlen
Number of elements in igdtmpl - i.e.
Definition: grib2.h:148
gribfield::list_opt
g2int * list_opt
(Used if numoct_opt .ne.
Definition: grib2.h:140
g2_addlocal
g2int g2_addlocal(unsigned char *cgrib, unsigned char *csec2, g2int lcsec2)
This routine adds a Local Use Section (Section 2) to a GRIB2 message.
Definition: g2_addlocal.c:40
gribfield::igdtnum
g2int igdtnum
Grid Definition Template Number (See Table 3.1).
Definition: grib2.h:144
jpcpack
void jpcpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a data field into a JPEG2000 code stream.
Definition: jpcpack.c:253
gribfield::bmap
g2int * bmap
Integer array containing decoded bitmap, if ibmap=0 or ibap=254.
Definition: grib2.h:211
gribfield::ipdtmpl
g2int * ipdtmpl
Contains the data values for the Product Definition Template specified by ipdtnum.
Definition: grib2.h:164
gribfield::idsectlen
g2int idsectlen
Number of elements in idsect.
Definition: grib2.h:99
g2intu
uint64_t g2intu
Unsigned long integer type.
Definition: grib2.h:32
jpcunpackd
g2int jpcunpackd(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, double *fld)
Unpack JPEG2000 compressed data into an array of doubles, using info from the GRIB2 Data Representati...
Definition: jpcunpack.c:135