Jose,
At 08:15 16-05-2000 -0600, you wrote:
>Hello,
>
> I am interested in a fortran program that does the following things:
>
> 1.- reads from a file of random bites, for example one of
> Marsaglia random generated files
> (http://www.csis.hku.hk/internet/randomCD.html)
>
> 2.- transforms this data into real*8 random numbers within
> the [0,1] interval.
>
> Conceptually this does not seem hard and I am sure that somebody has
>
> faced this problem before.
>
> Using DVF6.1 I have written a simple program that reads one of
> Marsaglia files. I am not sure that I have done this correctly because I
> have never faced this problem before.
>
>
>PROGRAM random
>implicit none
>real(8) :: rreal
>integer :: n, ierror, ierror1
>
>open(unit=1, file='c:\temp\bits.01', status='unknown', FORM='BINARY' &
> & , action='read', iostat=ierror)
>
>open(unit=2,file='c:\temp\out.dat',status='unknown' &
> & , action='write', iostat=ierror1)
>
> do n = 1, 10
> read(1) rreal
> write(2, *)rreal
> enddo
>END PROGRAM
>
>The result is
>
> 2.361349061791736E-199
> 8.425998214083004E+149
> -1.301095633149849E+261
> 5.166552341828369E+202
> -1.757866860529372E-276
> 7683276257476.26
> 6.581435966483412E-238
> 2.139230620717598E-264
> 2.629136211473332E+030
> 4.493242642612468E+071
>
>When I consider the option
>
> real(4) :: rreal
>
>the result is
>
> 8.1462669E+36
> 2.8769560E-25
> 4.3009742E-22
> 1.0410461E+19
> -556929.2
> -8.3743773E+32
> 4.0191015E-16
> 4.0224823E+25
> 1.5110841E-21
> -6.5888261E-35
>
> Any suggestions on how to solve this problem would be appreciated.
>Thanks in advance.
I modified your program, because BINARY is non-standard.
Now using non advancing read of Characters.
Equivalenced with Double precision; this is non-standard as well, use
Transfer.
Maybe UNformatted is possible.
After a few versions I got a result scaled on [0, 1]
! [JvO] 2000-05-17 Randomm.f90
PROGRAM random
implicit none
real(kind(1d0)) :: rreal
character(8) :: rchar
integer :: n, ierror7, ierror8
equivalence(rreal, rchar)
open(unit=7, file='D:\Download\Random\bits.01', status='OLD' &
& , FORM='Formatted', access = 'Sequential' &
& , iostat=ierror7)
! & , FORM='UNformatted', access = 'Direct' &
! & , recl=8, iostat=ierror7)
if(ierror7 /= 0) then
print *, 'File 7 not opened', ierror7
stop
endif
open(unit=8, file='ranout.dat', status='unknown' &
& , position='Append', iostat=ierror8)
if(ierror8 /= 0) then
print *, 'File 8 not opened', ierror8
stop
endif
do n = 1, 10
! read(7) rreal
read(7, '(A)', advance="NO") rchar
rreal = set_exponent(abs(rreal), 1) - 1d0
write(8,'(F30.16)') rreal
end do
END PROGRAM
[JvO]
! Result of Randomm.f90
2.361349061792E-0199
8.425998214083E+0149
-1.301095633150E+0261
5.166552341828E+0202
-1.757866860529E-0276
6.013470016999E-0154
2.143260755265E+0165
-1.511656163293E+0116
6.038407585566E-0154
2.629136211473E+30
[Org:]
From: "Jose J. Canals-Cerda" <[log in to unmask]>
2.361349061791736E-199
8.425998214083004E+149
-1.301095633149849E+261
5.166552341828369E+202
-1.757866860529372E-276
7683276257476.26
6.581435966483412E-238
2.139230620717598E-264
2.629136211473332E+030
4.493242642612468E+071
[Set_exponent(x, 0) ]
0.564842456516
0.514817766860
-0.661108868255
0.659149240525
-0.973782593183
0.503921568627
0.581537060082
-0.959123855115
0.506011306937
0.518505692933
[Set_exponent(x, -1) ]
0.282421228258
0.257408883430
-0.330554434127
0.329574620263
-0.486891296592
0.251960784314
0.290768530041
-0.479561927557
0.253005653469
0.259252846467
[Set_exponent(x, 1) - 1d0 ]
0.129684913032
0.02963553371940
-2.32221773651
0.318298481051
-2.94756518637
0.007843137254902
0.163074120164
-2.91824771023
0.01202261387469
0.03701138586610
[Set_exponent(abs(x), 1) - 1d0 ]
0.1296849130320223
0.0296355337193959
0.3222177365091781
0.3182984810509577
0.9475651863663890
0.0078431372549019
0.1630741201644847
0.9182477102292619
0.0120226138746851
0.0370113858660970
---
Meilleures Salutations,
Best Greetings,
/---
Jan van Oosterwijk
Computing Centre
Delft University of Technology
Postbus 354
2600 AJ Delft
Netherlands / Pays-Bas
Phone: +31 15 278 50 17
Fax: +31 15 278 37 87
|