LCOV - code coverage report
Current view: directory - frmts/grib/degrib18/g2clib-1.0.4 - simunpack.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 18 0 0.0 %
Date: 2010-01-09 Functions: 1 0 0.0 %

       1                 : #include <stdio.h>
       2                 : #include <stdlib.h>
       3                 : #include "grib2.h"
       4                 : 
       5                 : 
       6               0 : g2int simunpack(unsigned char *cpack,g2int *idrstmpl,g2int ndpts,g2float *fld)
       7                 : ////$$$  SUBPROGRAM DOCUMENTATION BLOCK
       8                 : //                .      .    .                                       .
       9                 : // SUBPROGRAM:    simunpack
      10                 : //   PRGMMR: Gilbert          ORG: W/NP11    DATE: 2002-10-29
      11                 : //
      12                 : // ABSTRACT: This subroutine unpacks a data field that was packed using a 
      13                 : //   simple packing algorithm as defined in the GRIB2 documention,
      14                 : //   using info from the GRIB2 Data Representation Template 5.0.
      15                 : //
      16                 : // PROGRAM HISTORY LOG:
      17                 : // 2002-10-29  Gilbert
      18                 : //
      19                 : // USAGE:    int simunpack(unsigned char *cpack,g2int *idrstmpl,g2int ndpts,
      20                 : //                         g2float *fld)
      21                 : //   INPUT ARGUMENT LIST:
      22                 : //     cpack    - pointer to the packed data field.
      23                 : //     idrstmpl - pointer to the array of values for Data Representation
      24                 : //                Template 5.0
      25                 : //     ndpts    - The number of data values to unpack
      26                 : //
      27                 : //   OUTPUT ARGUMENT LIST:
      28                 : //     fld      - Contains the unpacked data values.  fld must be allocated
      29                 : //                with at least ndpts*sizeof(g2float) bytes before
      30                 : //                calling this routine.
      31                 : //
      32                 : // REMARKS: None
      33                 : //
      34                 : // ATTRIBUTES:
      35                 : //   LANGUAGE: C
      36                 : //   MACHINE:  
      37                 : //
      38                 : //$$$//
      39                 : {
      40                 : 
      41                 :       g2int  *ifld;
      42                 :       g2int  j,nbits,itype;
      43                 :       g2float ref,bscale,dscale;
      44                 : 
      45                 :       
      46               0 :       rdieee(idrstmpl+0,&ref,1);
      47               0 :       bscale = int_power(2.0,idrstmpl[1]);
      48               0 :       dscale = int_power(10.0,-idrstmpl[2]);
      49               0 :       nbits = idrstmpl[3];
      50               0 :       itype = idrstmpl[4];
      51                 : 
      52               0 :       ifld=(g2int *)calloc(ndpts,sizeof(g2int));
      53               0 :       if ( ifld == 0 ) {
      54               0 :          fprintf(stderr,"Could not allocate space in simunpack.\n  Data field NOT upacked.\n");
      55               0 :          return(1);
      56                 :       }
      57                 :       
      58                 : //
      59                 : //  if nbits equals 0, we have a constant field where the reference value
      60                 : //  is the data value at each gridpoint
      61                 : //
      62               0 :       if (nbits != 0) {
      63               0 :          gbits(cpack,ifld,0,nbits,0,ndpts);
      64               0 :          for (j=0;j<ndpts;j++) {
      65               0 :            fld[j]=(((g2float)ifld[j]*bscale)+ref)*dscale;
      66                 :          }
      67                 :       }
      68                 :       else {
      69               0 :          for (j=0;j<ndpts;j++) {
      70               0 :            fld[j]=ref;
      71                 :          }
      72                 :       }
      73                 : 
      74               0 :       free(ifld);
      75               0 :       return(0);
      76                 : }

Generated by: LCOV version 1.7