1 subroutine mkieee
(a
,rieee
,num
)
2 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
5 ! PRGMMR
: Gilbert ORG
: W
/NP11
DATE: 2000-05-09
7 ! ABSTRACT
: This
subroutine stores a list of
real values in
8 ! 32-bit IEEE floating point
format.
10 ! PROGRAM HISTORY LOG
:
13 ! USAGE
: CALL mkieee
(a
,rieee
,num
)
14 ! INPUT ARGUMENT LIST
:
15 ! a
- Input array of floating point values
.
16 ! num
- Number of floating point values
to convert
.
18 ! OUTPUT ARGUMENT LIST
:
19 ! rieee
- Output array of floating point values in
32-bit IEEE
format.
24 ! LANGUAGE
: Fortran
90
29 real(4),intent
(in
) :: a
(num
)
30 real(4),intent
(out
) :: rieee
(num
)
31 integer,intent
(in
) :: num
37 integer,save
:: once
=0
39 if ( once
.EQ
. 0 ) then
52 rieee
(j
)=transfer
(ieee
,rieee
(j
))
53 ! write(6,fmt
='(f20.10,5x,b32)') a
,a
54 ! write(6,fmt
='(f20.10,5x,b32)') rieee
,rieee
59 ! Set Sign bit
(bit
31 - leftmost bit
)
69 ! Determine exponent n with base
2
71 if ( atemp
.ge
. 1.0 ) then
73 do while ( 2.0**(n
+1) .le
. atemp
)
78 do while ( 2.0**n
.gt
. atemp
)
82 ! n
=floor
(alog
(atemp
)/alog2
)
83 !write(6,*) ' logstuff ',alog
(atemp
)/alog2
84 !write(6,*) ' logstuffn ',n
86 if (n
.gt
.127) iexp
=255 ! overflow
88 ! set exponent bits
( bits
30-23 )
89 call mvbits
(iexp
,0,8,ieee
,23)
95 atemp
=(atemp
/(2.0**n
))-1.0
99 imant
=nint
(atemp*two23
)
103 ! set mantissa bits
( bits
22-0 )
104 call mvbits
(imant
,0,23,ieee
,0)
106 ! Transfer IEEE bit string
to real variable
108 rieee
(j
)=transfer
(ieee
,rieee
(j
))
109 ! write(6,fmt
='(f20.10,5x,b32)') a
,a
110 ! write(6,fmt
='(f20.10,5x,b32)') rieee
,rieee