-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPERIOD2D.F
116 lines (98 loc) · 2.87 KB
/
PERIOD2D.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
c This module contains routines for manipulating 1D arrays like 2D
c periodic boundary contructs.
c
c Arrays are of character This is because the byte is the smallest data
c type in F77.
c
c F77 doesn't have allocatable arrays, so create arrays of a max size.
c
c 1 = alive
c 0 = dead
c Create an uninitialised array.
subroutine cuarr(arr, m)
implicit none
integer m
character arr(m)
integer i
do i = 1, m
arr(i) = '0'
end do
end
c Calc array loc
c Note: x, y co-ords start at zero, 1D array at 1.
function locate(w, h, x, y)
implicit none
integer s, w, h, x, y, remain, locate
s = w * h
locate = remain((((y*w) + x)+1), s)
end
c Fortran 77 doesn't have the modulo intrinsic. Woe!
c This calculates the similar for +ve p, but where 0 => max val due to
c Fortran arrays starting at 1!
function remain(a, p)
implicit none
integer a, p, remain
remain = a - ((a/p) * p)
if (remain .le. 0) then
remain = remain + p
endif
end
c Get value at x,y
subroutine get(arr, m, w, h, x, y, v)
implicit none
integer m, w, h
character arr(m), t
integer x, y, v, l, locate
t = '1'
v = 0
l = locate(w, h, x, y)
if (arr(l) .eq. t) then
v = 1
endif
end
c Set value at x,y
subroutine set(arr, m, w, h, x, y, v)
implicit none
integer m, w, h
character arr(m)
integer x, y, v, l, locate
l = locate(w, h, x, y)
if (v .eq. 1) then
arr(l) = '1'
else
arr(l) = '0'
endif
end
c Get 9way sum
subroutine sum9w(arr, m, w, h, x, y, v)
implicit none
integer m, w, h
character arr(m)
integer x, y, v, l
integer nw, no, ne, ea, we, sw, so, se
call get(arr, m, w, h, x-1,y-1, nw)
call get(arr, m, w, h, x, y-1, no)
call get(arr, m, w, h, x+1, y-1, ne)
call get(arr, m, w, h, x-1, y, ea)
call get(arr, m, w, h, x, y, l)
call get(arr, m, w, h, x+1, y, we)
call get(arr, m, w, h, x-1, y+1, sw)
call get(arr, m, w, h, x, y+1, so)
call get(arr, m, w, h, x+1, y+1, se)
v = nw + no + ne + ea + l + we + sw + so + se
end
c Calculate the population (sum)
subroutine pop(arr, m, w, h, p)
implicit none
integer m, w, h, p
character arr(m), v
integer i, s
p = 0
s = w*h
do i = 1, s
v = arr(i)
if (v .eq. '1') then
p = p + 1
endif
enddo
end