Recursive Routines in FORTRAN 77 (and Fortran 90)

Submitted by:Jhon Brain

Date added:10 January, 2012

Category:Fortran

Fortran programmer should always write new code in Fortran 90 or Fortran 95, but for those of you stuck on a desert island with only a FORTRAN 77 compiler at your disposal, here's a way to write a recursive subroutine. FORTRAN 77 subroutines and functions are not allowed to call themselves directly. Attempting to do such will result in a compile time error with compilers that adhere to the FORTRAN 77 standard.

Tags: recursive routine

Code Snippet:

      PROGRAM MAIN
INTEGER N, X
EXTERNAL SUB1
COMMON /GLOBALS/ N
X = 0
PRINT *, 'Enter number of repeats'
READ (*,*) N
CALL SUB1(X,SUB1)
END

SUBROUTINE SUB1(X,DUMSUB)
INTEGER N, X
EXTERNAL DUMSUB
COMMON /GLOBALS/ N
IF(X .LT. N)THEN
X = X + 1
PRINT *, 'x = ', X
CALL DUMSUB(X,DUMSUB)
END IF
END
 
 

Comments