A complete Fortran program is made up from a number of distinct program units. Program units are:
The main program and some procedure (function or subroutine) subprograms may be provided by a language other than Fortran. For example a C main program may call a function defined by a Fortran function subprogram, or a Fortran main program may call a procedure defined by C.
These Fortran program units may be given be distinct files or within a single file.
For example, we may see the two files:
prog.f90
program main
use mod
end program main
mod.f90
module mod
end module mod
And the compiler (invoked correctly) will be able to associate the main program with the module.
The single file may contain many program units
everything.f90
module mod
end module mod
program prog
use mod
end program prog
function f()
end function f()
In this case, though, it must be noted that the function f
is still an external function as far as the main program and module are concerned. The module will be accessible by the main program, however.
Typing scope rules apply to each individual program unit and not to the file in which they are contained. For example, if we want each scoping unit to have no implicit typing, the above file need be written as
module mod
implicit none
end module mod
program prog
use mod
implicit none
end program prog
function f()
implicit none
<type> f
end function f