How to Avoid Leading Whitespace When Writing to a Text File in FORTRAN?

  • Topic: Fortran 
  • Thread starter Thread starter Saladsamurai
  • Start date Start date
  • Tags Tags
    Fortran
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 3K views
Saladsamurai
Messages
3,009
Reaction score
7
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:
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:
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.
 
Physics news on Phys.org
If I could find a way to convert a type Real to a string I could do this. Anyone know how to do that?