39 static unsigned char G = 0x47;
40 static unsigned char R = 0x52;
41 static unsigned char I = 0x49;
42 static unsigned char B = 0x42;
43 static unsigned char seven = 0x37;
46 g2int j, k, lensec2, iofst, ibeg, lencurr, ilen, len, istart;
51 if (cgrib[0] != G || cgrib[1] != R || cgrib[2] != I || cgrib[3] != B)
53 printf(
"g2_addlocal: GRIB not found in given message.\n");
54 printf(
"g2_addlocal: Call to routine g2_create required to initialize GRIB messge.\n");
60 gbit(cgrib, &lencurr, 96, 32);
63 if (cgrib[lencurr - 4] == seven && cgrib[lencurr - 3] == seven &&
64 cgrib[lencurr - 2] == seven && cgrib[lencurr - 1] == seven)
66 printf(
"g2_addlocal: GRIB message already complete. Cannot add new section.\n");
78 gbit(cgrib, &ilen, iofst, 32);
80 gbit(cgrib, &isecnum, iofst, 8);
89 printf(
"g2_addlocal: Section byte counts don't add to total.\n");
90 printf(
"g2_addlocal: Sum of section byte counts = %ld\n", len);
91 printf(
"g2_addlocal: Total byte count in Section 0 = %ld\n", lencurr);
98 if (isecnum != 1 && isecnum != 7)
100 printf(
"g2_addlocal: Section 2 can only be added after Section 1 or Section 7.\n");
101 printf(
"g2_addlocal: Section %ld was the last found in given GRIB message.\n", isecnum);
109 sbit(cgrib, &two, iofst, 8);
110 istart = lencurr + 5;
113 for (j = istart; j < istart + lcsec2; j++)
114 cgrib[j] = csec2[k++];
117 lensec2 = lcsec2 + 5;
118 sbit(cgrib, &lensec2, ibeg, 32);
122 sbit(cgrib, &lencurr, 96, 32);
g2int g2_addlocal(unsigned char *cgrib, unsigned char *csec2, g2int lcsec2)
This routine adds a Local Use Section (Section 2) to a GRIB2 message.
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 sbit(unsigned char *out, g2int *in, g2int iskip, g2int nbyte)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.