74 assert(cgrib && iofst && idrstmpl && fld);
76 LOG((2,
"g2c_unpack7_int *iofst %ld igdsnum %ld idrsnum %ld ndpts %ld v1 %d",
77 *iofst, igdsnum, idrsnum, ndpts, v1));
80 gbit(cgrib, &lensec, *iofst, 32);
82 LOG((3,
"lensec %ld", lensec));
85 gbit(cgrib, &isecnum, *iofst, 8);
98 if (!(lfld = calloc(ndpts ? ndpts : 1,
sizeof(float))))
107 simunpack(cgrib + ipos, idrstmpl, ndpts, *fld);
109 else if (idrsnum == 2 || idrsnum == 3)
111 if (
comunpack(cgrib+ipos, lensec, idrsnum, idrstmpl, ndpts, *fld))
114 else if (idrsnum == 50)
117 simunpack(cgrib + ipos, idrstmpl, ndpts - 1, lfld + 1);
118 rdieee(idrstmpl + 4, lfld, 1);
120 else if (idrsnum == 51)
123 if (igdsnum >= 50 && igdsnum <= 53)
124 specunpack(cgrib + ipos, idrstmpl, ndpts, igdstmpl[0], igdstmpl[2],
129 fprintf(stderr,
"g2_unpack7: Cannot use GDT 3.%d to unpack Data Section 5.51.\n",
137#if defined USE_JPEG2000 || defined USE_OPENJPEG
138 else if (idrsnum == 40 || idrsnum == 40000)
140 jpcunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld);
144 else if (idrsnum == 41 || idrsnum == 40010)
146 pngunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld);
150 else if (idrsnum == 42)
152 aecunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld);
158 fprintf(stderr,
"g2_unpack7: Data Representation Template 5.%d not yet "
159 "implemented.\n", (
int)idrsnum);
166 *iofst = *iofst + (8 * lensec);
216 return g2c_unpack7_int(cgrib, iofst, igdsnum, igdstmpl, idrsnum, idrstmpl,
258g2c_unpack7(
unsigned char *cgrib,
int igdsnum,
int gds_tmpl_len,
long long int *gdstmpl,
259 int idrsnum,
int drs_tmpl_len,
long long int *drstmpl,
int ndpts,
float *fld)
262 g2int *igdstmpl = NULL, *idrstmpl;
266 LOG((1,
"g2c_unpack7 igdsnum %d gds_tmpl_len %d idrsnum %d drs_tmpl_len %d ndpts %d",
267 igdsnum, gds_tmpl_len, idrsnum, drs_tmpl_len, ndpts));
270 assert(cgrib && drstmpl && fld);
271 if (gds_tmpl_len && !gdstmpl)
277 if (!(igdstmpl = malloc(gds_tmpl_len *
sizeof(
g2int))))
279 if (!(idrstmpl = malloc(drs_tmpl_len *
sizeof(
g2int))))
284 for (i = 0; i < gds_tmpl_len; i++)
285 igdstmpl[i] = gdstmpl[i];
286 for (i = 0; i < drs_tmpl_len; i++)
287 idrstmpl[i] = drstmpl[i];
290 ret =
g2c_unpack7_int(cgrib, &iofst, igdsnum, igdstmpl, idrsnum, idrstmpl,
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...
int comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, g2int *idrstmpl, g2int ndpts, float *fld)
Unpack a data field that was packed using a complex packing algorithm, using info from the GRIB2 Data...
static g2int g2c_unpack7_int(unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstmpl, g2int idrsnum, g2int *idrstmpl, g2int ndpts, int v1, float **fld)
Unpacks Section 7 (Data 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.
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.
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 ...
#define G2_UNPACK7_BAD_DRT
In g2_unpack7(), unrecognized Data Representation Template.
#define G2_UNPACK_BAD_SEC
Bad section number in unpacking function.
#define G2_UNPACK7_CORRUPT_SEC
In g2_unpack7(), corrupt section 7.
#define G2C_ENOMEM
Out of memory.
#define G2_UNPACK_NO_MEM
Error allocating memory in unpack function.
#define G2_UNPACK7_WRONG_GDT
In g2_unpack7(), need one of GDT 3.50 through 3.53 to decode DRT 5.51.
#define G2_NO_ERROR
Function succeeded.
#define G2C_EINVAL
Invalid input.
int64_t g2int
Long integer type.
Header file with internal function prototypes NCEPLIBS-g2c library.
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...
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...
#define LOG(e)
Ignore logging to stdout.
g2int specunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, g2int JJ, g2int KK, g2int MM, float *fld)
Unpack a spectral data field that was packed using the complex packing algorithm for spherical harmon...
g2int simunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, float *fld)
Unpack a data field that was packed using a simple packing algorithm, using info from the GRIB2 Data ...
void rdieee(g2int *rieee, float *a, g2int num)
Read a list of real values in 32-bit IEEE floating point format.