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)
This routine unpacks Section 3 (Grid Definition Section) from 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...
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_UNPACK_NO_MEM
Error allocating memory in unpack function.
#define G2_NO_ERROR
Function succeeded.
#define G2_UNPACK3_BAD_GDT
In g2_unpack3(), undefined Grid Definition Template.
int64_t g2int
Long integer type.
Header file with internal function prototypes NCEPLIBS-g2c library.
gtemplate * extgridtemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Grid Definition Template,...
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.
gtemplate * getgridtemplate(g2int number)
This subroutine returns grid template information for a specified Grid Definition Template for [Secti...
Struct for GRIB template, returned by getgridtemplate().