LCOV - code coverage report
Current view: top level - frmts/grib/degrib/g2clib - rdieee.c (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 17 20 85.0 %
Date: 2024-05-06 22:33:47 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "grib2.h"
       2             : 
       3         126 : void rdieee(g2int *rieee,g2float *a,g2int num)
       4             : //$$$  SUBPROGRAM DOCUMENTATION BLOCK
       5             : //                .      .    .                                       .
       6             : // SUBPROGRAM:    rdieee
       7             : //   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2002-10-25
       8             : //
       9             : // ABSTRACT: This subroutine reads a list of real values in
      10             : //   32-bit IEEE floating point format.
      11             : //
      12             : // PROGRAM HISTORY LOG:
      13             : // 2002-10-25  Gilbert
      14             : //
      15             : // USAGE:    void rdieee(g2int *rieee,g2float *a,g2int num)
      16             : //   INPUT ARGUMENT LIST:
      17             : //     rieee    - g2int array of floating point values in 32-bit IEEE format.
      18             : //     num      - Number of floating point values to convert.
      19             : //
      20             : //   OUTPUT ARGUMENT LIST:
      21             : //     a        - float array of real values.  a must be allocated with at
      22             : //                least 4*num bytes of memory before calling this function.
      23             : //
      24             : // REMARKS: None
      25             : //
      26             : // ATTRIBUTES:
      27             : //   LANGUAGE: C
      28             : //   MACHINE:  IBM SP
      29             : //
      30             : //$$$
      31             : {
      32             : 
      33             :       g2int  j;
      34             :       g2int  isign,iexp,imant;
      35             : 
      36             :       g2float  sign,temp;
      37             :       static const double two23 = 1.1920928955078125e-07; // pow(2,-23)
      38             :       static const double two126 = 1.1754943508222875e-38; // pow(2,-126)
      39             : 
      40             : 
      41         126 :       g2intu msk1=0x80000000;        // 10000000000000000000000000000000 binary
      42         126 :       g2int msk2=0x7F800000;         // 01111111100000000000000000000000 binary
      43         126 :       g2int msk3=0x007FFFFF;         // 00000000011111111111111111111111 binary
      44             : 
      45         252 :       for (j=0;j<num;j++) {
      46             : //
      47             : //  Extract sign bit, exponent, and mantissa
      48             : //
      49         126 :         isign=(rieee[j]&msk1)>>31;
      50         126 :         iexp=(rieee[j]&msk2)>>23;
      51         126 :         imant=(rieee[j]&msk3);
      52             :         //printf("SAGieee= %ld %ld %ld\n",isign,iexp,imant);
      53             : 
      54         126 :         sign=1.0;
      55         126 :         if (isign == 1) sign=-1.0;
      56             : 
      57         126 :         if ( (iexp > 0) && (iexp < 255) ) {
      58         111 :           temp=(g2float)int_power(2.0,(iexp-127));
      59         111 :           a[j]=(float)(sign*temp*(1.0+(two23*(g2float)imant)));
      60             :         }
      61          15 :         else if ( iexp == 0 ) {
      62          15 :           if ( imant != 0 )
      63           0 :             a[j]=(float)(sign*two126*two23*(g2float)imant);
      64             :           else
      65          15 :             a[j]=(float)(sign*0.0);
      66             : 
      67             :         }
      68           0 :         else if ( iexp == 255 )
      69           0 :            a[j]=(float)(sign*(1E+37));
      70             : 
      71             : 
      72             :       }
      73             : 
      74         126 : }

Generated by: LCOV version 1.14