Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

opening multiple files

Oliviu
Beginner
1,875 Views
Can somebody please tell me how to open and write in multiple files using Compaq Visual Fortran.
For example,in a simple Do iteration loop:
number=0
do i=1,100
number=number+1
What do i have to write next so that each ''number'' is written in a different file,and not overwrite the file
created with a normal open file statement.Furthermore,is there any possible way to control the file name,
so that the 100 files generated will have the following names: file_1.dat,file_2.dat,and so on.
Thank you.
0 Kudos
1 Reply
bmchenry
New Contributor II
1,875 Views
simply create a filename character string.
Then use an internal write to increment the filename string 'name'
use open to open the files (and close after if you no longer need)

so for example
character*255 myfilename
number=0
do i=1,100
number= number+1
write(myfilename,100) number
100 format('file_',i3.3,'.dat')
open (filename=myfilename, unit=number)
write(i,110) number
110 format(' this is file', i3.3)
end do
0 Kudos
Reply