Fortran Fortran 90 - How to write all on one line

  • Thread starter Thread starter dvo
  • Start date Start date
  • Tags Tags
    Fortran Line
AI Thread Summary
To write multiple values from a variable on one line in Fortran 90, a format specifier can be used, such as write(1,"(7f8.4)") X, X, X, X, X, X, X. However, if the output still appears on multiple lines, it may be due to the text editor's settings, particularly if word wrap is enabled. Users reported that using console output (print *) can lead to line breaks, while file output maintains a single line. It's essential to check the viewing software, as Notepad may wrap long lines, whereas WordPad handles them better. The original code works correctly in some compilers, indicating that the issue may not be with the code itself.
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.
 
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
25
Views
3K
Replies
4
Views
2K
Replies
2
Views
1K
Replies
12
Views
3K
Replies
4
Views
2K
Replies
17
Views
6K
Replies
5
Views
5K
Replies
3
Views
2K
Back
Top