Creating Multiple Output Files in Fortran

  • Context: Fortran 
  • Thread starter Thread starter wooly
  • Start date Start date
  • Tags Tags
    File Fortran Output
Click For Summary
SUMMARY

The discussion focuses on generating multiple output files in Fortran, specifically using Fortran 77 (F77). A sample code snippet is provided, demonstrating how to create filenames based on integer variables. The code utilizes a loop to format the filenames, ensuring proper handling of leading zeroes. The output filenames range from A1.dat to A9.dat, showcasing the successful implementation of dynamic file naming.

PREREQUISITES
  • Understanding of Fortran 77 syntax and structure
  • Familiarity with character manipulation in Fortran
  • Knowledge of file I/O operations in Fortran
  • Basic programming concepts such as loops and formatting
NEXT STEPS
  • Explore advanced file handling techniques in Fortran 90 and later versions
  • Learn about dynamic memory allocation in Fortran
  • Investigate error handling in Fortran file operations
  • Study the use of formatted output in Fortran for complex data types
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those working on scientific computing or data processing applications that require dynamic file generation.

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
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K