69 static g2int one = 1, three = 3, miss = 65535;
70 g2int lensec3, iofst, ibeg, lencurr, len;
71 g2int i, j, temp, ilen, isecnum, nbits;
92 gbit(cgrib, &ilen, iofst, 32);
94 gbit(cgrib, &isecnum, iofst, 8);
105 printf(
"g2_addgrid: Section byte counts don''t add to total.\n");
106 printf(
"g2_addgrid: Sum of section byte counts = %ld\n", len);
107 printf(
"g2_addgrid: Total byte count in Section 0 = %ld\n", lencurr);
113 if (isecnum != 1 && isecnum != 2 && isecnum != 7)
115 printf(
"g2_addgrid: Section 3 can only be added after Section 1, 2 or 7.\n");
116 printf(
"g2_addgrid: Section ',isecnum,' was the last found in given GRIB message.\n");
123 sbit(cgrib, &three, iofst, 8);
125 sbit(cgrib, igds + 0, iofst, 8);
127 sbit(cgrib, igds + 1, iofst, 32);
129 sbit(cgrib, igds + 2, iofst, 8);
131 sbit(cgrib, igds + 3, iofst, 8);
137 sbit(cgrib, igds + 4, iofst, 16);
139 sbit(cgrib, &miss, iofst, 16);
161 for (i = 0; i < mapgrid->
maplen; i++)
163 nbits = abs(mapgrid->
map[i]) * 8;
164 if ((mapgrid->
map[i] >= 0) || (igdstmpl[i] >= 0))
165 sbit(cgrib, igdstmpl + i, iofst, nbits);
168 sbit(cgrib, &one, iofst, 1);
169 temp = abs(igdstmpl[i]);
170 sbit(cgrib, &temp, iofst + 1, nbits - 1);
172 iofst = iofst + nbits;
179 for (i = 0; i < mapgrid->
extlen; i++)
181 nbits = abs(mapgrid->
ext[i]) * 8;
182 if (mapgrid->
ext[i] >= 0 || igdstmpl[j] >= 0)
183 sbit(cgrib, igdstmpl + j, iofst, nbits);
186 sbit(cgrib, &one, iofst, 1);
187 temp = abs(igdstmpl[j]);
188 sbit(cgrib, &temp, iofst + 1, nbits - 1);
190 iofst = iofst + nbits;
204 sbits(cgrib, ideflist, iofst, nbits, 0, idefnum);
205 iofst = iofst + (nbits * idefnum);
209 lensec3 = (iofst - ibeg) / 8;
210 sbit(cgrib, &lensec3, ibeg, 32);
214 sbit(cgrib, &lencurr, 96, 32);
g2int g2_addgrid(unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist, g2int idefnum)
Packs a Grid Definition Section (Section 3) and adds it to 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 sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, g2int nskip, g2int n)
Store arbitrary size values into a packed bit string, taking the low order bits from each value in th...
void sbit(unsigned char *out, g2int *in, g2int iskip, g2int nbits)
Store arbitrary size values into a packed bit string, taking the low order bits from each value in th...
int g2c_check_msg(unsigned char *cgrib, g2int *lencurr, int verbose)
Check for 'GRIB' at the beginning of a GRIB message, and check to see if the message is already termi...