Fortran Fortran 90 - How to write all on one line

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

The discussion focuses on writing output to a file in Fortran 90 using Visual Studio 2005. The user seeks to ensure that multiple outputs of the variable X appear on a single line in the output file. A suggested solution involves using the format specifier "write(1,'(7f8.4)') X, X, X, X, X, X, X" to control the number of decimal places. Additionally, it is noted that the viewing software, such as Notepad or WordPad, may affect how the output appears, particularly regarding line wrapping.

PREREQUISITES
  • Familiarity with Fortran 90 syntax and file I/O operations
  • Understanding of format specifiers in Fortran
  • Basic knowledge of Visual Studio 2005 environment
  • Experience with text file viewing software like Notepad and WordPad
NEXT STEPS
  • Explore advanced Fortran 90 file I/O techniques
  • Learn about different format specifiers in Fortran for output control
  • Investigate the behavior of various text editors regarding line wrapping
  • Review best practices for output formatting in Fortran applications
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those working with file I/O operations and output formatting in applications using Visual Studio 2005.

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.
 
We have many threads on AI, which are mostly AI/LLM, e.g,. ChatGPT, Claude, etc. It is important to draw a distinction between AI/LLM and AI/ML/DL, where ML - Machine Learning and DL = Deep Learning. AI is a broad technology; the AI/ML/DL is being developed to handle large data sets, and even seemingly disparate datasets to rapidly evaluated the data and determine the quantitative relationships in order to understand what those relationships (about the variaboles) mean. At the Harvard &...

Similar threads

  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · 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