NCEPLIBS-g2c  1.6.4
rdieee.c
Go to the documentation of this file.
1 
6 #include "grib2.h"
7 
20 void rdieee(g2int *rieee,g2float *a,g2int num)
21 {
22 
23  g2int j;
24  g2int isign,iexp,imant;
25 
26  g2float sign,temp;
27  static g2float two23,two126;
28  static g2int test=0;
29  g2intu msk1=0x80000000; // 10000000000000000000000000000000 binary
30  g2int msk2=0x7F800000; // 01111111100000000000000000000000 binary
31  g2int msk3=0x007FFFFF; // 00000000011111111111111111111111 binary
32 
33  if ( test == 0 ) {
34  two23=(g2float)int_power(2.0,-23);
35  two126=(g2float)int_power(2.0,-126);
36  test=1;
37  }
38 
39  for (j=0;j<num;j++) {
40 //
41 // Extract sign bit, exponent, and mantissa
42 //
43  isign=(rieee[j]&msk1)>>31;
44  iexp=(rieee[j]&msk2)>>23;
45  imant=(rieee[j]&msk3);
46  //printf("SAGieee= %ld %ld %ld\n",isign,iexp,imant);
47 
48  sign=1.0;
49  if (isign == 1) sign=-1.0;
50 
51  if ( (iexp > 0) && (iexp < 255) ) {
52  temp=(g2float)int_power(2.0,(iexp-127));
53  a[j]=sign*temp*(1.0+(two23*(g2float)imant));
54  }
55  else if ( iexp == 0 ) {
56  if ( imant != 0 )
57  a[j]=sign*two126*two23*(g2float)imant;
58  else
59  a[j]=sign*0.0;
60 
61  }
62  else if ( iexp == 255 )
63  a[j]=sign*(1E+37);
64 
65 
66  }
67 
68 }
Header file for NCEPLIBS-g2c library.
float g2float
Float type.
Definition: grib2.h:22
uint64_t g2intu
Unsigned long integer type.
Definition: grib2.h:21
int64_t g2int
Long integer type.
Definition: grib2.h:20
double int_power(double x, g2int y)
Function similar to C pow() power function.
Definition: int_power.c:17
void rdieee(g2int *rieee, g2float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.
Definition: rdieee.c:20