LCOV - code coverage report
Current view: directory - frmts/grib/degrib18/g2clib-1.0.4 - g2_unpack1.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 23 17 73.9 %
Date: 2012-04-28 Functions: 1 1 100.0 %

       1                 : #include <stdio.h>
       2                 : #include <stdlib.h>
       3                 : #include "grib2.h"
       4                 : 
       5               6 : g2int g2_unpack1(unsigned char *cgrib,g2int *iofst,g2int **ids,g2int *idslen)
       6                 : /*//$$$  SUBPROGRAM DOCUMENTATION BLOCK
       7                 : //                .      .    .                                       .
       8                 : // SUBPROGRAM:    g2_unpack1 
       9                 : //   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2002-10-29
      10                 : //
      11                 : // ABSTRACT: This subroutine unpacks Section 1 (Identification Section)
      12                 : //           as defined in GRIB Edition 2.
      13                 : //
      14                 : // PROGRAM HISTORY LOG:
      15                 : // 2002-10-29  Gilbert
      16                 : //
      17                 : // USAGE:    int g2_unpack1(unsigned char *cgrib,g2int *iofst,g2int **ids,
      18                 : //                          g2int *idslen)
      19                 : //   INPUT ARGUMENTS:
      20                 : //     cgrib    - char array containing Section 1 of the GRIB2 message
      21                 : //     iofst    - Bit offset for the beginning of Section 1 in cgrib.
      22                 : //
      23                 : //   OUTPUT ARGUMENTS:      
      24                 : //     iofst    - Bit offset at the end of Section 1, returned.
      25                 : //     ids      - address of pointer to integer array containing information 
      26                 : //                read from Section 1, the Identification section.
      27                 : //            ids[0]  = Identification of originating Centre
      28                 : //                                 ( see Common Code Table C-1 )
      29                 : //            ids[1]  = Identification of originating Sub-centre
      30                 : //            ids[2]  = GRIB Master Tables Version Number
      31                 : //                                 ( see Code Table 1.0 )
      32                 : //            ids[3]  = GRIB Local Tables Version Number
      33                 : //                                 ( see Code Table 1.1 )
      34                 : //            ids[4]  = Significance of Reference Time (Code Table 1.2)
      35                 : //            ids[5]  = Year ( 4 digits )
      36                 : //            ids[6]  = Month
      37                 : //            ids[7]  = Day
      38                 : //            ids[8]  = Hour
      39                 : //            ids[9]  = Minute
      40                 : //            ids[10]  = Second
      41                 : //            ids[11]  = Production status of processed data
      42                 : //                                 ( see Code Table 1.3 )
      43                 : //            ids[12]  = Type of processed data ( see Code Table 1.4 )
      44                 : //     idslen   - Number of elements in ids[].
      45                 : //
      46                 : //   RETURN VALUES:
      47                 : //     ierr     - Error return code.
      48                 : //                0 = no error
      49                 : //                2 = Array passed is not section 1
      50                 : //                6 = memory allocation error
      51                 : //
      52                 : // REMARKS: 
      53                 : //
      54                 : // ATTRIBUTES:
      55                 : //   LANGUAGE: C
      56                 : //   MACHINE:
      57                 : //
      58                 : //$$$
      59                 : */
      60                 : {
      61                 : 
      62                 :       g2int i,lensec,nbits,ierr,isecnum;
      63               6 :       g2int mapid[13]={2,2,1,1,1,2,1,1,1,1,1,1,1};
      64                 : 
      65               6 :       ierr=0;
      66               6 :       *idslen=13;
      67               6 :       *ids=0;
      68                 : 
      69               6 :       gbit(cgrib,&lensec,*iofst,32);        // Get Length of Section
      70               6 :       *iofst=*iofst+32;
      71               6 :       gbit(cgrib,&isecnum,*iofst,8);         // Get Section Number
      72               6 :       *iofst=*iofst+8;
      73                 : 
      74               6 :       if ( isecnum != 1 ) {
      75               0 :          ierr=2;
      76               0 :          *idslen=13;
      77               0 :          fprintf(stderr,"g2_unpack1: Not Section 1 data.\n");
      78               0 :          return(ierr);
      79                 :       }
      80                 : 
      81                 :       //
      82                 :       //   Unpack each value into array ids from the
      83                 :       //   the appropriate number of octets, which are specified in
      84                 :       //   corresponding entries in array mapid.
      85                 :       //
      86               6 :       *ids=(g2int *)calloc(*idslen,sizeof(g2int));
      87               6 :       if (*ids == 0) {
      88               0 :          ierr=6;
      89               0 :          return(ierr);
      90                 :       }
      91                 :       
      92              84 :       for (i=0;i<*idslen;i++) {
      93              78 :         nbits=mapid[i]*8;
      94              78 :         gbit(cgrib,*ids+i,*iofst,nbits);
      95              78 :         *iofst=*iofst+nbits;
      96                 :       }
      97                 :       
      98               6 :       return(ierr);    // End of Section 1 processing
      99                 : }

Generated by: LCOV version 1.7