71 g2int mapsec1len = 13;
72 g2int mapsec1[13] = {2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1};
73 g2int i, j, istart, iofst, lengrib, lensec0, lensec1;
74 g2int ipos, isecnum, nbits, lensec;
83 for (j = 0; j < 100; j++)
85 if (cgrib[j] ==
'G' && cgrib[j + 1] ==
'R' && cgrib[j + 2] ==
'I' &&
94 printf(
"g2_info: Beginning characters GRIB not found.");
98 LOG((3,
"msg found at byte %ld", istart));
101 iofst = 8 * (istart + 6);
102 gbit(cgrib, listsec0, iofst, 8);
104 gbit(cgrib, &listsec0[1], iofst, 8);
108 gbit(cgrib, &lengrib, iofst, 64);
111 listsec0[2] = lengrib;
113 ipos = istart + lensec0;
114 LOG((3,
"unpacked section 0, lengrib %ld now at byte %ld", lengrib, ipos));
117 if (listsec0[1] != 2)
119 printf(
"g2_info: can only decode GRIB edition 2.");
124 gbit(cgrib, &lensec1, iofst, 32);
126 gbit(cgrib, &isecnum, iofst, 8);
130 printf(
"g2_info: Could not find section 1.");
137 for (i = 0; i < mapsec1len; i++)
139 nbits = mapsec1[i] * 8;
140 gbit(cgrib, &listsec1[i], iofst, nbits);
141 iofst = iofst + nbits;
143 ipos = ipos + lensec1;
144 LOG((3,
"unpacked section 1, now at byte %ld", ipos));
151 if (cgrib[ipos] ==
'7' && cgrib[ipos + 1] ==
'7' && cgrib[ipos + 2] ==
'7' &&
152 cgrib[ipos + 3] ==
'7')
154 LOG((3,
"found 7777 at byte %ld", ipos));
156 if (ipos != (istart + lengrib))
158 printf(
"g2_info: '7777' found, but not where expected.\n");
165 gbit(cgrib, &lensec, iofst, 32);
167 gbit(cgrib, &isecnum, iofst, 8);
168 LOG((3,
"found section number %ld of length %ld", isecnum, lensec));
170 ipos = ipos + lensec;
171 if (ipos > (istart + lengrib))
173 printf(
"g2_info: '7777' not found at end of GRIB message.\n");
176 if (isecnum >= 2 && isecnum <= 7)
182 else if (isecnum == 4)
187 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)
This subroutine searches through a GRIB2 message and returns the number of gridded fields found in th...
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...
#define G2_INFO_NO_SEC1
g2_info() can't find section 1.
#define G2_INFO_INVAL_SEC
g2_info() found invalid section number.
#define G2_INFO_GRIB_VERSION
Wrong GRIB version for g2_info(), must be 2.
#define G2_INFO_BAD_END
g2_info() didn't find "7777" at end of message.
int64_t g2int
Long integer type.
#define G2_INFO_NO_GRIB
g2_info() can't find beginning characters "GRIB".
#define G2_INFO_WRONG_END
g2_info() found "7777" not where expected.
Header file with internal function prototypes NCEPLIBS-g2c library.
#define LOG(e)
Ignore logging to stdout.