Fortran 90 - How to write all on one line

  • Context: Fortran 
  • Thread starter Thread starter dvo
  • Start date Start date
  • Tags Tags
    Fortran Line
Click For Summary

Discussion Overview

The discussion revolves around writing output to a file in Fortran 90, specifically how to ensure that multiple values are written on a single line rather than wrapping to multiple lines. The context includes coding practices and output formatting in programming environments.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks a method to write multiple instances of a variable on a single line in a file, expressing a need for formatting that prevents line breaks.
  • Another participant suggests using a format specifier to control the number of decimal places in the output, proposing the format "(7f8.4)".
  • A later reply indicates that the original code works as intended on their system, suggesting that the issue may be related to the text editor used to view the output file rather than the Fortran code itself.
  • One participant questions whether the viewing software might be causing the appearance of line breaks, recommending checking settings in Notepad and Wordpad.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the issue, with some asserting that the output is correctly formatted while others continue to seek a solution for ensuring single-line output.

Contextual Notes

There is uncertainty regarding the impact of different text editors on the display of the output file, as well as the specific behavior of the Fortran compiler being used.

dvo
Messages
3
Reaction score
0
Hi I am trying to write the following into a file using visual studio 2005:

REAL :: X =5
open(1, file = 'File.txt')
write(1,*) X, X, X, X, X, X, X
END

Is there a way I can have the output on just one line?

I need it to be from the variable X instead of just changing it to '5'

The current output is:

5.000000 5.000000 5.000000 5.000000 5.000000
5.000000 5.000000
 
Technology news on Phys.org
It looks like you'll need a format specifier to tell it to use fewer decimals places. Try something like :

write(1,"(7f8.4)") X, X, X, X, X, X, X
 
uart said:
It looks like you'll need a format specifier to tell it to use fewer decimals places. Try something like :

write(1,"(7f8.4)") X, X, X, X, X, X, X

Oh no. Regardless of how many decimals places there are, I need a code that will continue the output on the same line even if the output becomes too long.

I know it sounds ridiculous but this problem is for a larger program I'm currently working on that includes a kind of spreadsheet where I would like some values to all continue in one line.

Thank you.
 
Your original code writes all on the one line for me (I'm using the freeware g95 fortran compiler btw).

If I use the console as an output device (print *,...) then it uses multiple lines, but when I write to a file there is no problems - it all goes on one line.

Are you sure it's not just the program you're using to view the file? If you use notepad for example then make sure you have "format->word wrap" turned off. If the lines are really long then notepad with eventually wrap them regardless of that setting, but wordpad is better behaved (BTW. Are you running Windows or something else. What software are you using to view the output file?)
 
I am running windows 7. I used notepad and wordpad to view the files.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K