NCEPLIBS-g2c  1.8.0
grib2.h
Go to the documentation of this file.
1 
18 #ifndef _grib2_H
19 #define _grib2_H
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <string.h>
23 #include <sys/types.h>
24 #include <unistd.h>
25 
26 #define G2C_VERSION "1.8.0"
28 #define G2_PNG_ENABLED 1
29 #define G2_JPEG2000_ENABLED 1
30 /* #undef G2_AEC_ENABLED */
31 
33 typedef int64_t g2int;
34 
37 typedef uint64_t g2intu;
38 
41 typedef float g2float;
42 
46 struct gribfield
47 {
50 
54 
102 
105 
108  unsigned char *local;
109 
112 
115 
122 
125 
130 
135 
141 
146 
150 
154 
158 
162 
166 
170 
173 
177  float *coord_list;
178 
181 
185 
188 
192 
196 
205 
213 
217 
219  float *fld;
220 };
221 
222 typedef struct gribfield gribfield;
224 /* Prototypes for unpacking sections API */
225 g2int g2_unpack1(unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen);
226 g2int g2_unpack2(unsigned char *cgrib, g2int *iofst, g2int *lencsec2,
227  unsigned char **csec2);
228 g2int g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl,
229  g2int *mapgridlen, g2int **ideflist, g2int *idefnum);
230 g2int g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl,
231  g2int *mappdslen, float **coordlist, g2int *numcoord);
232 g2int g2_unpack5(unsigned char *cgrib, g2int *iofst, g2int *ndpts, g2int *idrsnum,
233  g2int **idrstmpl, g2int *mapdrslen);
234 g2int g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap,
235  g2int **bmap);
236 g2int g2_unpack7(unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstmpl,
237  g2int idrsnum, g2int *idrstmpl, g2int ndpts, float **fld);
238 
239 /* Prototypes for unpacking API */
240 void seekgb(FILE *lugb, g2int iseek, g2int mseek, g2int *lskip,
241  g2int *lgrib);
242 g2int g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1,
243  g2int *numfields, g2int *numlocal);
244 g2int g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand,
245  gribfield **gfld);
246 void g2_free(gribfield *gfld);
247 
248 /* Prototypes for packing API */
249 g2int g2_create(unsigned char *cgrib, g2int *listsec0, g2int *listsec1);
250 g2int g2_addlocal(unsigned char *cgrib, unsigned char *csec2, g2int lcsec2);
251 g2int g2_addgrid(unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist,
252  g2int idefnum);
253 g2int g2_addfield(unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl,
254  float *coordlist, g2int numcoord, g2int idrsnum, g2int *idrstmpl,
255  float *fld, g2int ngrdpts, g2int ibmap, g2int *bmap);
256 g2int g2_gribend(unsigned char *cgrib);
257 
258 /* Compression. */
259 void pngpack(float *fld, g2int width, g2int height, g2int *idrstmpl,
260  unsigned char *cpack, g2int *lcpack);
261 g2int pngunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
262  float *fld);
263 void jpcpack(float *fld, g2int width, g2int height, g2int *idrstmpl,
264  unsigned char *cpack, g2int *lcpack);
265 g2int jpcunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
266  float *fld);
267 void aecpack(float *fld, g2int width, g2int height, g2int *idrstmpl,
268  unsigned char *cpack, g2int *lcpack);
269 g2int aecunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
270  float *fld);
271 
272 
273 /* The new g2c API is being introduced in version 2.0 of the library. */
274 
275 /* Data types. */
276 #define G2C_BYTE 1
277 #define G2C_CHAR 2
278 #define G2C_SHORT 3
279 #define G2C_INT 4
280 #define G2C_FLOAT 5
281 #define G2C_DOUBLE 6
282 #define G2C_UBYTE 7
283 #define G2C_USHORT 8
284 #define G2C_UINT 9
285 #define G2C_INT64 10
286 #define G2C_UINT64 11
288 /* Defines for file handling. */
289 #define G2C_MAX_FILES 3
290 #define G2C_MAX_NAME 1024
291 #define G2C_NOWRITE 0x0000
292 #define G2C_WRITE 0x0001
293 #define G2C_CLOBBER 0x0000
294 #define G2C_NOCLOBBER 0x0004
296 /* Useful constants. */
297 #define G2C_SECTION0_BYTES 16
301 #define G2C_SECTION1_BYTES 21
302 
303 #define G2C_SECTION0_LEN 3
304 #define G2C_SECTION1_LEN 13
306 /* Constants to help with templates. */
307 #define G2C_MAX_GDS_TEMPLATE 31
308 #define G2C_MAX_GDS_TEMPLATE_MAPLEN 28
309 #define G2C_MAX_PDS_TEMPLATE 47
310 #define G2C_MAX_PDS_TEMPLATE_MAPLEN 45
311 #define G2C_MAX_DRS_TEMPLATE 10
312 #define G2C_MAX_DRS_TEMPLATE_MAPLEN 18
314 /* File handling functions. */
315 int g2c_open(const char *path, int mode, int *g2cid);
316 int g2c_open_index(const char *data_file, const char *index_file, int mode, int *g2cid);
317 int g2c_close(int g2cid);
318 int g2c_write_index(int g2cid, int mode, const char *index_file);
319 
320 /* GRIB1 file functions. */
321 int g2c_open_index1(const char *index_file);
322 
323 /* Inquiry functions. */
324 int g2c_inq(int g2cid, int *num_msg);
325 int g2c_inq_msg(int g2cid, int msg_num, unsigned char *discipline, int *num_fields,
326  int *num_local, short *center, short *subcenter, unsigned char *master_version,
327  unsigned char *local_version);
328 int g2c_inq_msg_time(int g2cid, int msg_num, unsigned char *sig_ref_time, short *year,
329  unsigned char *month, unsigned char *day, unsigned char *hour,
330  unsigned char *minute, unsigned char *second);
331 int g2c_inq_prod(int g2cid, int msg_num, int prod_num, int *pds_template_len,
332  int *pds_template, int *gds_template_len, int *gds_template,
333  int *drs_template_len, int *drs_template);
334 int g2c_inq_dim(int g2cid, int msg_num, int prod_num, int dim_num, size_t *len,
335  char *name, float *val);
336 
337 /* Getting data. */
338 int g2c_get_prod(int g2cid, int msg_num, int prod_num, int *num_data_points,
339  float *data);
340 
341 /* Templates. */
342 int g2c_get_grid_template(int grid_template_num, int *maplen, int *map, int *needext);
343 int g2c_get_grid_template_extension(int grid_template_num, int *g2c_template,
344  int *extlen, int *ext);
345 int g2c_get_pds_template_extension(int pds_template_num, int *g2c_template,
346  int *extlen, int *ext);
347 int g2c_get_pds_template(int pds_template_num, int *maplen, int *map, int *needext);
348 int g2c_get_drs_template(int drs_template_num, int *maplen, int *map, int *needext);
349 
350 /* Internal functions. */
351 int g2c_get_msg(int g2cid, size_t skip_bytes, size_t max_bytes, size_t *bytes_to_msg,
352  size_t *bytes_in_msg, unsigned char **cbuf);
353 int g2c_find_msg2(int g2cid, size_t skip_bytes, size_t max_bytes, size_t *bytes_to_msg,
354  size_t *bytes_in_msg);
355 int g2c_xml_init();
356 int g2c_find_desc_str(char *title, char *code, char *desc);
357 int g2c_find_desc(char *title, int code, char *desc);
358 void g2c_free_tables();
359 void g2c_gbit_int(unsigned char *in, int *iout, int iskip, int nbits);
360 int g2c_gbits_int(unsigned char *in, int *iout, int iskip, int nbits,
361  int nskip, int n);
362 int g2c_seekmsg(int g2cid, size_t skip, size_t *offset, size_t *msglen);
363 
364 /* Logging, for debugging purposes. */
365 int g2c_set_log_level(int new_level);
366 int g2c_log_file(int g2cid);
367 
368 /* Error handling. */
369 const char *g2c_strerror(int g2cerr);
370 
371 /* Compression. */
372 int g2c_unpack7(unsigned char *cgrib, int igdsnum, int gds_tmpl_len, long long int *gdstmpl,
373  int idrsnum, int drs_tmpl_len, long long int *drstmpl, int ndpts, float *fld);
374 int g2c_pngpackf(float *fld, size_t width, size_t height, int *idrstmpl,
375  unsigned char *cpack, int *lcpack);
376 int g2c_pngpackd(double *fld, size_t width, size_t height, int *idrstmpl,
377  unsigned char *cpack, int *lcpack);
378 int g2c_pngunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts,
379  float *fld);
380 int g2c_pngunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts,
381  double *fld);
382 int g2c_jpcpackf(float *fld, size_t width, size_t height, int *idrstmpl,
383  unsigned char *cpack, size_t *lcpack);
384 int g2c_jpcpackd(double *fld, size_t width, size_t height, int *idrstmpl,
385  unsigned char *cpack, size_t *lcpack);
386 int g2c_jpcunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts,
387  float *fld);
388 int g2c_jpcunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts,
389  double *fld);
390 int g2c_enc_jpeg2000(unsigned char *cin, int width, int height, int nbits,
391  int ltype, int ratio, int retry, char *outjpc,
392  size_t jpclen);
393 int g2c_dec_jpeg2000(char *injpc, size_t bufsize, int *outfld);
394 int g2c_aecpackf(float *fld, size_t width, size_t height, int *idrstmpl,
395  unsigned char *cpack, size_t *lcpack);
396 int g2c_aecpackd(double *fld, size_t width, size_t height, int *idrstmpl,
397  unsigned char *cpack, size_t *lcpack);
398 int g2c_aecunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts,
399  float *fld);
400 int g2c_aecunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts,
401  double *fld);
402 
403 /* Testing. */
404 int g2c_compare(int g2cid1, int g2cid2);
405 
406 /* Output. */
407 int g2c_degrib2(int g2cid, const char *fileout);
408 
409 /* Parameters. */
410 int g2c_param_g1tog2(int g1val, int g1ver, int *g2disc, int *g2cat, int *g2num);
411 int g2c_param_abbrev(int g2disc, int g2cat, int g2num, char *abbrev);
412 int g2c_param_g2tog1(int g2disc, int g2cat, int g2num, int *g1val, int *g1ver);
413 int g2c_param_all(int param_idx, int *g1ver, int *g1val, int *g2disc, int *g2cat,
414  int *g2num, char *abbdrev);
415 
416 /* Useful constants. */
417 #define G2C_SECTION0_ARRAY_LEN 3
418 #define G2C_SECTION1_ARRAY_LEN 13
420 #define G2C_JPEG_DRS_TEMPLATE_LEN 7
421 #define G2C_PNG_DRS_TEMPLATE_LEN 5
422 #define G2C_AEC_DRS_TEMPLATE_LEN 8
424 #define G2C_MAX_GRIB_DESC_LEN 512
425 #define G2C_MAX_GRIB_STATUS_LEN 40
426 #define G2C_MAX_GRIB_LEVEL_DESC_LEN 40
427 #define G2C_MAX_GRIB_CODE_LEN 20
428 #define G2C_MAX_GRIB_TITLE_LEN 200
429 #define G2C_MAX_NUM_SECTIONS 1024
431 #define G2C_MAX_NOAA_PARAMS 2000
432 #define G2C_MAX_NOAA_ABBREV_LEN 8
433 #define G2C_MAX_NOAA_PARAM_LINE_LEN 120
435 #define G2C_JASPER_MAX_MEM 268435456
437 /* Error codes for G2 API. */
438 #define G2_NO_ERROR 0
439 #define G2_CREATE_GRIB_VERSION -1
440 #define G2_INFO_NO_GRIB 1
441 #define G2_INFO_GRIB_VERSION 2
442 #define G2_INFO_NO_SEC1 3
443 #define G2_INFO_WRONG_END 4
444 #define G2_INFO_BAD_END 5
445 #define G2_INFO_INVAL_SEC 6
446 #define G2_GETFLD_NO_GRIB 1
447 #define G2_GETFLD_GRIB_VERSION 2
448 #define G2_GETFLD_INVAL 3
449 #define G2_GETFLD_WRONG_END 4
450 #define G2_GETFLD_WRONG_NFLDS 6
451 #define G2_GETFLD_BAD_END 7
452 #define G2_GETFLD_INVAL_SEC 8
453 #define G2_GETFLD_NO_DRT 9
454 #define G2_GETFLD_BAD_SEC1 15
455 #define G2_GETFLD_BAD_SEC2 16
456 #define G2_GETFLD_BAD_SEC3 10
457 #define G2_GETFLD_BAD_SEC4 11
458 #define G2_GETFLD_BAD_SEC5 12
459 #define G2_GETFLD_BAD_SEC6 13
460 #define G2_GETFLD_BAD_SEC7 14
461 #define G2_GETFLD_NO_BITMAP 17
462 #define G2_GRIBEND_MSG_INIT -1
463 #define G2_BAD_SEC -4
464 #define G2_UNPACK_BAD_SEC 2
465 #define G2_UNPACK_NO_MEM 6
466 #define G2_UNPACK3_BAD_GDT 5
467 #define G2_UNPACK4_BAD_PDT 5
468 #define G2_UNPACK5_BAD_DRT 7
469 #define G2_UNPACK6_BAD_BITMAP 4
470 #define G2_UNPACK7_CORRUPT_SEC 7
471 #define G2_UNPACK7_WRONG_GDT 5
472 #define G2_UNPACK7_BAD_DRT 4
473 #define G2_ADD_MSG_INIT -1
474 #define G2_ADD_MSG_COMPLETE -2
475 #define G2_BAD_SEC_COUNTS -3
476 #define G2_ADDFIELD_BAD_PDT -5
477 #define G2_ADDFIELD_BAD_GDS -6
478 #define G2_ADDFIELD_BAD_DRT -7
479 #define G2_ADDFIELD_BAD_BITMAP -8
480 #define G2_ADDFIELD_BAD_GDT -9
481 #define G2_ADDFIELD_ERR -10
482 #define G2_ADDGRID_BAD_GDT -5
483 #define G2_JPCUNPACK_MEM 1
484 #define G2_SPECUNPACK_TYPE -3
485 #define G2_JASPER_INIT -2
486 #define G2_JASPER_ENCODE -3
487 #define G2_JASPER_DECODE -3
488 #define G2_JASPER_DECODE_COLOR -5
490 /* These are the new error codes. */
491 #define G2C_NOERROR 0
492 #define G2C_ERROR 1
493 #define G2C_ENOTGRIB (-50)
494 #define G2C_EMSGCOMPLETE (-51)
495 #define G2C_ENAMETOOLONG (-52)
496 #define G2C_EINVAL (-53)
497 #define G2C_EFILE (-54)
498 #define G2C_EBADID (-55)
499 #define G2C_ETOOMANYFILES (-56)
500 #define G2C_ENOMEM (-57)
501 #define G2C_EMSG (-58)
502 #define G2C_ENOMSG (-59)
503 #define G2C_EXML (-60)
504 #define G2C_ENOTFOUND (-61)
505 #define G2C_ENOTGRIB2 (-62)
506 #define G2C_ENOSECTION (-63)
507 #define G2C_ENOEND (-64)
508 #define G2C_EBADEND (-65)
509 #define G2C_EBADSECTION (-66)
510 #define G2C_EJPEG (-67)
511 #define G2C_EPNG (-68)
512 #define G2C_ENOTEMPLATE (-69)
513 #define G2C_EBADTEMPLATE (-70)
514 #define G2C_ENOPARAM (-71)
515 #define G2C_ENOPRODUCT (-72)
516 #define G2C_EBADTYPE (-73)
517 #define G2C_EAEC (-74)
519 #endif /* _grib2_H */
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
g2int igdtnum
Grid Definition Template Number (See Table 3.1).
Definition: grib2.h:149
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:124
void g2_free(gribfield *gfld)
This routine frees up memory that was allocated for struct gribfield.
Definition: g2_free.c:24
int g2c_inq_prod(int g2cid, int msg_num, int prod_num, int *pds_template_len, int *pds_template, int *gds_template_len, int *gds_template, int *drs_template_len, int *drs_template)
Inquire about a product.
Definition: g2cinq.c:207
g2int locallen
Length of array local.
Definition: grib2.h:111
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
g2int ibmap
Bitmap indicator (see Table 6.0).
Definition: grib2.h:212
int g2c_inq(int g2cid, int *num_msg)
Learn about a GRIB2 file.
Definition: g2cinq.c:31
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:242
int g2c_open_index(const char *data_file, const char *index_file, int mode, int *g2cid)
Open a GRIB2 file with the help of an index file.
Definition: g2cindex.c:786
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
const char * g2c_strerror(int g2cerr)
Given an error code, return an error message.
Definition: g2cutil.c:29
int g2c_jpcunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, double *fld)
Unpack JPEG2000 compressed data into an array of doubles, using info from the GRIB2 Data Representati...
Definition: jpcunpack.c:200
int g2c_aecpackf(float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)
This function packs up a float array into a AEC code stream.
Definition: aecpack.c:346
g2int interp_opt
Interpretation of list for optional points definition.
Definition: grib2.h:134
g2int ngrdpts
Number of grid points in the defined grid.
Definition: grib2.h:124
int g2c_find_desc_str(char *title, char *code, char *desc)
Given a table title and a code, find a description.
Definition: g2cxml.c:84
int g2c_dec_jpeg2000(char *injpc, size_t bufsize, int *outfld)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
Definition: dec_jpeg2000.c:174
int g2c_open(const char *path, int mode, int *g2cid)
Open an existing GRIB2 file.
Definition: g2cfile.c:1193
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:117
void seekgb(FILE *lugb, g2int iseek, g2int mseek, g2int *lskip, g2int *lgrib)
Search a file for the next GRIB Message.
Definition: seekgb.c:46
int g2c_jpcpackd(double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)
This function packs up a double array into a JPEG2000 code stream.
Definition: jpcpack.c:387
int g2c_param_g2tog1(int g2disc, int g2cat, int g2num, int *g1val, int *g1ver)
Translate GRIB2 parameter to GRIB1 parameter.
Definition: g2cparams.c:1136
g2int ifldnum
Field number within GRIB message.
Definition: grib2.h:114
int g2c_jpcunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, float *fld)
Unpack JPEG2000 compressed data into an array of floats, using info from the GRIB2 Data Representatio...
Definition: jpcunpack.c:160
float g2float
Float type.
Definition: grib2.h:41
int g2c_param_abbrev(int g2disc, int g2cat, int g2num, char *abbrev)
Get NOAA abbreviation for a GRIB2 parameter.
Definition: g2cparams.c:1091
int g2c_open_index1(const char *index_file)
Open a GRIB1 index file and read the contents.
Definition: g2cindex.c:685
int g2c_pngunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t 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:179
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) of a GRIB2 message.
Definition: g2_unpack7.c:214
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
int g2c_aecunpackd(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, double *fld)
Unpack AEC compressed data into an array of doubles, using info from the GRIB2 Data Representation Te...
Definition: aecunpack.c:210
g2int griddef
Source of grid definition (see Table 3.0).
Definition: grib2.h:121
int g2c_find_desc(char *title, int code, char *desc)
Given a table title and an integer code, find a description.
Definition: g2cxml.c:132
g2int ipdtnum
Product Definition Template Number (see Table 4.0).
Definition: grib2.h:161
g2int * ipdtmpl
Contains the data values for the Product Definition Template specified by ipdtnum.
Definition: grib2.h:169
g2int discipline
Message Discipline (see Table 0.0).
Definition: grib2.h:53
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
int g2c_enc_jpeg2000(unsigned char *cin, int width, int height, int nbits, int ltype, int ratio, int retry, char *outjpc, size_t jpclen)
This Function encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 ...
Definition: enc_jpeg2000.c:51
g2int numoct_opt
Number of octets needed for each additional grid points definition.
Definition: grib2.h:129
g2int aecunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld)
Unpack AEC compressed data into an array of floats, using info from the GRIB2 Data Representation Tem...
Definition: aecunpack.c:139
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
int g2c_get_pds_template(int pds_template_num, int *maplen, int *map, int *needext)
Get PDS template information.
Definition: pdstemplates.c:816
int g2c_pngpackd(double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, int *lcpack)
This subroutine packs up a double data field into PNG image format.
Definition: pngpack.c:336
g2int idrtlen
Number of elements in idrtmpl.
Definition: grib2.h:187
int g2c_get_grid_template_extension(int grid_template_num, int *g2c_template, int *extlen, int *ext)
Get grid template extension information.
int g2c_xml_init()
Init.
Definition: g2cxml.c:190
int g2c_close(int g2cid)
Close a GRIB2 file, freeing resources.
Definition: g2cfile.c:1357
g2int unpacked
Logical value indicating whether the bitmap and data values were unpacked.
Definition: grib2.h:195
int g2c_jpcpackf(float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)
This function packs up a float array into a JPEG2000 code stream.
Definition: jpcpack.c:321
int g2c_degrib2(int g2cid, const char *fileout)
Write a summary file like the degrib2 utility.
Definition: g2cdegrib2.c:637
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
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
int g2c_pngunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t 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:147
g2int idsectlen
Number of elements in idsect.
Definition: grib2.h:104
g2int ipdtlen
Number of elements in ipdtmpl - i.e.
Definition: grib2.h:165
int g2c_inq_dim(int g2cid, int msg_num, int prod_num, int dim_num, size_t *len, char *name, float *val)
Learn about the one of the dimensions of a GRIB2 product.
Definition: g2cinq.c:328
int g2c_inq_msg_time(int g2cid, int msg_num, unsigned char *sig_ref_time, short *year, unsigned char *month, unsigned char *day, unsigned char *hour, unsigned char *minute, unsigned char *second)
Learn about the date/time information in a GRIB2 message.
Definition: g2cinq.c:149
uint64_t g2intu
Unsigned long integer type.
Definition: grib2.h:37
float * coord_list
Array containing floating point values intended to document the vertical discretisation associated to...
Definition: grib2.h:177
void g2c_free_tables()
Free table memory.
Definition: g2cxml.c:42
int g2c_get_msg(int g2cid, size_t skip_bytes, size_t max_bytes, size_t *bytes_to_msg, size_t *bytes_in_msg, unsigned char **cbuf)
Search a file for the next GRIB1 or GRIB2 message, and read it, allocating space in memory to hold th...
Definition: g2cfile.c:293
int g2c_set_log_level(int new_level)
Use this to set the global log level.
Definition: util.c:124
int g2c_inq_msg(int g2cid, int msg_num, unsigned char *discipline, int *num_fields, int *num_local, short *center, short *subcenter, unsigned char *master_version, unsigned char *local_version)
Learn about a GRIB2 message.
Definition: g2cinq.c:86
g2int * igdtmpl
Contains the data values for the Grid Definition Template specified by igdtnum.
Definition: grib2.h:157
g2int idrtnum
Data Representation Template Number (see Table 5.0).
Definition: grib2.h:184
int g2c_write_index(int g2cid, int mode, const char *index_file)
Create an index file from a GRIB2 file, just like those created by the grb2index utility.
Definition: g2cindex.c:346
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
g2int ndpts
Number of data points unpacked and returned.
Definition: grib2.h:180
int g2c_get_drs_template(int drs_template_num, int *maplen, int *map, int *needext)
Get DRS template information.
Definition: drstemplates.c:261
int g2c_param_all(int param_idx, int *g1ver, int *g1val, int *g2disc, int *g2cat, int *g2num, char *abbdrev)
Return all the information about a parameter.
Definition: g2cparams.c:1185
g2int * idrtmpl
Contains the data values for the Data Representation Template specified by idrtnum.
Definition: grib2.h:191
int g2c_find_msg2(int g2cid, size_t skip_bytes, size_t max_bytes, size_t *bytes_to_msg, size_t *bytes_in_msg)
Search a file for the next GRIB1 or GRIB2 message.
Definition: g2cfile.c:164
g2int * list_opt
(Used if numoct_opt .ne.
Definition: grib2.h:145
int g2c_get_prod(int g2cid, int msg_num, int prod_num, int *num_data_points, float *data)
Read the data for a product.
Definition: g2cprod.c:28
int g2c_param_g1tog2(int g1val, int g1ver, int *g2disc, int *g2cat, int *g2num)
Translate GRIB1 parameter to GRIB2 parameter.
Definition: g2cparams.c:1051
int g2c_unpack7(unsigned char *cgrib, int igdsnum, int gds_tmpl_len, long long int *gdstmpl, int idrsnum, int drs_tmpl_len, long long int *drstmpl, int ndpts, float *fld)
This subroutine unpacks Section 7 (Data Section) of a GRIB2 message.
Definition: g2_unpack7.c:259
int g2c_get_pds_template_extension(int pds_template_num, int *g2c_template, int *extlen, int *ext)
Get pds template extension information.
Definition: pdstemplates.c:741
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
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:68
g2int version
GRIB edition number (2).
Definition: grib2.h:49
void jpcpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This function packs up a float array into a JPEG2000 code stream.
Definition: jpcpack.c:270
int g2c_aecpackd(double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)
This function packs up a double array into a AEC code stream.
Definition: aecpack.c:410
int g2c_log_file(int g2cid)
Print a summary of the contents of an open GRIB2 file.
Definition: g2cutil.c:188
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:99
g2int * idsect
Contains the entries in the Identification Section (Section 1).
Definition: grib2.h:101
float * fld
Array of ndpts unpacked data points.
Definition: grib2.h:219
g2int num_coord
Number of values in array coord_list.
Definition: grib2.h:172
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) from a GRIB2 message.
Definition: g2_unpack3.c:62
int g2c_gbits_int(unsigned char *in, int *iout, int iskip, int nbits, int nskip, int n)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
Definition: gbits.c:139
unsigned char * local
Pointer to character array containing contents of Local Section 2, if included.
Definition: grib2.h:108
g2int expanded
Logical value indicating whether the data field was expanded to the grid in the case where a bit-map ...
Definition: grib2.h:204
g2int num_opt
(Used if numoct_opt .ne.
Definition: grib2.h:140
int g2c_pngpackf(float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, int *lcpack)
This subroutine packs up a float data field into PNG image format.
Definition: pngpack.c:282
g2int igdtlen
Number of elements in igdtmpl - i.e.
Definition: grib2.h:153
int g2c_compare(int g2cid1, int g2cid2)
Compare the metadata of two open GRIB2 files.
Definition: g2ccompare.c:28
g2int * bmap
Integer array containing decoded bitmap, if ibmap=0 or ibap=254.
Definition: grib2.h:216
int g2c_aecunpackf(unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, float *fld)
Unpack AEC compressed data into an array of floats, using info from the GRIB2 Data Representation Tem...
Definition: aecunpack.c:172
int64_t g2int
Long integer type.
Definition: grib2.h:33
int g2c_get_grid_template(int grid_template_num, int *maplen, int *map, int *needext)
Get grid template information.
int g2c_seekmsg(int g2cid, size_t skip, size_t *offset, size_t *msglen)
Search a file for the next GRIB2 Message.
Definition: g2cfile.c:56
void g2c_gbit_int(unsigned char *in, int *iout, int iskip, int nbits)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
Definition: gbits.c:114
void aecpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This function packs up a float array into a AEC code stream.
Definition: aecpack.c:297
Struct for GRIB field.
Definition: grib2.h:47