60 g2int ierr, i, j, nbits, isecnum;
61 g2int lensec, ibyttem = 0, isign, newlen;
62 g2int *ligds, *ligdstmpl = NULL, *lideflist = NULL;
70 gbit(cgrib, &lensec, *iofst, 32);
72 gbit(cgrib, &isecnum, *iofst, 8);
84 ligds = calloc(5,
sizeof(
g2int));
87 gbit(cgrib, &ligds[0], *iofst, 8);
89 gbit(cgrib, &ligds[1], *iofst, 32);
91 gbit(cgrib, &ligds[2], *iofst, 8);
93 gbit(cgrib, &ligds[3], *iofst, 8);
95 gbit(cgrib, &ligds[4], *iofst, 16);
98 if (ligds[4] != 65535)
107 *mapgridlen = mapgrid->
maplen;
114 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));
204 *ideflist = lideflist;
205 gbits(cgrib, lideflist, *iofst, nbits, 0, *idefnum);
206 *iofst = *iofst + (nbits * *idefnum);
g2int g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, g2int *mapgridlen, g2int **ideflist, g2int *idefnum)
This routine unpacks Section 3 (Grid 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 * extgridtemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Grid Definition Template,...
gtemplate * getgridtemplate(g2int number)
This subroutine returns grid template information for a specified Grid Definition Template for [Secti...