75 assert(cgrib && iofst && idrstmpl && fld);
77 LOG((2,
"g2c_unpack7_int *iofst %ld igdsnum %ld idrsnum %ld ndpts %ld v1 %d",
78 *iofst, igdsnum, idrsnum, ndpts, v1));
81 gbit(cgrib, &lensec, *iofst, 32);
83 LOG((3,
"lensec %ld", lensec));
86 gbit(cgrib, &isecnum, *iofst, 8);
99 if (!(lfld = calloc(ndpts ? ndpts : 1,
sizeof(
float))))
108 simunpack(cgrib + ipos, idrstmpl, ndpts, *fld);
110 else if (idrsnum == 2 || idrsnum == 3)
112 if (
comunpack(cgrib+ipos, lensec, idrsnum, idrstmpl, ndpts, *fld))
115 else if (idrsnum == 50)
118 simunpack(cgrib + ipos, idrstmpl, ndpts - 1, lfld + 1);
119 rdieee(idrstmpl + 4, lfld, 1);
121 else if (idrsnum == 51)
124 if (igdsnum >= 50 && igdsnum <= 53)
125 specunpack(cgrib + ipos, idrstmpl, ndpts, igdstmpl[0], igdstmpl[2],
130 fprintf(stderr,
"g2_unpack7: Cannot use GDT 3.%d to unpack Data Section 5.51.\n",
138 #if defined USE_JPEG2000 || defined USE_OPENJPEG
139 else if (idrsnum == 40 || idrsnum == 40000)
141 jpcunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld);
145 else if (idrsnum == 41 || idrsnum == 40010)
147 pngunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld);
151 else if (idrsnum == 42)
153 aecunpack(cgrib + ipos, lensec - 5, idrstmpl, ndpts, *fld);
159 fprintf(stderr,
"g2_unpack7: Data Representation Template 5.%d not yet "
160 "implemented.\n", (
int)idrsnum);
167 *iofst = *iofst + (8 * lensec);
217 return g2c_unpack7_int(cgrib, iofst, igdsnum, igdstmpl, idrsnum, idrstmpl,
259 g2c_unpack7(
unsigned char *cgrib,
int igdsnum,
int gds_tmpl_len,
long long int *gdstmpl,
260 int idrsnum,
int drs_tmpl_len,
long long int *drstmpl,
int ndpts,
float *fld)
263 g2int *igdstmpl = NULL, *idrstmpl;
267 LOG((1,
"g2c_unpack7 igdsnum %d gds_tmpl_len %d idrsnum %d drs_tmpl_len %d ndpts %d",
268 igdsnum, gds_tmpl_len, idrsnum, drs_tmpl_len, ndpts));
271 assert(cgrib && drstmpl && fld);
272 if (gds_tmpl_len && !gdstmpl)
278 if (!(igdstmpl = malloc(gds_tmpl_len *
sizeof(
g2int))))
280 if (!(idrstmpl = malloc(drs_tmpl_len *
sizeof(
g2int))))
285 for (i = 0; i < gds_tmpl_len; i++)
286 igdstmpl[i] = gdstmpl[i];
287 for (i = 0; i < drs_tmpl_len; i++)
288 idrstmpl[i] = drstmpl[i];
291 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)
This subroutine unpacks a data field that was packed using a complex packing algorithm as defined in ...
static g2int g2c_unpack7_int(unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstmpl, g2int idrsnum, g2int *idrstmpl, g2int ndpts, int v1, float **fld)
This subroutine 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 bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
#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)
This subroutine unpacks a spectral data field that was packed using the complex packing algorithm for...
g2int simunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, float *fld)
This subroutine unpacks a data field that was packed using a simple packing algorithm as defined in t...
void rdieee(g2int *rieee, float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.