Created a tag for the 2012 HWRF baseline tests.
[WPS-merge.git] / hwrf-baseline-20120103-1354 / ungrib / src / ngl / w3 / w3fi76.f
blob2a1553f51c4384d06eedf2426386956eb122b0f5
1 SUBROUTINE W3FI76(PVAL,KEXP,KMANT,KBITS)
2 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
3 C . . . .
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.
28 C ATTRIBUTES:
29 C LANGUAGE: IBM370 VS FORTRAN 77, CRAY CFT77 FORTRAN
30 C MACHINE: HDS 9000, CRAY Y-MP8/864< CRAY Y-MP EL2/256
32 C$$$
34 C********************************************************************
36 C* NAME : CONFP3
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
46 C* PVAL - UNCHANGED.
48 C* JOHN HENNESSY , ECMWF 18.06.91
50 C********************************************************************
53 C IMPLICIT NONE
55 INTEGER IEXP
56 INTEGER ISIGN
58 INTEGER KBITS
59 INTEGER KEXP
60 INTEGER KMANT
62 REAL PVAL
63 REAL ZEPS
64 REAL ZREF
66 C TEST FOR FLOATING POINT ZERO
68 IF (PVAL.EQ.0.0) THEN
69 KEXP = 0
70 KMANT = 0
71 GO TO 900
72 ENDIF
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
77 IF (KBITS.EQ.32) THEN
78 ZEPS = 1.0E-8
79 ELSE
80 ZEPS = 1.0E-12
81 ENDIF
82 ZREF = PVAL
84 C SIGN OF VALUE
86 ISIGN = 0
87 IF (ZREF.LT.0.0) THEN
88 ISIGN = 128
89 ZREF = - ZREF
90 ENDIF
92 C EXPONENT
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
99 C MANTISSA
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
110 IEXP = IEXP + 1
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
121 ENDIF
122 ENDIF
124 C ADD SIGN BIT TO EXPONENT.
126 KEXP = IEXP + ISIGN
128 900 CONTINUE
130 RETURN