Fortran 90 - How to write all on one line

In summary: I also tried viewing the output in visual studio 2005 and it still shows the output on multiple lines instead of one line as desired.In summary, the conversation discusses the issue of having the output for a code appear on a single line instead of multiple lines. It is suggested to use a format specifier to control the number of decimal places and to make sure the program used to view the output file does not have word wrap turned on. However, the person states that they have tried this and the output still appears on multiple lines.
  • #1
dvo
3
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
  • #2
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
 
  • #3
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.
 
  • #4
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?)
 
  • #5
I am running windows 7. I used notepad and wordpad to view the files.
 

Related to Fortran 90 - How to write all on one line

What is Fortran 90?

Fortran 90 is a programming language used primarily for scientific and engineering computations. It is an updated version of the original Fortran programming language and is known for its efficiency and array-based syntax.

Why would I want to write all on one line in Fortran 90?

Writing all on one line in Fortran 90 can save space and improve readability when writing short and simple programs. It can also be useful for writing quick one-line calculations or for debugging purposes.

How do I write all on one line in Fortran 90?

To write all on one line in Fortran 90, simply use the "inline" keyword at the beginning of the line. This tells the compiler to treat the entire line as a single statement, ignoring any line breaks or indentation.

Are there any limitations to writing all on one line in Fortran 90?

Yes, there are a few limitations to writing all on one line in Fortran 90. The statement must fit within the maximum line length allowed by the compiler, which is usually around 132 characters. Additionally, some complex statements may be difficult to read when written all on one line.

Can I mix both single-line and multi-line code in Fortran 90?

Yes, you can mix single-line and multi-line code in Fortran 90. This can be helpful for organizing your code and making it more readable. However, it is important to use proper indentation and spacing to avoid confusion and errors.

Similar threads

  • Programming and Computer Science
Replies
25
Views
992
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
17
Views
5K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
Back
Top