65 g2int i, j, nbits, isecnum;
66 g2int lensec, ibyttem = 0, isign, newlen;
67 g2int *ligds, *ligdstmpl = NULL, *lideflist = NULL;
74 gbit(cgrib, &lensec, *iofst, 32);
76 gbit(cgrib, &isecnum, *iofst, 8);
86 ligds = calloc(5,
sizeof(
g2int));
89 gbit(cgrib, &ligds[0], *iofst, 8);
91 gbit(cgrib, &ligds[1], *iofst, 32);
93 gbit(cgrib, &ligds[2], *iofst, 8);
95 gbit(cgrib, &ligds[3], *iofst, 8);
97 gbit(cgrib, &ligds[4], *iofst, 16);
100 if (ligds[4] != 65535)
108 *mapgridlen = mapgrid->
maplen;
115 if (!(ligdstmpl = calloc(*mapgridlen,
sizeof(
g2int))))
123 *igdstmpl = ligdstmpl;
126 for (i = 0; i < *mapgridlen; i++)
128 nbits = abs(mapgrid->
map[i]) * 8;
129 if (mapgrid->
map[i] >= 0)
131 gbit(cgrib, ligdstmpl + i, *iofst, nbits);
135 gbit(cgrib, &isign, *iofst, 1);
136 gbit(cgrib, ligdstmpl + i, *iofst + 1, nbits - 1);
138 ligdstmpl[i] = -1 * ligdstmpl[i];
140 *iofst = *iofst + nbits;
141 ibyttem = ibyttem + abs(mapgrid->
map[i]);
154 ligdstmpl = realloc(ligdstmpl, newlen *
sizeof(
g2int));
155 *igdstmpl = ligdstmpl;
157 for (i = *mapgridlen; i < newlen; i++)
159 nbits = abs(mapgrid->
ext[j]) * 8;
160 if (mapgrid->
ext[j] >= 0)
162 gbit(cgrib, ligdstmpl + i, *iofst, nbits);
166 gbit(cgrib, &isign, *iofst, 1);
167 gbit(cgrib, ligdstmpl + i, *iofst + 1, nbits - 1);
169 ligdstmpl[i] = -1 * ligdstmpl[i];
171 *iofst = *iofst + nbits;
172 ibyttem = ibyttem + abs(mapgrid->
ext[j]);
175 *mapgridlen = newlen;
193 nbits = ligds[2] * 8;
194 *idefnum = (lensec - 14 - ibyttem) / ligds[2];
196 lideflist = calloc(*idefnum,
sizeof(
g2int));
203 *ideflist = lideflist;
204 gbits(cgrib, lideflist, *iofst, nbits, 0, *idefnum);
205 *iofst = *iofst + (nbits * *idefnum);
g2int g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, g2int *mapgridlen, g2int **ideflist, g2int *idefnum)
Unpack Section 3 (Grid Definition 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 ...
void gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, g2int nskip, g2int n)
Unpack arbitrary size values from a packed bit string, right justifying each value in the unpacked io...