73 static g2int one = 1, three = 3, miss = 65535;
74 g2int lensec3, iofst, ibeg, lencurr, len;
75 g2int i, j, temp, ilen, isecnum, nbits;
96 gbit(cgrib, &ilen, iofst, 32);
98 gbit(cgrib, &isecnum, iofst, 8);
109 printf(
"g2_addgrid: Section byte counts don''t add to total.\n");
110 printf(
"g2_addgrid: Sum of section byte counts = %ld\n", len);
111 printf(
"g2_addgrid: Total byte count in Section 0 = %ld\n", lencurr);
117 if (isecnum != 1 && isecnum != 2 && isecnum != 7)
119 printf(
"g2_addgrid: Section 3 can only be added after Section 1, 2 or 7.\n");
120 printf(
"g2_addgrid: Section ',isecnum,' was the last found in given GRIB message.\n");
127 sbit(cgrib, &three, iofst, 8);
129 sbit(cgrib, igds+0, iofst, 8);
131 sbit(cgrib, igds+1, iofst, 32);
133 sbit(cgrib, igds+2, iofst, 8);
135 sbit(cgrib, igds+3, iofst, 8);
141 sbit(cgrib, igds+4, iofst, 16);
143 sbit(cgrib, &miss, iofst, 16);
165 for (i = 0; i < mapgrid->
maplen; i++)
167 nbits = abs(mapgrid->
map[i]) * 8;
168 if ((mapgrid->
map[i] >= 0) || (igdstmpl[i] >= 0))
169 sbit(cgrib, igdstmpl+i, iofst, nbits);
172 sbit(cgrib, &one, iofst, 1);
173 temp = abs(igdstmpl[i]);
174 sbit(cgrib, &temp, iofst+1, nbits-1);
176 iofst = iofst + nbits;
183 for (i = 0; i < mapgrid->
extlen; i++)
185 nbits = abs(mapgrid->
ext[i]) * 8;
186 if (mapgrid->
ext[i] >= 0 || igdstmpl[j] >= 0)
187 sbit(cgrib, igdstmpl + j, iofst, nbits);
190 sbit(cgrib, &one, iofst, 1);
191 temp = abs(igdstmpl[j]);
192 sbit(cgrib, &temp, iofst + 1, nbits - 1);
194 iofst = iofst + nbits;
208 sbits(cgrib, ideflist, iofst, nbits, 0, idefnum);
209 iofst = iofst + (nbits * idefnum);
213 lensec3 = (iofst - ibeg) / 8;
214 sbit(cgrib, &lensec3, ibeg, 32);
218 sbit(cgrib, &lencurr, 96, 32);
g2int g2_addgrid(unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist, g2int idefnum)
This routine packs up 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 bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
void sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, g2int nskip, g2int n)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
void sbit(unsigned char *out, g2int *in, g2int iskip, g2int nbits)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
#define G2_BAD_SEC_COUNTS
Sum of Section byte counts doesn't add to total byte count.
#define G2_BAD_SEC
Previous Section was unexpected.
#define G2_ADDGRID_BAD_GDT
In g2_addgrid() Could not find requested Grid Definition Template.
#define G2_ADD_MSG_COMPLETE
GRIB message already complete.
#define G2_ADD_MSG_INIT
GRIB message was not initialized - call g2_create() first.
#define G2C_ENOTGRIB
GRIB header not found.
#define G2C_EMSGCOMPLETE
GRIB message already complete.
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.
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...
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().