NCEPLIBS-w3emc  2.11.0
w3fi76.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Convert to ibm370 floating point
3 C> @author John Hennessy @date 1985-09-15
4 
5 C> Converts floating point number from machine
6 C> representation to grib representation (ibm370 32 bit f.p.).
7 C>
8 C> Program history log:
9 C> - John Hennessy 1985-09-15
10 C> - Ralph Jones 1992-09-23 Change name, add doc block
11 C> - Ralph Jones 1993-10-27 Change to agree with hennessy changes
12 C> - Mark Iredell 1995-10-31 Removed saves and prints
13 C> - Boi Vuong 1998-03-10 Remove the cdir$ integer=64 directive
14 C>
15 C> @param[in] PVAL Floating point number to be converted
16 C> @param[in] KBITS Number of bits in computer word (32 or 64)
17 C> @param[out] KEXP 8 Bit signed exponent
18 C> @param[out] KMANT 24 Bit mantissa (fraction)
19 C>
20 C> @note Subprogram can be called from a multiprocessing environment.
21 C>
22 C> @author John Hennessy @date 1985-09-15
23  SUBROUTINE w3fi76(PVAL,KEXP,KMANT,KBITS)
24 C
25 C********************************************************************
26 C*
27 C* NAME : CONFP3
28 C*
29 C* FUNCTION : CONVERT FLOATING POINT NUMBER FROM MACHINE
30 C* REPRESENTATION TO GRIB REPRESENTATION.
31 C*
32 C* INPUT : PVAL - FLOATING POINT NUMBER TO BE CONVERTED.
33 C* KBITS : KBITS - NUMBER OF BITS IN COMPUTER WORD
34 C*
35 C* OUTPUT : KEXP - 8 BIT SIGNED EXPONENT
36 C* KMANT - 24 BIT MANTISSA
37 C* PVAL - UNCHANGED.
38 C*
39 C* JOHN HENNESSY , ECMWF 18.06.91
40 C*
41 C********************************************************************
42 C
43 C
44 C IMPLICIT NONE
45 C
46  INTEGER IEXP
47  INTEGER ISIGN
48 C
49  INTEGER KBITS
50  INTEGER KEXP
51  INTEGER KMANT
52 C
53  REAL PVAL
54  REAL ZEPS
55  REAL ZREF
56 C
57 C TEST FOR FLOATING POINT ZERO
58 C
59  IF (pval.EQ.0.0) THEN
60  kexp = 0
61  kmant = 0
62  GO TO 900
63  ENDIF
64 C
65 C SET ZEPS TO 1.0E-12 FOR 64 BIT COMPUTERS (CRAY)
66 C SET ZEPS TO 1.0E-8 FOR 32 BIT COMPUTERS
67 C
68  IF (kbits.EQ.32) THEN
69  zeps = 1.0e-8
70  ELSE
71  zeps = 1.0e-12
72  ENDIF
73  zref = pval
74 C
75 C SIGN OF VALUE
76 C
77  isign = 0
78  IF (zref.LT.0.0) THEN
79  isign = 128
80  zref = - zref
81  ENDIF
82 C
83 C EXPONENT
84 C
85  iexp = int(alog(zref)*(1.0/alog(16.0))+64.0+1.0+zeps)
86 C
87  IF (iexp.LT.0 ) iexp = 0
88  IF (iexp.GT.127) iexp = 127
89 C
90 C MANTISSA
91 C
92 C CLOSEST NUMBER IN GRIB FORMAT TO ORIGINAL NUMBER
93 C (EQUAL TO, GREATER THAN OR LESS THAN ORIGINAL NUMBER).
94 C
95  kmant = nint(zref/16.0**(iexp-70))
96 C
97 C CHECK THAT MANTISSA VALUE DOES NOT EXCEED 24 BITS
98 C 16777215 = 2**24 - 1
99 C
100  IF (kmant.GT.16777215) THEN
101  iexp = iexp + 1
102 C
103 C CLOSEST NUMBER IN GRIB FORMAT TO ORIGINAL NUMBER
104 C (EQUAL TO, GREATER THAN OR LESS THAN ORIGINAL NUMBER).
105 C
106  kmant = nint(zref/16.0**(iexp-70))
107 C
108 C CHECK MANTISSA VALUE DOES NOT EXCEED 24 BITS AGAIN
109 C
110  IF (kmant.GT.16777215) THEN
111  print *,'BAD MANTISSA VALUE FOR PVAL = ',pval
112  ENDIF
113  ENDIF
114 C
115 C ADD SIGN BIT TO EXPONENT.
116 C
117  kexp = iexp + isign
118 C
119  900 CONTINUE
120 C
121  RETURN
122  END
subroutine w3fi76(PVAL, KEXP, KMANT, KBITS)
Converts floating point number from machine representation to grib representation (ibm370 32 bit f....
Definition: w3fi76.f:24