73 g2int mapsec1len = 13;
74 g2int mapsec1[13] = {2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1};
75 g2int i, j, istart, iofst, lengrib, lensec0, lensec1;
76 g2int ipos, isecnum, nbits, lensec;
85 for (j = 0; j < 100; j++)
87 if (cgrib[j] ==
'G' && cgrib[j + 1] ==
'R' && cgrib[j + 2] ==
'I' &&
96 printf(
"g2_info: Beginning characters GRIB not found.");
100 LOG((3,
"msg found at byte %ld", istart));
103 iofst = 8 * (istart + 6);
104 gbit(cgrib, listsec0, iofst, 8);
106 gbit(cgrib, &listsec0[1], iofst, 8);
110 gbit(cgrib, &lengrib, iofst, 64);
113 listsec0[2] = lengrib;
115 ipos = istart + lensec0;
116 LOG((3,
"unpacked section 0, lengrib %ld now at byte %ld", lengrib, ipos));
119 if (listsec0[1] != 2)
121 printf(
"g2_info: can only decode GRIB edition 2.");
126 gbit(cgrib, &lensec1, iofst, 32);
128 gbit(cgrib, &isecnum, iofst, 8);
132 printf(
"g2_info: Could not find section 1.");
139 for (i = 0; i < mapsec1len; i++)
141 nbits = mapsec1[i] * 8;
142 gbit(cgrib, &listsec1[i], iofst, nbits);
143 iofst = iofst + nbits;
145 ipos = ipos + lensec1;
146 LOG((3,
"unpacked section 1, now at byte %ld", ipos));
153 if (cgrib[ipos] ==
'7' && cgrib[ipos + 1] ==
'7' && cgrib[ipos + 2] ==
'7' &&
154 cgrib[ipos + 3] ==
'7')
156 LOG((3,
"found 7777 at byte %ld", ipos));
158 if (ipos != (istart + lengrib))
160 printf(
"g2_info: '7777' found, but not where expected.\n");
167 gbit(cgrib, &lensec, iofst, 32);
169 gbit(cgrib, &isecnum, iofst, 8);
170 LOG((3,
"found section number %ld of length %ld", isecnum, lensec));
172 ipos = ipos + lensec;
173 if (ipos > (istart + lengrib))
175 printf(
"g2_info: '7777' not found at end of GRIB message.\n");
178 if (isecnum >= 2 && isecnum <= 7)
184 else if (isecnum == 4)
189 printf(
"g2_info: Invalid section number found in GRIB message: %ld\n", isecnum);
g2int g2_info(unsigned char *cgrib, g2int *listsec0, g2int *listsec1, g2int *numfields, g2int *numlocal)
Search through a GRIB2 message and return the number of gridded fields found in the message and the n...
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 ...