NCEPLIBS-g2c 2.0.0
Loading...
Searching...
No Matches
g2_unpack6.c
Go to the documentation of this file.
1
5#include "grib2_int.h"
6#include <stdio.h>
7#include <stdlib.h>
8
32g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap,
33 g2int **bmap)
34{
35 g2int j, isecnum;
36 g2int *lbmap = 0;
37 g2int *intbmap;
38
39 *bmap = NULL;
40
41 *iofst = *iofst + 32; /* skip Length of Section */
42 gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */
43 *iofst = *iofst + 8;
44
45 if (isecnum != 6)
46 {
47 fprintf(stderr, "g2_unpack6: Not Section 6 data.\n");
48 return G2_UNPACK_BAD_SEC;
49 }
50
51 gbit(cgrib, ibmap, *iofst, 8); /* Get bit-map indicator */
52 *iofst = *iofst + 8;
53
54 if (*ibmap == 0)
55 { /* Unpack bitmap */
56 if (ngpts > 0)
57 lbmap = calloc(ngpts, sizeof(g2int));
58 if (!lbmap)
59 return G2_UNPACK_NO_MEM;
60
61 *bmap = lbmap;
62 intbmap = calloc(ngpts, sizeof(g2int));
63 gbits(cgrib, intbmap, *iofst, 1, 0, ngpts);
64 *iofst = *iofst + ngpts;
65 for (j = 0; j < ngpts; j++)
66 lbmap[j] = (g2int)intbmap[j];
67 free(intbmap);
68 }
69
70 return G2_NO_ERROR;
71}
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
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
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
#define G2_UNPACK_BAD_SEC
Bad section number in unpacking function.
Definition grib2.h:449
#define G2_UNPACK_NO_MEM
Error allocating memory in unpack function.
Definition grib2.h:450
#define G2_NO_ERROR
Function succeeded.
Definition grib2.h:423
int64_t g2int
Long integer type.
Definition grib2.h:32
Header file with internal function prototypes NCEPLIBS-g2c library.