1 SUBROUTINE W3FI76
(PVAL
,KEXP
,KMANT
,KBITS
)
2 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
4 C SUBPROGRAM: W3FI76 CONVERT TO IBM370 FLOATING POINT
5 C PRGMMR: REJONES ORG: NMC421 DATE:92-11-16
7 C ABSTRACT: CONVERTS FLOATING POINT NUMBER FROM MACHINE
8 C REPRESENTATION TO GRIB REPRESENTATION (IBM370 32 BIT F.P.).
10 C PROGRAM HISTORY LOG:
11 C 85-09-15 JOHN HENNESSY ECMWF
12 C 92-09-23 JONES R. E. CHANGE NAME, ADD DOC BLOCK
13 C 93-10-27 JONES,R. E. CHANGE TO AGREE WITH HENNESSY CHANGES
14 C 95-10-31 IREDELL REMOVED SAVES AND PRINTS
15 C 98-03-10 B. VUONG REMOVE THE CDIR$ INTEGER=64 DIRECTIVE
17 C USAGE: CALL W3FI76 (FVAL, KEXP, KMANT, NBITS)
18 C INPUT ARGUMENT LIST:
19 C PVAL - FLOATING POINT NUMBER TO BE CONVERTED
20 C KBITS - NUMBER OF BITS IN COMPUTER WORD (32 OR 64)
22 C OUTPUT ARGUMENT LIST:
23 C KEXP - 8 BIT SIGNED EXPONENT
24 C KMANT - 24 BIT MANTISSA (FRACTION)
26 C REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
29 C LANGUAGE: IBM370 VS FORTRAN 77, CRAY CFT77 FORTRAN
30 C MACHINE: HDS 9000, CRAY Y-MP8/864< CRAY Y-MP EL2/256
34 C********************************************************************
38 C* FUNCTION : CONVERT FLOATING POINT NUMBER FROM MACHINE
39 C* REPRESENTATION TO GRIB REPRESENTATION.
41 C* INPUT : PVAL - FLOATING POINT NUMBER TO BE CONVERTED.
42 C* KBITS : KBITS - NUMBER OF BITS IN COMPUTER WORD
44 C* OUTPUT : KEXP - 8 BIT SIGNED EXPONENT
45 C* KMANT - 24 BIT MANTISSA
48 C* JOHN HENNESSY , ECMWF 18.06.91
50 C********************************************************************
66 C TEST FOR FLOATING POINT ZERO
74 C SET ZEPS TO 1.0E-12 FOR 64 BIT COMPUTERS (CRAY)
75 C SET ZEPS TO 1.0E-8 FOR 32 BIT COMPUTERS
94 IEXP
= INT
(ALOG
(ZREF
)*(1.0/ALOG
(16.0))+64.0+1.0+ZEPS
)
96 IF (IEXP
.LT
.0 ) IEXP
= 0
97 IF (IEXP
.GT
.127) IEXP
= 127
101 C CLOSEST NUMBER IN GRIB FORMAT TO ORIGINAL NUMBER
102 C (EQUAL TO, GREATER THAN OR LESS THAN ORIGINAL NUMBER).
104 KMANT
= NINT
(ZREF
/16.0**(IEXP
-70))
106 C CHECK THAT MANTISSA VALUE DOES NOT EXCEED 24 BITS
107 C 16777215 = 2**24 - 1
109 IF (KMANT
.GT
.16777215) THEN
112 C CLOSEST NUMBER IN GRIB FORMAT TO ORIGINAL NUMBER
113 C (EQUAL TO, GREATER THAN OR LESS THAN ORIGINAL NUMBER).
115 KMANT
= NINT
(ZREF
/16.0**(IEXP
-70))
117 C CHECK MANTISSA VALUE DOES NOT EXCEED 24 BITS AGAIN
119 IF (KMANT
.GT
.16777215) THEN
120 PRINT
*,'BAD MANTISSA VALUE FOR PVAL = ',PVAL
124 C ADD SIGN BIT TO EXPONENT.