97 g2int have3 = 0, have4 = 0, have5 = 0, have6 = 0, have7 = 0;
98 g2int numfld = 0, j, n, istart, iofst, ipos;
99 g2int disc, ver, lensec0, lengrib, lensec, isecnum;
114 printf(
"g2_getfld: Request for field number must be positive.\n");
121 for (j = 0; j < 100; j++)
123 if (cgrib[j] ==
'G' && cgrib[j + 1] ==
'R' && cgrib[j + 2] ==
'I' &&
132 printf(
"g2_getfld: Beginning characters GRIB not found.\n");
138 iofst = 8 * (istart + 6);
139 gbit(cgrib, &disc, iofst, 8);
141 gbit(cgrib, &ver, iofst, 8);
144 gbit(cgrib, &lengrib, iofst, 32);
147 ipos = istart + lensec0;
152 printf(
"g2_getfld: can only decode GRIB edition 2.\n");
163 if (cgrib[ipos] ==
'7' && cgrib[ipos + 1] ==
'7' && cgrib[ipos + 2] ==
'7' &&
164 cgrib[ipos + 3] ==
'7')
170 if (ipos != istart + lengrib)
172 printf(
"g2_getfld: '7777' found, but not where expected.\n");
181 gbit(cgrib, &lensec, iofst, 32);
183 gbit(cgrib, &isecnum, iofst, 8);
187 if (isecnum < 1 || isecnum > 7)
189 printf(
"g2_getfld: Unrecognized Section Encountered=%ld\n", isecnum);
250 if (numfld == ifldnum)
271 if (isecnum == 5 && numfld == ifldnum)
291 bmpsave = lgfld->
bmap;
300 if (lgfld->
ibmap == 254)
303 lgfld->
bmap = bmpsave;
306 printf(
"g2_getfld: Prev bit-map specified, but none exist.\n");
323 if (isecnum == 7 && numfld == ifldnum && unpack)
330 printf(
"g2_getfld: return from g2_unpack7 = %d \n", (
int)jerr);
339 if (lgfld->
ibmap != 255 && lgfld->
bmap != 0)
344 newfld = calloc(lgfld->
ngrdpts,
sizeof(
float));
345 for (j = 0; j < lgfld->
ngrdpts; j++)
347 if (lgfld->
bmap[j] == 1)
348 newfld[j] = lgfld->
fld[n++];
367 ipos = ipos + lensec;
368 if (ipos > istart + lengrib)
370 printf(
"g2_getfld: '7777' not found at end of GRIB message.\n");
377 if (unpack && have3 && have4 && have5 && have6 && have7)
382 if (!unpack && have3 && have4 && have5 && have6)
388 printf(
"g2_getfld: GRIB message contained %ld different fields.\n", numfld);
389 printf(
"g2_getfld: The request was for field %ld.\n", ifldnum);
void g2_free(gribfield *gfld)
Free memory that was allocated for struct gribfield.
g2int g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, gribfield **gfld)
Return all the metadata, template values, bit-map (if applicable), and the unpacked data for a data f...
g2int g2_unpack1(unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen)
Unpacks Section 1 - Identification Section of a GRIB2 message.
g2int g2_unpack2(unsigned char *cgrib, g2int *iofst, g2int *lencsec2, unsigned char **csec2)
Unpack Section 2 (Local Use Section) of a GRIB2 message.
g2int g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, g2int *mapgridlen, g2int **ideflist, g2int *idefnum)
Unpack Section 3 (Grid Definition Section) of a GRIB2 message.
g2int g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, g2int *mappdslen, float **coordlist, g2int *numcoord)
Unpack Section 4 (Product Definition Section) of a GRIB2 message.
g2int g2_unpack5(unsigned char *cgrib, g2int *iofst, g2int *ndpts, g2int *idrsnum, g2int **idrstmpl, g2int *mapdrslen)
Unpack Section 5 (Data Representation Section) of a GRIB2 message.
g2int g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap, g2int **bmap)
Unpack Section 6 (Bit-Map Section) of a GRIB2 message.
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.
void gbit(unsigned char *in, g2int *iout, g2int iskip, g2int nbits)
Get arbitrary size values from a packed bit string, right justifying each value in the unpacked iout ...
g2int igdtnum
Grid Definition Template Number (See Table 3.1).
g2int locallen
Length of array local.
g2int ibmap
Bitmap indicator (see Table 6.0).
#define G2_GETFLD_BAD_SEC7
Error in g2_getfld() unpacking section 7.
g2int interp_opt
Interpretation of list for optional points definition.
g2int ngrdpts
Number of grid points in the defined grid.
#define G2_GETFLD_INVAL
g2_getfld() data field request number was not positive.
g2int ifldnum
Field number within GRIB message.
#define G2_GETFLD_GRIB_VERSION
Wrong GRIB version for g2_getfld(), must be 2.
g2int griddef
Source of grid definition (see Table 3.0).
g2int ipdtnum
Product Definition Template Number (see Table 4.0).
g2int * ipdtmpl
Contains the data values for the Product Definition Template specified by ipdtnum.
#define G2_GETFLD_WRONG_NFLDS
In g2_getfld() message did not contain the requested number of data fields.
g2int discipline
Message Discipline (see Table 0.0).
#define G2_GETFLD_BAD_SEC2
Error in g2_getfld() unpacking section 2.
g2int numoct_opt
Number of octets needed for each additional grid points definition.
#define G2_GETFLD_BAD_SEC1
Error in g2_getfld() unpacking section 1.
#define G2_GETFLD_BAD_SEC5
Error in g2_getfld() unpacking section 5.
g2int idrtlen
Number of elements in idrtmpl.
g2int unpacked
Logical value indicating whether the bitmap and data values were unpacked.
g2int idsectlen
Number of elements in idsect.
g2int ipdtlen
Number of elements in ipdtmpl - i.e.
#define G2_GETFLD_WRONG_END
g2_info() found "7777" not where expected.
#define G2_GETFLD_BAD_SEC4
Error in g2_getfld() unpacking section 4.
#define G2_NO_ERROR
Function succeeded.
#define G2_GETFLD_NO_GRIB
g2_getfld() can't find beginning characters "GRIB".
float * coord_list
Array containing floating point values intended to document the vertical discretisation associated to...
g2int * igdtmpl
Contains the data values for the Grid Definition Template specified by igdtnum.
g2int idrtnum
Data Representation Template Number (see Table 5.0).
g2int ndpts
Number of data points unpacked and returned.
g2int * idrtmpl
Contains the data values for the Data Representation Template specified by idrtnum.
#define G2_GETFLD_BAD_SEC6
Error in g2_getfld() unpacking section 6.
g2int * list_opt
(Used if numoct_opt .ne.
g2int version
GRIB edition number (2).
#define G2_GETFLD_BAD_SEC3
Error in g2_getfld() unpacking section 3.
g2int * idsect
Contains the entries in the Identification Section (Section 1).
float * fld
Array of ndpts unpacked data points.
g2int num_coord
Number of values in array coord_list.
unsigned char * local
Pointer to character array containing contents of Local Section 2, if included.
#define G2_GETFLD_BAD_END
g2_getfld() didn't find "7777" at end of message.
g2int expanded
Logical value indicating whether the data field was expanded to the grid in the case where a bit-map ...
g2int num_opt
(Used if numoct_opt .ne.
g2int igdtlen
Number of elements in igdtmpl - i.e.
#define G2_GETFLD_NO_BITMAP
In g2_getfld() previous bitmap specified, yet none exists.
g2int * bmap
Integer array containing decoded bitmap, if ibmap=0 or ibap=254.
int64_t g2int
Long integer type.
#define G2_GETFLD_INVAL_SEC
g2_getfld() encountered unrecognized section.
Header file with internal function prototypes NCEPLIBS-g2c library.