A subroutine is a fortran procedure that is invoked by naming it in a call statement and that receives its input values and returns its results through an argument list. These variables are called dummy variables since the subroutine does not actually allocate any memory for them. When a program calls the subroutine, the execution of the calling program is suspended and the execution section of the subroutine is executed. When a return or end subroutine program is reached in the subroutine, the calling program starts running again at the line following the subroutine call. The return statement in the subroutine is optional.
Execution automatically returns to the calling program when the end subroutine statement is reached.
A return statement is necessary only when we wish to return to the calling program before the end of the subroutine is reached. Each subroutine is compiled separately from the main program and from any other procedures. Because each program unit in a program is compiled separately, statement label and local variable names may be reused in different routines without causing an error. Any executable program unit may call a subroutine, including another subroutine. To call a subroutine, the calling program uses a call statement.