Creating Multiple Output Files in Fortran

  • Context: Fortran 
  • Thread starter Thread starter wooly
  • Start date Start date
  • Tags Tags
    File Fortran Output
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 6K views
wooly
Messages
1
Reaction score
0
Hi guys,

I am tryin to get my program to output multiple files with the name of the file dependent on a number of integer variables in the program, any help with this would be greatfully appreciated.

Cheers
 
Physics news on Phys.org
You can try something along these lines (for F77).
Take care about the leading zeroes if you have different number of digits in the numeric part of the file.

Code:
      character*12 filename
      character*1 num
      do 20 I=1,9
      write(num,999)I
 999  format(I1)
      filename='A'//num//'.dat'
      print *,filename
      open(unit=5,file=filename, status='unknown')
   20 continue

Output:
Code:
A1.dat
A2.dat
A3.dat
A4.dat
A5.dat
A6.dat
A7.dat
A8.dat
A9.dat