/
coms.f
61 lines (53 loc) · 1.55 KB
/
coms.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
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C @file coms.f
C @Author Mitch Richling<https://www.mitchr.me>
C @Copyright Copyright 1993 by Mitch Richling. All rights reserved.
C @brief Illustrates the FORTRAN common block.@EOL
C @Keywords common block fortran
C @Std F77
C
program coms
C Declaration optional (a and b are real by default)
real a, b
C COMMON let's us specify that vars will
C be common to all code blocks that request it
common a
C You can name a common block too. Consider this
common /foo/b
a=1.1
b=2.2
write (*,*) 'In main... a=', a
write (*,*) 'In main... b=', b
write (*,*) 'In main... Calling sub1'
call sub1
write (*,*) 'In main... a=', a
write (*,*) 'In main... b=', b
call sub2
write (*,*) 'In main... a=', a
write (*,*) 'In main... b=', b
write (*,*) 'Back in main..'
end
C Sub number 1.
subroutine sub1
real a, b
common a
write (*,*) 'In sub1... a=', a
write (*,*) 'In sub1... b has no value here'
a=10
b=20
write (*,*) 'In sub1... a=', a
write (*,*) 'In sub1... b=', b
return
end
C Sub number 2.
subroutine sub2
real a, b
common /foo/b
write (*,*) 'In sub2... a has no value here'
write (*,*) 'In sub2... b=', b
a=30
b=40
write (*,*) 'In sub1... a=', a
write (*,*) 'In sub1... b=', b
return
end