49 g2int ierr, needext, i, j, nbits, isecnum;
50 g2int lensec, isign, newlen;
60 gbit(cgrib, &lensec, *iofst, 32);
62 gbit(cgrib, &isecnum, *iofst, 8);
74 gbit(cgrib, numcoord, *iofst, 16);
76 gbit(cgrib, ipdsnum, *iofst, 16);
87 *mappdslen = mappds->
maplen;
94 lipdstmpl = calloc(*mappdslen,
sizeof(
g2int));
104 *ipdstmpl = lipdstmpl;
106 for (i = 0; i < mappds->
maplen; i++)
108 nbits = abs(mappds->
map[i]) * 8;
109 if (mappds->
map[i] >= 0)
111 gbit(cgrib, lipdstmpl + i, *iofst, nbits);
115 gbit(cgrib, &isign, *iofst, 1);
116 gbit(cgrib, lipdstmpl + i, *iofst + 1, nbits - 1);
117 if (isign == 1) lipdstmpl[i] = -1 * lipdstmpl[i];
119 *iofst = *iofst + nbits;
131 lipdstmpl = realloc(lipdstmpl, newlen *
sizeof(
g2int));
132 *ipdstmpl = lipdstmpl;
135 for (i = *mappdslen; i < newlen; i++)
137 nbits = abs(mappds->
ext[j]) * 8;
138 if (mappds->
ext[j] >= 0)
140 gbit(cgrib, lipdstmpl + i, *iofst, nbits);
144 gbit(cgrib, &isign, *iofst, 1);
145 gbit(cgrib, lipdstmpl + i, *iofst+1, nbits-1);
147 lipdstmpl[i] = -1 * lipdstmpl[i];
149 *iofst = *iofst + nbits;
164 coordieee = calloc(*numcoord,
sizeof(
g2int));
165 lcoordlist = calloc(*numcoord,
sizeof(
g2float));
166 if (coordieee == 0 || lcoordlist == 0)
179 *coordlist = lcoordlist;
181 gbits(cgrib, coordieee, *iofst, 32, 0, *numcoord);
182 rdieee(coordieee, *coordlist, *numcoord);
184 *iofst = *iofst + (32 * (*numcoord));
g2int g2_unpack4(unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, g2int *mappdslen, g2float **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 nbyte)
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 nbyte, g2int nskip, g2int n)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
Header file for NCEPLIBS-g2c library.
g2int * ext
Number of octets of each entry in the extension part of the 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.
g2int maplen
Number of entries in the static part of the template.
int64_t g2int
Long integer type.
Struct for GRIB template.
gtemplate * extpdstemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Product Definition Template,...
gtemplate * getpdstemplate(g2int number)
This subroutine returns PDS template information for a specified Product Definition Template.
void rdieee(g2int *rieee, g2float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.