Fortran Program Test: How to Change Line in File

  • Context: Fortran 
  • Thread starter Thread starter kth
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary
SUMMARY

The discussion focuses on modifying line breaks in a Fortran program that writes to a file. The provided code demonstrates how to write integers to both the screen and a file, but the output in the file lacks the expected line breaks. Users compiling with F77 observed that the output file 'test.dat' contained unexpected formatting, while F90 users may experience different behavior. The issue is attributed to the handling of carriage control characters in Fortran, particularly when using F77 on different operating systems.

PREREQUISITES
  • Understanding of Fortran programming language syntax
  • Familiarity with file I/O operations in Fortran
  • Knowledge of differences between Fortran 77 (F77) and Fortran 90 (F90)
  • Basic concepts of carriage control in text files
NEXT STEPS
  • Explore Fortran file I/O functions in detail
  • Learn about carriage control in Fortran and its implications
  • Investigate differences in output formatting between F77 and F90
  • Review best practices for writing formatted output in Fortran
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those working with file I/O operations and seeking to understand output formatting issues in different Fortran versions.

kth
Messages
3
Reaction score
0
program test
open(50,file='test.dat')
write(6 ,FMT='(I3,/)') 111
WRITE(6 ,FMT='(I3,/)') 222
write(50,FMT='(I3,/)') 111
WRITE(50,FMT='(I3,/)') 222
close(50)
end

In the above, at the screen i see:
111
222
but in the dat file i see:
111222

How can i change line in the file??
 
Technology news on Phys.org
Kth
When I run the above code compiled with F77 fortran, test.dat contains
111

222

with an extra line between the numbers and after the line 222.
On the other hand, the first character on the screen has been used for printer carriage control, namely the first 1 had been taken as a new page.

Are you running with f77 or f90, and on Linux or Windows XP?
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 4 ·
Replies
4
Views
11K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 20 ·
Replies
20
Views
37K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K