Go to the documentation of this file.
95 g2int have3 = 0, have4 = 0, have5 = 0, have6 = 0, have7 = 0;
96 g2int numfld = 0, j, n, istart, iofst, ipos;
97 g2int disc, ver, lensec0, lengrib, lensec, isecnum;
112 printf(
"g2_getfld: Request for field number must be positive.\n");
119 for (j = 0; j < 100; j++)
121 if (cgrib[j] ==
'G' && cgrib[j + 1] ==
'R' &&cgrib[j + 2] ==
'I' &&
130 printf(
"g2_getfld: Beginning characters GRIB not found.\n");
136 iofst = 8 * (istart + 6);
137 gbit(cgrib, &disc, iofst, 8);
139 gbit(cgrib, &ver, iofst, 8);
142 gbit(cgrib, &lengrib, iofst, 32);
145 ipos = istart + lensec0;
150 printf(
"g2_getfld: can only decode GRIB edition 2.\n");
161 if (cgrib[ipos] ==
'7' && cgrib[ipos + 1] ==
'7' && cgrib[ipos + 2] ==
'7' &&
162 cgrib[ipos + 3] ==
'7')
168 if (ipos != istart + lengrib)
170 printf(
"g2_getfld: '7777' found, but not where expected.\n");
179 gbit(cgrib, &lensec, iofst, 32);
181 gbit(cgrib, &isecnum, iofst, 8);
185 if (isecnum < 1 || isecnum > 7)
187 printf(
"g2_getfld: Unrecognized Section Encountered=%ld\n", isecnum);
248 if (numfld == ifldnum)
269 if (isecnum == 5 && numfld == ifldnum)
289 bmpsave = lgfld->
bmap;
298 if (lgfld->
ibmap == 254)
301 lgfld->
bmap = bmpsave;
304 printf(
"g2_getfld: Prev bit-map specified, but none exist.\n");
321 if (isecnum == 7 && numfld == ifldnum && unpack)
328 printf(
"g2_getfld: return from g2_unpack7 = %d \n", (
int)jerr);
337 if (lgfld->
ibmap != 255 && lgfld->
bmap != 0)
342 newfld = calloc(lgfld->
ngrdpts,
sizeof(
float));
343 for (j = 0; j < lgfld->
ngrdpts; j++)
345 if (lgfld->
bmap[j] == 1)
346 newfld[j] = lgfld->
fld[n++];
365 ipos = ipos + lensec;
366 if (ipos > istart + lengrib)
368 printf(
"g2_getfld: '7777' not found at end of GRIB message.\n");
375 if (unpack && have3 && have4 && have5 && have6 && have7)
380 if (!unpack && have3 && have4 && have5 && have6)
386 printf(
"g2_getfld: GRIB message contained %ld different fields.\n", numfld);
387 printf(
"g2_getfld: The request was for field %ld.\n", ifldnum);
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.
g2int * igdtmpl
Contains the data values for the Grid Definition Template specified by igdtnum.
#define G2_GETFLD_NO_BITMAP
In g2_getfld() previous bitmap specified, yet none exists.
#define G2_GETFLD_BAD_SEC7
Error in g2_getfld() unpacking section 7.
g2int ngrdpts
Number of grid points in the defined grid.
#define G2_GETFLD_BAD_SEC6
Error in g2_getfld() unpacking section 6.
g2int unpacked
Logical value indicating whether the bitmap and data values were unpacked.
g2int ifldnum
Field number within GRIB message.
#define G2_GETFLD_BAD_SEC3
Error in g2_getfld() unpacking section 3.
g2int idrtlen
Number of elements in idrtmpl.
#define G2_NO_ERROR
Function succeeded.
g2int ibmap
Bitmap indicator (see Table 6.0).
g2int griddef
Source of grid definition (see Table 3.0).
g2int numoct_opt
Number of octets needed for each additional grid points definition.
g2int * idsect
Contains the entries in the Identification Section (Section 1).
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.
Header file with internal function prototypes NCEPLIBS-g2c library.
#define G2_GETFLD_WRONG_NFLDS
In g2_getfld() message did not contain the requested number of data fields.
#define G2_GETFLD_WRONG_END
g2_info() found "7777" not where expected.
g2int * idrtmpl
Contains the data values for the Data Representation Template specified by idrtnum.
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.
#define G2_GETFLD_BAD_SEC4
Error in g2_getfld() unpacking section 4.
g2int interp_opt
Interpretation of list for optional points definition.
g2int ipdtlen
Number of elements in ipdtmpl - i.e.
void gbit(unsigned char *in, g2int *iout, g2int iskip, g2int nbits)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
void g2_free(gribfield *gfld)
This routine frees up memory that was allocated for struct gribfield.
#define G2_GETFLD_BAD_SEC5
Error in g2_getfld() unpacking section 5.
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.
g2int discipline
Message Discipline (see Table 0.0).
g2int num_opt
(Used if numoct_opt .ne.
#define G2_GETFLD_BAD_END
g2_getfld() didn't find "7777" at end of message.
float * coord_list
Array containing floating point values intended to document the vertical discretisation associated to...
g2int ipdtnum
Product Definition Template Number (see Table 4.0).
int64_t g2int
Long integer type.
#define G2_GETFLD_GRIB_VERSION
Wrong GRIB version for g2_getfld(), must be 2.
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.
float * fld
Array of ndpts unpacked data points.
unsigned char * local
Pointer to character array containing contents of Local Section 2, if included.
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.
g2int idrtnum
Data Representation Template Number (see Table 5.0).
#define G2_GETFLD_INVAL
g2_getfld() data field request number was not positive.
g2int num_coord
Number of values in array coord_list.
g2int expanded
Logical value indicating whether the data field was expanded to the grid in the case where a bit-map ...
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.
g2int version
GRIB edition number (2).
g2int locallen
Length of array local.
#define G2_GETFLD_INVAL_SEC
g2_getfld() encountered unrecognized section.
g2int ndpts
Number of data points unpacked and returned.
g2int igdtlen
Number of elements in igdtmpl - i.e.
g2int * list_opt
(Used if numoct_opt .ne.
g2int igdtnum
Grid Definition Template Number (See Table 3.1).
#define G2_GETFLD_BAD_SEC1
Error in g2_getfld() unpacking section 1.
#define G2_GETFLD_BAD_SEC2
Error in g2_getfld() unpacking section 2.
g2int * bmap
Integer array containing decoded bitmap, if ibmap=0 or ibap=254.
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),...
#define G2_GETFLD_NO_GRIB
g2_getfld() can't find beginning characters "GRIB".
g2int * ipdtmpl
Contains the data values for the Product Definition Template specified by ipdtnum.
g2int idsectlen
Number of elements in idsect.