I have two FORTRAN codes that are almost identical except for one line of code, and the FILE names in my OPEN statements. This one different line of code produces the two distinct final results I am looking for hence why I have two different codes.
I would like to merge these two codes into one if possible.
What is the best way to do this? To be specific, I want to have only one FORTRAN file which will run either FORTRAN 'code'. That way, when I need to edit either code I am only doing so in one file. Now having two different files it is a bit of an inconvenience.
A simplified example code for the two different files are below, Sample.f90 and Sample2.f90. What IF statements can I use that will allow me to choose which initial condition to use, either R = COS(x+y) or R = SIN(x+y)? I am not familiar at all with how to use IF statements for this.
PROGRAM SAMPLE !Sample.f90
USE TestModule
IMPLICIT NONE
REAL, DIMENSION(-10,10) :: R
INTEGER :: i,j
REAL :: x,y
OPEN(UNIT = 100, FILE = 'Sample1.dat')
DO j = -10,10
DO i = -10,10
x = i*0.1
y = j*0.1
R(i,j) = COS(x+y)
END DO
END DO
WRITE(100,*) R(0,1)
END PROGRAM
!The next program is of the form:
PROGRAM SAMPLE2 !Sample2.f90
USE TestModule2
IMPLICIT NONE
REAL, DIMENSION(-10,10) :: R
INTEGER :: i,j
REAL :: x,y
OPEN(UNIT = 101, FILE = 'Sample2.dat')
DO j = -10,10
DO i = -10,10
x = i*0.1
y = j*0.1
R(i,j) = SIN(x+y)
END DO
END DO
WRITE(101,*) R(0,1)
END PROGRAM