47 g2int *mappdslen,
float **coordlist,
g2int *numcoord)
50 g2int needext, i, j, nbits, isecnum;
51 g2int lensec, isign, newlen;
60 gbit(cgrib, &lensec, *iofst, 32);
62 gbit(cgrib, &isecnum, *iofst, 8);
72 gbit(cgrib, numcoord, *iofst, 16);
74 gbit(cgrib, ipdsnum, *iofst, 16);
83 *mappdslen = mappds->
maplen;
90 lipdstmpl = calloc(*mappdslen,
sizeof(
g2int));
99 *ipdstmpl = lipdstmpl;
101 for (i = 0; i < mappds->
maplen; i++)
103 nbits = abs(mappds->
map[i]) * 8;
104 if (mappds->
map[i] >= 0)
106 gbit(cgrib, lipdstmpl + i, *iofst, nbits);
110 gbit(cgrib, &isign, *iofst, 1);
111 gbit(cgrib, lipdstmpl + i, *iofst + 1, nbits - 1);
112 if (isign == 1) lipdstmpl[i] = -1 * lipdstmpl[i];
114 *iofst = *iofst + nbits;
126 lipdstmpl = realloc(lipdstmpl, newlen *
sizeof(
g2int));
127 *ipdstmpl = lipdstmpl;
130 for (i = *mappdslen; i < newlen; i++)
132 nbits = abs(mappds->
ext[j]) * 8;
133 if (mappds->
ext[j] >= 0)
135 gbit(cgrib, lipdstmpl + i, *iofst, nbits);
139 gbit(cgrib, &isign, *iofst, 1);
140 gbit(cgrib, lipdstmpl + i, *iofst+1, nbits-1);
142 lipdstmpl[i] = -1 * lipdstmpl[i];
144 *iofst = *iofst + nbits;
159 coordieee = calloc(*numcoord,
sizeof(
g2int));
160 lcoordlist = calloc(*numcoord,
sizeof(
float));
161 if (coordieee == 0 || lcoordlist == 0)
173 *coordlist = lcoordlist;
175 gbits(cgrib, coordieee, *iofst, 32, 0, *numcoord);
176 rdieee(coordieee, *coordlist, *numcoord);
178 *iofst = *iofst + (32 * (*numcoord));
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.
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 gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, g2int nskip, g2int n)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
#define G2_UNPACK_BAD_SEC
Bad section number in unpacking function.
#define G2_UNPACK4_BAD_PDT
In g2_unpack4(), undefined Product Definition Template.
#define G2_UNPACK_NO_MEM
Error allocating memory in unpack function.
#define G2_NO_ERROR
Function succeeded.
int64_t g2int
Long integer type.
Header file with internal function prototypes NCEPLIBS-g2c library.
g2int * ext
Number of octets of each entry in the extension part of the template.
gtemplate * extpdstemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Product Definition Template,...
g2int extlen
Number of entries in the template extension.
g2int * map
Number of octets of each entry in the static part of the template.
g2int needext
Indicates whether or not the template needs to be extended.
gtemplate * getpdstemplate(g2int number)
This subroutine returns PDS template information for a specified Product Definition Template.
g2int maplen
Number of entries in the static part of the template.
void rdieee(g2int *rieee, float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.
Struct for GRIB template, returned by getgridtemplate().