Loading...
Searching...
No Matches
g2_unpack6.c
Go to the documentation of this file.
#include "grib2_int.h"
#include <stdio.h>
#include <stdlib.h>
g2int
g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap,
g2int **bmap)
{
g2int j, isecnum;
g2int *lbmap = 0;
g2int *intbmap;
*bmap = NULL;
*iofst = *iofst + 32; /* skip Length of Section */
gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */
*iofst = *iofst + 8;
if (isecnum != 6)
{
fprintf(stderr, "g2_unpack6: Not Section 6 data.\n");
return G2_UNPACK_BAD_SEC;
}
gbit(cgrib, ibmap, *iofst, 8); /* Get bit-map indicator */
*iofst = *iofst + 8;
if (*ibmap == 0)
{ /* Unpack bitmap */
if (ngpts > 0)
lbmap = calloc(ngpts, sizeof(g2int));
if (!lbmap)
return G2_UNPACK_NO_MEM;
*bmap = lbmap;
intbmap = calloc(ngpts, sizeof(g2int));
gbits(cgrib, intbmap, *iofst, 1, 0, ngpts);
*iofst = *iofst + ngpts;
for (j = 0; j < ngpts; j++)
lbmap[j] = (g2int)intbmap[j];
free(intbmap);
}
return G2_NO_ERROR;
}
g2_unpack6
g2int g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap, g2int **bmap)
Unpack Section 6 (Bit-Map Section) of a GRIB2 message.
Definition g2_unpack6.c:32
gbit
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 ...
Definition gbits.c:20
gbits
void gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, g2int nskip, g2int n)
Unpack arbitrary size values from a packed bit string, right justifying each value in the unpacked io...
Definition gbits.c:57
G2_UNPACK_BAD_SEC
#define G2_UNPACK_BAD_SEC
Bad section number in unpacking function.
Definition grib2.h:457
G2_UNPACK_NO_MEM
#define G2_UNPACK_NO_MEM
Error allocating memory in unpack function.
Definition grib2.h:458
G2_NO_ERROR
#define G2_NO_ERROR
Function succeeded.
Definition grib2.h:431
g2int
int64_t g2int
Long integer type.
Definition grib2.h:32
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.