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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

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