I'm a beginner on FORTRAN so maybe what I'm asking is trivial, but I haven't found a solution: I have 2 different files to be read, do some calculation, and then write the result in a different file that depends on the input file. I tried fisrt a simple approach:
real*4 counts,par,deg,fl
integer*2 i
character*13 input_file
WRITE(*,*) "Name of file"
READ(*,*) input_file
OPEN(3,FILE=input_file)
IF (input_file .EQ. 'filename1.dat') THEN
OPEN(4,FILE='filename1_done.dat',STATUS='NEW')
par=3.5
ELSE
OPEN(4,FILE='filename2_done.dat',STATUS='NEW')
par=2.1
END IF
i = 0
do
i = i+1
READ(3,*,END=99) counts,deg
fl = 10**(counts)*par
WRITE(4,*) counts,deg,fl
END DO
99 CONTINUE
CLOSE (3)
END
My problem is that when IF returns false, it performs the calculation with the right value for par but it still calls the output file 'filename1_done.dat'. Even including the loop inside the IF statement and using different units for the output file didn't work. I feel that I'm missing something completely obvious, but can't figure out what. PS: I never learned the syntax for FORTRAN 90, but I'm trying to.
Aucun commentaire:
Enregistrer un commentaire