Fortran Creating Multiple Output Files in Fortran

AI Thread Summary
The discussion focuses on generating multiple output files in a program, specifically using Fortran 77. The key solution involves creating a filename based on integer variables, with attention to formatting for leading zeroes when necessary. A sample code snippet demonstrates how to construct filenames like "A1.dat" through "A9.dat" using a loop. The method includes defining character variables for the filename and number, formatting the integer output, and using the `open` statement to create the files. This approach allows for dynamic file naming based on the loop index.
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
 
Technology 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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
8
Views
1K
Replies
17
Views
6K
Replies
5
Views
5K
Replies
5
Views
2K
Replies
59
Views
11K
Replies
5
Views
2K
Replies
6
Views
3K
Replies
3
Views
3K
Back
Top