SURFEX v8.1
General documentation of Surfex
confp_mf.F
Go to the documentation of this file.
1  SUBROUTINE confp_mf (PFVAL,KEXP,KMANT)
2  USE parkind1, ONLY : jprb
3  USE yomhook , ONLY : lhook, dr_hook
4  USE lfi_precision
5 !
6 !
7 !
8 !
9 !
10 !********************************************************************
11 !*
12 !* NAME : CONFP
13 !*
14 !* FUNCTION : CONVERT FLOATING POINT NUMBER FROM MACHINE
15 !* REPRESENTATION TO GRIB REPRESENTATION.
16 !*
17 !* INPUT : PFVAL - FLOATING POINT NUMBER TO BE CONVERTED.
18 !*
19 !* OUTPUT : KEXP - 8 BIT SIGNED EXPONENT
20 !* KMANT - 24 BIT MANTISSA
21 !* PFVAL - UNCHANGED.
22 !*
23 !* JOHN HENNESSY , ECMWF , 15TH APRIL 1985
24 !*
25 !* Modified by Jean CLOCHARD, February 1990, to comply with "DOCTOR",
26 !* and to get a better precision on the truncation made:
27 !* according to FM92 GRIB specification and recommandation,
28 !* replacement of "1.0/ALOG(2.0)" by "1.+ZEPS", where ZEPS
29 !* is a small positive value avoiding rounding errors to lead to
30 !* a mantissa greater than (or equal to) 2**24.
31 !*
32 !* (recommandation: ZEPS=1.E-12 for machines with word length of 60
33 !* bits or more, ZEPS=1.E-8 for 32 bits word length)
34 !*
35 !* Tested with 10**5 pseudo-random values through the RANF
36 !* function on Cyber 960 under NOS/VE 1.4.2, the modification gives
37 !* an enhancement of more than 10, both on standard deviation and
38 !* maximum error. Similar results are obtained when changing test
39 !* interval from (0,1) to (-256,256).
40 !*
41 !* Overflowing values are truncated, with a message on the listing.
42 !*
43 !********************************************************************
44 !
45  IMPLICIT NONE
46 !
47  INTEGER (KIND=JPLIKM) :: KEXP
48  INTEGER (KIND=JPLIKM) :: KMANT
49 !
50  REAL (KIND=JPDBLD) :: PFVAL
51 !
52  INTEGER (KIND=JPLIKM) :: IEXP
53 !
54  REAL (KIND=JPDBLD) :: ZEPS, ZREF, ZC16
55 !
56 !RJ INTRINSIC ABS, LOG, MAX, MIN
57 !
58  SAVE zeps, zc16
59  DATA zeps / 1.e-12_jpdbld /
60  DATA zc16 / 16.0_jpdbld /
61 !
62 !
63 !
64 ! Elimination of sign.
65 !
66 !
67  REAL(KIND=JPRB) :: ZHOOK_HANDLE
68  IF (lhook) CALL dr_hook('CONFP_MF',0,zhook_handle)
69  zref = abs(pfval)
70 !
71 !
72 !
73 ! EXPONENT
74 !
75  IF (zref.EQ.0.0_jpdbld) THEN
76  kexp = 0
77  ELSE
78  iexp = int( ( log(zref)/log(zc16) + 65.0_jpdbld ) +zeps )
79  kexp= max(0, min(127,iexp))
80  ENDIF
81 !
82 !
83 !
84 !
85 !
86 !
87 !
88 ! MANTISSA
89 !
90  201 CONTINUE
91 !
92  kmant = nint( zref/(zc16**(kexp-70)) )
93 !
94  IF (kmant.GE.2**24) THEN
95 !
96  IF (kexp.LT.127) THEN
97 !
98 ! Some rounding error ocurred in the computation of KEXP, and could
99 ! not be compensated by ZEPS. Incrementation of KEXP, and new value
100 ! of KMANT computed.
101 !
102  kexp=kexp+1
103  GOTO 201
104  ELSE
105  print *, &
106  &'*/*/* OVERFLOW OF GRIB FLOATING-POINT REPRESENTATION WITH ',pfval
107  kmant=2**24-1
108  ENDIF
109 !
110  ENDIF
111 !
112 ! ADD SIGN BIT TO EXPONENT.
113 !
114  IF (pfval.LT.0.0_jpdbld) kexp = kexp + 128
115 !
116 !
117 !
118 !
119  IF (lhook) CALL dr_hook('CONFP_MF',1,zhook_handle)
120  ENDSUBROUTINE confp_mf
integer, parameter jprb
Definition: parkind1.F90:32
logical lhook
Definition: yomhook.F90:15
subroutine confp_mf(PFVAL, KEXP, KMANT)
Definition: confp_mf.F:2