-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGENRAND.F
62 lines (52 loc) · 1.53 KB
/
GENRAND.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
c Utility to generate random PBMs
c
c Owain Kenway, 2021
program genrand
implicit none
integer n, l
integer m
c Maximum size of simulation in bytes (cells).
parameter (m = 1000000)
character opt*1024, ar*1024, arr(m)
integer w, h, seed
real p
ar = ' '
c Get args via our platform independent wrapper.
call countargs(n)
if (n .ge. 5) then
call getargat(5, ar, l)
call getargat(1, opt, l)
read(opt,*) w
call getargat(2, opt, l)
read(opt,*) h
call getargat(3, opt, l)
read(opt,*) p
call getargat(4, opt, l)
read(opt,*) seed
else
stop 'Invoke with: genrand.exe <w> <h> <p> <seed> <filename>'
endif
c Initialise our simulation, load file, draw it.
call cuarr(arr, m)
call randarr(arr, m, w, h, p, seed)
write(*,*) 'Writing...'
call writepbm(arr, m, w, h, ar)
end
c Fill an array with random 1/0s with a probability of being 1 of p.
subroutine randarr(arr, m, w, h, p, seed)
implicit none
integer m
character arr(m)
integer i, w, h, s, seed
real p, r, getrand
s = w * h
call initrand(seed)
do i = 1, s
r = getrand(seed)
if (r .gt. p) then
arr(i) = '0'
else
arr(i) = '1'
endif
end do
end