- #1
jf22901
- 55
- 1
Hi all
I am currently using subroutines, and placing them at the end of the main program. However, I was wondering if it is possible to save them to a separate file, which the main program then calls?
For example, in the program below I call the subroutine 'SUB', which is located at the end of the program 'TEST'. Is there any way in which it could be split so that the program 'TEST is in a file called 'test.f' and the subroutine is in a file called 'sub.f'? That way I could call the same subroutines from different programmes, rather than having to put them at the end all the time.
Many thanks,
Jack
I am currently using subroutines, and placing them at the end of the main program. However, I was wondering if it is possible to save them to a separate file, which the main program then calls?
For example, in the program below I call the subroutine 'SUB', which is located at the end of the program 'TEST'. Is there any way in which it could be split so that the program 'TEST is in a file called 'test.f' and the subroutine is in a file called 'sub.f'? That way I could call the same subroutines from different programmes, rather than having to put them at the end all the time.
Many thanks,
Jack
Code:
PROGRAM TEST
IMPLICIT NONE
INTEGER X, Y, Z, TOTAL, TOT
PRINT *, 'Enter numbers X,Y,Z where Y > X'
READ *, X, Y, Z
CALL SUB(X, Y, Z, TOTAL)
PRINT *, 'TOTAL =', TOTAL
END
C***********************************************************************
C Subroutine called above is located below
C***********************************************************************
SUBROUTINE SUB(A, B, C, TOT)
INTEGER TOT, A, B, C, I
TOT=C
DO 10 I=A,B
TOT = TOT*I
10 END DO
RETURN
END
Last edited: