I would like to understand how scopes work in Fortran-77.
From what I have understood so far, there is no global scope in Fortran-77. However, the “common block” allows this to be changed as it allows variables to be shared between multiple program units.
I have come across examples of code where the “#include ‘file.inc’” directive (not to be confused with the Fortran include statement) is also used to group together a number of declarations which are then included in the declaration part of each program unit.
for example: in
declarations.inc I have this
integer x real y complex z
main.F I have this
program test #include "declarations.inc" x = 1 y = 2 z = cmplx(3, 4) print *, 'in test: x=', x, ', y=', y, ', z=', z call sub(z, y, x) end subroutine sub(z, y, x) #include "declarations.inc" x = 10 y = 20 z = cmplx(30, 40) print *, 'in sub : x=', x, ', y=', y, ', z=', z end
And even with this construction, the scope always remains local to each program unit.
Is it not possible for a program to contains another subprogram? And then have variables defined in the scope of its parent? What about the
ENTRY statement, which seems to behave almost identically to the
contains statement in modern Fortran subprograms?