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

Trouble with format in fortran

  1. Jun 28, 2011 #1
    Hi all

    I am trying to use fortran to write a .pvd file, an example of what one line of such a file should look like is

    <DataSet timestep="1.00000E-07" part="0" file="Psb000001.vtu"/>

    however with the following code:

    Code (Text):
    write(90,2000) ttim,fname
    2000  format('<DataSet timestep="',1pe15.5,'" part="0" file="',
         &       a,'"/>')
    gives me the following result:

    <DataSet timestep=" 1.00000E-07" part="0" file="Psb000001.vtu

    which happens to result in a bad .pvd file. Is there a way to garuantee that everything gets written on one line? Also, is it possible to get rid of the spaces before 1.00000E-07?

  2. jcsd
  3. Jun 29, 2011 #2
    Which FORTRAN are you writing in? I'm guessing 95?
  4. Jun 29, 2011 #3
    yes I'm using FORTRAN 95, the compiler is gfortran
  5. Jun 29, 2011 #4
    Let me play with this. I'll get back to you shortly.
  6. Jun 29, 2011 #5
    Just played with testing this out. Here is what I wrote.

    Code (Text):
          program testformat
          implicit none

          real ttim
          character fname*13

          ttim = 1.0E-7
          fname = "Psb000001.vtu"

          write(10,2000) ttim,fname
     2000 format('<DataSet timestep="',es13.7,'" part="0" file="',a,'"/>')

          end program
    FORTRAN can go out to 72 columns, so you don't need to truncate your format statement and continue to the next line. The whole thing can fit on one line. Taking the 1 out of in front of your real ouput will remove that space.
  7. Jun 29, 2011 #6
    works perfectly thanks!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook