NCEPLIBS-g2c  1.6.4
g2_unpack6.c
Go to the documentation of this file.
1 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "grib2.h"
8 
32 g2int
33 g2_unpack6(unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap,
34  g2int **bmap)
35 {
36  g2int j, ierr = 0, 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  ierr = 2;
49  fprintf(stderr, "g2_unpack6: Not Section 6 data.\n");
50  return(ierr);
51  }
52 
53  gbit(cgrib, ibmap, *iofst, 8); /* Get bit-map indicator */
54  *iofst = *iofst + 8;
55 
56  if (*ibmap == 0)
57  { /* Unpack bitmap */
58  if (ngpts > 0)
59  lbmap = calloc(ngpts, sizeof(g2int));
60  if (lbmap == 0)
61  {
62  ierr = 6;
63  return(ierr);
64  }
65  else
66  {
67  *bmap = lbmap;
68  }
69  intbmap = calloc(ngpts, sizeof(g2int));
70  gbits(cgrib, intbmap, *iofst, 1, 0, ngpts);
71  *iofst = *iofst + ngpts;
72  for (j = 0; j < ngpts; j++)
73  {
74  lbmap[j] = (g2int)intbmap[j];
75  }
76  free(intbmap);
77  /*
78  else if (*ibmap.eq.254) ! Use previous bitmap
79  return(ierr);
80  else if (*ibmap.eq.255) ! No bitmap in message
81  bmap(1:ngpts)=.true.
82  else {
83  print *,'gf_unpack6: Predefined bitmap ',*ibmap,' not recognized.'
84  ierr=4;
85  */
86  }
87 
88  return(ierr); /* End of Section 6 processing */
89 
90 }
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
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...
Definition: gbits.c:20
void gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbyte, g2int nskip, g2int n)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
Definition: gbits.c:57
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.
Definition: grib2.h:20