0

I have hundreds of files with file name fort.1, fort.2, fort.3 and so on until fort.5000. What I want is to open each file and operate that file and close. Then go on with next file. I want to do this in Fortran 90.

I have browsed but could not get what I want. I saw one thread for opening but it doesn't help me much.

I tried writing `

program openFile
IMPLICIT none
INTEGER(I-N), REAL*8(A-H,O-Z)
real,dimension(2000) :: angle           
CHARACTER(len=10) FN
integer::I, k
integer,parameter :: N=102  
DO I=101,N
!WRITE(FN,10) I
!WRITE(6,*) FN
OPEN(1,FILE=FN)
do k=1,200
read(1,'(F8.3)') angle(k)
print*,
end do      
CLOSE(1)
enddo 
10 FORMAT(5Hfort.I3)
STOP
END

` But seems it doesn't work. Is that possible me getting some help? Thanks in advance.

Community
  • 1
  • 1
Vijay
  • 965
  • 5
  • 13
  • 27
  • you realise you have commented out the key line setting the file name. also the format here only works for 3 digit numbers, not to mention using the archaic h descriptor – agentp Nov 06 '12 at 12:26
  • Try to see some example programs in some book or internet tutorial and use some formatting for your programs. You will be able to orientate better in them. – Vladimir F Героям слава Nov 06 '12 at 12:56

1 Answers1

6

The approach is to create the filename in a string. For your style of names:

write (filename, '("fort.", I0)' )  FileNum

Then open each file using the filename, as you are doing.

A related question: https://stackoverflow.com/questions/13048441/writing-files-in-fortran-with-increasing-numbers

Community
  • 1
  • 1
M. S. B.
  • 28,968
  • 2
  • 46
  • 73