SURFEX v8.1
General documentation of Surfex
prtbin_mf.F
Go to the documentation of this file.
1  SUBROUTINE prtbin_mf (KIN,KNBIT,KOUT,KERR)
2  USE parkind1, ONLY : jprb
3  USE yomhook , ONLY : lhook, dr_hook
4  USE lfi_precision
5 !
6 !**** PRTBIN - Binary to decimal conversion.
7 !
8 ! Purpose.
9 ! --------
10 !
11 ! Produces a decimal number with ones and zeroes
12 ! corresponding to the ones and zeroes of the input
13 ! binary number.
14 ! eg input number 1011 binary, output number 1011 decimal.
15 !
16 !** Interface.
17 ! ----------
18 !
19 ! CALL PRTBIN_MF (KIN,KNBIT,KOUT,KERR)
20 !
21 ! Integer K.
22 ! Real P.
23 ! Logical O.
24 ! Character H.
25 !
26 ! Input Parameters.
27 ! -----------------
28 !
29 ! KIN - Integer variable containing binary number.
30 !
31 ! KNBIT - Number of bits in binary number.
32 !
33 ! Output Parameters.
34 ! -----------------
35 !
36 ! KOUT - Integer variable containing decimal value
37 ! with ones and zeroes corresponding to those of
38 ! the input binary number.
39 !
40 ! KERR - 0, If no error.
41 ! 1, Number of bits in binary number exceeds
42 ! maximum allowed.
43 !
44 ! Method.
45 ! -------
46 !
47 ! Masking expression used is not ANSI standard.
48 !
49 ! Externals.
50 ! ----------
51 !
52 ! None.
53 !
54 ! Reference.
55 ! ----------
56 !
57 ! None.
58 !
59 ! Comments.
60 ! ---------
61 !
62 ! Routine contains sections 0, 1 and section 9.
63 !
64 ! Author.
65 ! -------
66 !
67 ! John Hennessy ECMWF October 1985
68 !
69 ! Modifications.
70 ! --------------
71 !
72 ! John Hennessy ECMWF March 1991
73 ! Made to conform to current programming standards.
74 !
75 ! ---------------------------------------------------------------
76 !
77 !
78  IMPLICIT NONE
79 !
80  INTEGER (KIND=JPLIKM) :: KIN
81  INTEGER (KIND=JPLIKM) :: KNBIT
82  INTEGER (KIND=JPLIKM) :: KOUT
83  INTEGER (KIND=JPLIKM) :: KERR
84 !
85  INTEGER (KIND=JPLIKM) :: J101, IK, IMASC, ITEMP
86 !
87 !
88 !
89 !
90 !
91 !
92 !
93 !
94 !* Section 0. Definition of variables. Check on parameters.
95 ! -----------------------------------------------------------------
96 !
97 ! Check length of binary number.
98 !
99  REAL(KIND=JPRB) :: ZHOOK_HANDLE
100  IF (lhook) CALL dr_hook('PRTBIN_MF',0,zhook_handle)
101  IF (knbit.LT.0.OR.knbit.GT.15) &
102  & THEN
103  kerr = 1
104  WRITE (*,9000) knbit
105  GO TO 900
106  ELSE
107  kerr = 0
108  ENDIF
109 !
110 ! -----------------------------------------------------------------
111 !
112 !
113 !
114 !
115 !
116 !
117 !
118 !
119 !
120 !
121 !* Section 1. Generate required number.
122 ! -----------------------------------------------------------------
123 !
124  100 CONTINUE
125 !
126  kout = 0
127 !
128  DO 101 j101=1,knbit
129  ik = j101 - 1
130  imasc = 2**ik
131  itemp = iand(kin,imasc)
132  IF (itemp.NE.0) kout = kout + 10**ik
133  101 CONTINUE
134 !
135 ! -----------------------------------------------------------------
136 !
137 !
138 !
139 !
140 !
141 !
142 !
143 !
144 !
145 !
146 !* Section 9. Format statements. Return to calling routine.
147 ! -----------------------------------------------------------------
148 !
149  900 CONTINUE
150 !
151  9000 FORMAT (1h ,'PRTBIN : Binary number too long - ',i3,' bits.')
152 !
153  IF (lhook) CALL dr_hook('PRTBIN_MF',1,zhook_handle)
154  ENDSUBROUTINE prtbin_mf
integer, parameter jprb
Definition: parkind1.F90:32
subroutine prtbin_mf(KIN, KNBIT, KOUT, KERR)
Definition: prtbin_mf.F:2
logical lhook
Definition: yomhook.F90:15