I have several programs that use the same block of code at the begining, but do different stuff. Is it possible to declare this block of code in an external file (fortran file or text file) so if I want to change one part of this code (in the block I'm talking about) I don't have to change it in every program?
Example: Two programs MAIN1 and MAIN2 that do different operations with the vector X generated in an external file.
PROGRAM MAIN1
IMPLICIT NONE
! External block here
REAL, PARAMETER :: M = REAL(N)*2.0
INTEGER :: i
REAL :: Out1
Out1 = 0.0
DO i = 1,SIZE(X,1)
Out1 = Out1+M*X(i)
END DO
PRINT *, Out1
END PROGRAM MAIN1
PROGRAM MAIN2
IMPLICIT NONE
! External block here
REAL, PARAMETER :: M = 1.0
INTEGER :: i
REAL :: Out2
Out1 = 1.0
DO i = 1,SIZE(X,1)
Out2 = Out2*M*X(i)
END DO
PRINT *, Out2
END PROGRAM MAIN2
And this is the external code:
INTEGER,PARAMETER :: N = 5
REAL :: X(N)
CALL RANDOM_NUMBER(X)
I tried putting the external code in a module, but I cannot call subroutines in this way (as I understand that all the lines should be of the type INTEGER,PARAMETER :: N = 5) if want want to call the external block right after the IMPLICIT NONE statement.
Any ideas?