1 #include "grib2.h"
2 
rdieee(g2int * rieee,g2float * a,g2int num)3 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       g2intu msk1=0x80000000;        // 10000000000000000000000000000000 binary
42       g2int msk2=0x7F800000;         // 01111111100000000000000000000000 binary
43       g2int msk3=0x007FFFFF;         // 00000000011111111111111111111111 binary
44 
45       for (j=0;j<num;j++) {
46 //
47 //  Extract sign bit, exponent, and mantissa
48 //
49         isign=(rieee[j]&msk1)>>31;
50         iexp=(rieee[j]&msk2)>>23;
51         imant=(rieee[j]&msk3);
52         //printf("SAGieee= %ld %ld %ld\n",isign,iexp,imant);
53 
54         sign=1.0;
55         if (isign == 1) sign=-1.0;
56 
57         if ( (iexp > 0) && (iexp < 255) ) {
58           temp=(g2float)int_power(2.0,(iexp-127));
59           a[j]=(float)(sign*temp*(1.0+(two23*(g2float)imant)));
60         }
61         else if ( iexp == 0 ) {
62           if ( imant != 0 )
63             a[j]=(float)(sign*two126*two23*(g2float)imant);
64           else
65             a[j]=(float)(sign*0.0);
66 
67         }
68         else if ( iexp == 255 )
69            a[j]=(float)(sign*(1E+37));
70 
71 
72       }
73 
74 }
75