C Author: Mitch Richling<http://www.mitchr.me/>
C IP: Copyright 1993 by Mitch Richling. All rights reserved.
C Key word: common block FORTRAN f77
C Notes: Illustrates the FORTRAN common block
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
Generated by GNU Enscript 1.6.5.2.