LCOV - code coverage report
Current view: top level - frmts/grib/degrib/g2clib - g2_unpack6.c (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 21 26 80.8 %
Date: 2024-05-06 13:02:59 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include <stdio.h>
       2             : #include <stdlib.h>
       3             : #include "grib2.h"
       4             : 
       5         158 : g2int g2_unpack6(unsigned char *cgrib,g2int cgrib_length,g2int *iofst,g2int ngpts,g2int *ibmap,
       6             :                g2int **bmap)
       7             : //$$$  SUBPROGRAM DOCUMENTATION BLOCK
       8             : //                .      .    .                                       .
       9             : // SUBPROGRAM:    g2_unpack6
      10             : //   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2002-10-31
      11             : //
      12             : // ABSTRACT: This subroutine unpacks Section 6 (Bit-Map Section)
      13             : //           as defined in GRIB Edition 2.
      14             : //
      15             : // PROGRAM HISTORY LOG:
      16             : // 2002-10-31  Gilbert
      17             : //
      18             : // USAGE:    int g2_unpack6(unsigned char *cgrib,g2int *iofst,g2int ngpts,
      19             : //                          g2int *ibmap,g2int **bmap)
      20             : //   INPUT ARGUMENTS:
      21             : //     cgrib    - char array containing Section 6 of the GRIB2 message
      22             : //     iofst    - Bit offset of the beginning of Section 6 in cgrib.
      23             : //     ngpts    - Number of grid points specified in the bit-map
      24             : //
      25             : //   OUTPUT ARGUMENTS:
      26             : //     iofst    - Bit offset at the end of Section 6, returned.
      27             : //     ibmap    - Bitmap indicator ( see Code Table 6.0 )
      28             : //                0 = bitmap applies and is included in Section 6.
      29             : //                1-253 = Predefined bitmap applies
      30             : //                254 = Previously defined bitmap applies to this field
      31             : //                255 = Bit map does not apply to this product.
      32             : //     bmap     - Pointer to an integer array containing decoded bitmap.
      33             : //                ( if ibmap=0 )
      34             : //
      35             : //   RETURN VALUES:
      36             : //     ierr     - Error return code.
      37             : //                0 = no error
      38             : //                2 = Not Section 6
      39             : //                4 = Unrecognized pre-defined bit-map.
      40             : //                6 = memory allocation error
      41             : //
      42             : // REMARKS: None
      43             : //
      44             : // ATTRIBUTES:
      45             : //   LANGUAGE: C
      46             : //   MACHINE:
      47             : //
      48             : //$$$//
      49             : {
      50             :       g2int j,ierr,isecnum;
      51         158 :       g2int *lbmap=0;
      52             :       g2int *intbmap;
      53             : 
      54         158 :       ierr=0;
      55         158 :       *bmap=0;    //NULL
      56             : 
      57         158 :       *iofst=*iofst+32;    // skip Length of Section
      58         158 :       gbit(cgrib,&isecnum,*iofst,8);         // Get Section Number
      59         158 :       *iofst=*iofst+8;
      60             : 
      61         158 :       if ( isecnum != 6 ) {
      62           0 :          ierr=2;
      63           0 :          fprintf(stderr,"g2_unpack6: Not Section 6 data.\n");
      64           0 :          return(ierr);
      65             :       }
      66             : 
      67         158 :       gbit(cgrib,ibmap,*iofst,8);    // Get bit-map indicator
      68         158 :       *iofst=*iofst+8;
      69             : 
      70         158 :       if (*ibmap == 0) {               // Unpack bitmap
      71           2 :          if (ngpts > 0) lbmap=(g2int *)calloc(ngpts,sizeof(g2int));
      72           2 :          if (lbmap == 0) {
      73           0 :             ierr=6;
      74           0 :             return(ierr);
      75             :          }
      76             :          else {
      77           2 :             *bmap=lbmap;
      78             :          }
      79           2 :          intbmap=(g2int *)calloc(ngpts,sizeof(g2int));
      80           2 :          gbits(cgrib,cgrib_length,intbmap,*iofst,1,0,ngpts);
      81           2 :          *iofst=*iofst+ngpts;
      82         802 :          for (j=0;j<ngpts;j++) {
      83         800 :            lbmap[j]=(g2int)intbmap[j];
      84             :          }
      85           2 :          free(intbmap);
      86             : //      else if (*ibmap.eq.254)               ! Use previous bitmap
      87             : //        return(ierr);
      88             : //      else if (*ibmap.eq.255)               ! No bitmap in message
      89             : //        bmap(1:ngpts)=.true.
      90             : //      else {
      91             : //        print *,'gf_unpack6: Predefined bitmap ',*ibmap,' not recognized.'
      92             : //        ierr=4;
      93             :       }
      94             : 
      95         158 :       return(ierr);    // End of Section 6 processing
      96             : 
      97             : }

Generated by: LCOV version 1.14