106 g2int have3 = 0, have4 = 0, have5 = 0, have6 = 0, have7 = 0, ierr = 0, jerr;
107 g2int numfld = 0, j, n, istart, iofst, ipos;
108 g2int disc, ver, lensec0, lengrib, lensec, isecnum;
130 printf(
"g2_getfld: Request for field number must be positive.\n");
137 for (j = 0; j < 100; j++) {
138 if (cgrib[j] ==
'G' && cgrib[j + 1] ==
'R' &&cgrib[j + 2] ==
'I' &&
139 cgrib[j + 3] ==
'B') {
145 printf(
"g2_getfld: Beginning characters GRIB not found.\n");
151 iofst = 8 * (istart + 6);
152 gbit(cgrib, &disc, iofst, 8);
154 gbit(cgrib, &ver, iofst, 8);
157 gbit(cgrib, &lengrib, iofst, 32);
160 ipos = istart + lensec0;
164 printf(
"g2_getfld: can only decode GRIB edition 2.\n");
174 if (cgrib[ipos] ==
'7' && cgrib[ipos+1] ==
'7' && cgrib[ipos+2] ==
'7' &&
175 cgrib[ipos+3] ==
'7') {
178 if (ipos != (istart+lengrib)) {
179 printf(
"g2_getfld: '7777' found, but not where expected.\n");
186 iofst = (ipos - 1) * 8;
188 gbit(cgrib, &lensec, iofst, 32);
190 gbit(cgrib, &isecnum, iofst, 8);
195 if (isecnum < 1 || isecnum > 7) {
196 printf(
"g2_getfld: Unrecognized Section Encountered=%ld\n", isecnum);
215 if (lgfld->
local != 0)
252 if (numfld == ifldnum) {
273 if (isecnum == 5 && numfld == ifldnum) {
290 bmpsave = lgfld->
bmap;
295 if (lgfld->
ibmap == 254)
297 lgfld->
bmap = bmpsave;
299 printf(
"g2_getfld: Prev bit-map specified, but none exist.\n");
320 if (isecnum == 7 && numfld == ifldnum && unpack) {
329 if (lgfld->
ibmap != 255 && lgfld->
bmap != 0) {
333 for (j = 0;j<lgfld->
ngrdpts;j++) {
334 if (lgfld->
bmap[j] == 1)
335 newfld[j] = lgfld->
fld[n++];
350 printf(
"g2_getfld: return from g2_unpack7 = %d \n", (
int)jerr);
358 ipos = ipos + lensec;
359 if (ipos > (istart + lengrib)) {
360 printf(
"g2_getfld: '7777' not found at end of GRIB message.\n");
367 if (unpack && have3 && have4 && have5 && have6 && have7)
372 if ((!unpack) && have3 && have4 && have5 && have6)
379 printf(
"g2_getfld: GRIB message contained %ld different fields.\n", numfld);
380 printf(
"g2_getfld: The request was for field %ld.\n", ifldnum);
g2int g2_unpack7(unsigned char *, g2int *, g2int, g2int *, g2int, g2int *, g2int, g2float **)
This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2.
g2int g2_unpack6(unsigned char *, g2int *, g2int, g2int *, g2int **)
This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.
g2int g2_unpack1(unsigned char *, g2int *, g2int **, g2int *)
This subroutine unpacks Section 1 - Identification Section as defined in GRIB Edition 2.
g2int g2_unpack5(unsigned char *, g2int *, g2int *, g2int *, g2int **, g2int *)
This subroutine unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2.
g2int g2_unpack2(unsigned char *, g2int *, g2int *, unsigned char **)
This subroutine unpacks Section 2 (Local Use Section) as defined in GRIB Edition 2.
g2int g2_unpack3(unsigned char *, g2int *, g2int **, g2int **, g2int *, g2int **, g2int *)
This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.
g2int g2_unpack4(unsigned char *, g2int *, g2int *, g2int **, g2int *, g2float **, g2int *)
This subroutine unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2.
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),...
void gbit(unsigned char *in, g2int *iout, g2int iskip, g2int nbyte)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
Header file for NCEPLIBS-g2c library.
g2int igdtnum
Grid Definition Template Number (See Table 3.1).
g2int locallen
Length of array local.
g2int ibmap
Bitmap indicator (see Table 6.0).
g2int interp_opt
Interpretation of list for optional points definition.
g2int ngrdpts
Number of grid points in the defined grid.
g2int ifldnum
Field number within GRIB message.
g2float * coord_list
Array containing floating point values intended to document the vertical discretisation associated to...
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.
g2int discipline
Message Discipline (see Table 0.0).
g2int numoct_opt
Number of octets needed for each additional grid points definition.
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.
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.
g2int * list_opt
(Used if numoct_opt .ne.
g2int version
GRIB edition number (2).
g2int * idsect
Contains the entries in the Identification Section (Section 1).
g2float * 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.
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.
g2int * bmap
Integer array containing decoded bitmap, if ibmap=0 or ibap=254.
int64_t g2int
Long integer type.