Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran output file

  1. Dec 14, 2008 #1
    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
     
  2. jcsd
  3. Dec 14, 2008 #2
    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 (Text):
          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 (Text):
    A1.dat
    A2.dat
    A3.dat
    A4.dat
    A5.dat
    A6.dat
    A7.dat
    A8.dat
    A9.dat
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?