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
35 ! Recent versions of the PGI compilers apparently still
do not fully support
36 ! the use of all intrinsics in
parameter statements
, though this is part of
38 ! real, parameter :: two23
=scale
(1.0,23)
39 ! real, parameter :: two126
=scale
(1.0,126)
53 rieee
(j
)=transfer
(ieee
,rieee
(j
))
54 ! write(6,fmt
='(f20.10,5x,b32)') a
,a
55 ! write(6,fmt
='(f20.10,5x,b32)') rieee
,rieee
60 ! Set Sign bit
(bit
31 - leftmost bit
)
70 ! Determine exponent n with base
2
72 if ( atemp
.ge
. 1.0 ) then
74 do while ( 2.0**(n
+1) .le
. atemp
)
79 do while ( 2.0**n
.gt
. atemp
)
83 ! n
=floor
(alog
(atemp
)/alog2
)
84 !write(6,*) ' logstuff ',alog
(atemp
)/alog2
85 !write(6,*) ' logstuffn ',n
87 if (n
.gt
.127) iexp
=255 ! overflow
89 ! set exponent bits
( bits
30-23 )
90 call mvbits
(iexp
,0,8,ieee
,23)
96 atemp
=(atemp
/(2.0**n
))-1.0
100 imant
=nint
(atemp*two23
)
104 ! set mantissa bits
( bits
22-0 )
105 call mvbits
(imant
,0,23,ieee
,0)
107 ! Transfer IEEE bit string
to real variable
109 rieee
(j
)=transfer
(ieee
,rieee
(j
))
110 ! write(6,fmt
='(f20.10,5x,b32)') a
,a
111 ! write(6,fmt
='(f20.10,5x,b32)') rieee
,rieee