NCEPLIBS-g2c  1.7.0
g2_unpack6.c
Go to the documentation of this file.
1 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "grib2_int.h"
8 
32 g2int
33 g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap,
34  g2int **bmap)
35 {
36  g2int j, isecnum;
37  g2int *lbmap = 0;
38  g2int *intbmap;
39 
40  *bmap = NULL;
41 
42  *iofst = *iofst + 32; /* skip Length of Section */
43  gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */
44  *iofst = *iofst + 8;
45 
46  if (isecnum != 6)
47  {
48  fprintf(stderr, "g2_unpack6: Not Section 6 data.\n");
49  return G2_UNPACK_BAD_SEC;
50  }
51 
52  gbit(cgrib, ibmap, *iofst, 8); /* Get bit-map indicator */
53  *iofst = *iofst + 8;
54 
55  if (*ibmap == 0)
56  { /* Unpack bitmap */
57  if (ngpts > 0)
58  lbmap = calloc(ngpts, sizeof(g2int));
59  if (!lbmap)
60  return G2_UNPACK_NO_MEM;
61 
62  *bmap = lbmap;
63  intbmap = calloc(ngpts, sizeof(g2int));
64  gbits(cgrib, intbmap, *iofst, 1, 0, ngpts);
65  *iofst = *iofst + ngpts;
66  for (j = 0; j < ngpts; j++)
67  lbmap[j] = (g2int)intbmap[j];
68  free(intbmap);
69  }
70 
71  return G2_NO_ERROR;
72 }
G2_UNPACK_NO_MEM
#define G2_UNPACK_NO_MEM
Error allocating memory in unpack function.
Definition: grib2.h:302
G2_NO_ERROR
#define G2_NO_ERROR
Function succeeded.
Definition: grib2.h:275
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.
gbit
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...
Definition: gbits.c:20
g2int
int64_t g2int
Long integer type.
Definition: grib2.h:28
g2_unpack6
g2int g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap, g2int **bmap)
This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.
Definition: g2_unpack6.c:33
gbits
void gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, g2int nskip, g2int n)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
Definition: gbits.c:57
G2_UNPACK_BAD_SEC
#define G2_UNPACK_BAD_SEC
Bad section number in unpacking function.
Definition: grib2.h:301