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

FORTRAN Write Statement Issue

  1. Jun 24, 2011 #1
    I am writing to a text file and a do not want any leading whitespace on each line. I have been trying the Write(*,'(a)') statement. This works just fine:

    Code (Text):

    Program MyTest

    Open(2,File = 'testFile.inp')

    Write(2,'(a)')'DIAG'
    Write(2,'(a)')'REAC C2H4F2 2.00000000000'

    Close(2)
    End
     
    However, the value written is not always 2.00000000000 and hence I would like something like:


    Code (Text):

    Program MyTest
    Double Precision PHI

    PHI = 2.0

    Open(2,File = 'testFile2.inp')

    Write(2,'(a)')'DIAG'
    Write(2,'(a)')'REAC C2H4F2 ', [B]PHI[/B]

    Close(2)
    End
     

    I am trying to avoid statement labels if possible.

    However the latter produces nonsense in the file for PHI.
     
  2. jcsd
  3. Jun 24, 2011 #2
    If I could find a way to convert a type Real to a string I could do this. Anyone know how to do that?
     
  4. Jun 24, 2011 #3

    Mark44

    Staff: Mentor

    Something like this?
    Code (Text):

    WRITE(17, FMT= '('REAC C2H4F2', 1X, F13.10)') PHI
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook