Variables and other data objects are local to the program unit in which they are declared unless they appear in the argument list for the procedure. When a procedure is compiled all local objects that are not arguments to the procedure are allocated new storage space that is local to the procedure. The names of such objects are not ``visible'' outside the context of the procedure in which they are declared. Consider the following program:
PROGRAM tv IMPLICIT NONE REAL :: fun fun = 1.0 CALL girl PRINT*, fun END PROGRAM tv SUBROUTINE girl IMPLICIT NONE REAL :: fun ... fun=2.0 ... END SUBROUTINE girl
The variable fun in the main program is totally unrelated to fun in girl. A compiler would allocate different memory locations to the two objects. This would mean that although the call to girl would cause the fun (in girl) to be assigned the value 2.0, the value of fun in tv would be unaffected and the program would write out the value 1.0. In general, local objects are created each time a procedure is invoked and are destroyed when the procedure completes its execution and returns control to the calling program. Local variables do not retain their values between calls, however, if a local variable has the SAVE attribute, then it does retain its value. The SAVE attribute can be declared explicitly,
REAL, SAVE :: fun
or it is given implicitly by a variable being initialised, for example, in
REAL :: fun = 0.0fun would implicitly have the SAVE attribute.