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