Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran 90 - How to write all on one line

  1. Aug 4, 2011 #1

    dvo

    User Avatar

    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
     
  2. jcsd
  3. Aug 4, 2011 #2

    uart

    User Avatar
    Science Advisor

    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
     
  4. Aug 4, 2011 #3

    dvo

    User Avatar

    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.
     
  5. Aug 4, 2011 #4

    uart

    User Avatar
    Science Advisor

    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?)
     
  6. Aug 4, 2011 #5

    dvo

    User Avatar

    I am running windows 7. I used notepad and wordpad to view the files.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran 90 - How to write all on one line
  1. Fortran 90 (Replies: 1)

Loading...