How to Fix Fortran Formatting Issues in .pvd Files?

  • Context: Fortran 
  • Thread starter Thread starter cjm2176
  • Start date Start date
  • Tags Tags
    Format Fortran
Click For Summary

Discussion Overview

The discussion revolves around formatting issues encountered when writing .pvd files using Fortran, specifically focusing on ensuring that the output is correctly formatted on a single line without unwanted spaces.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant shares their code for writing a .pvd file and describes the formatting issue, particularly the unwanted spaces before the scientific notation and the line break.
  • Another participant inquires about the version of Fortran being used, suggesting it might be Fortran 95.
  • A participant confirms they are using Fortran 95 with the gfortran compiler.
  • A later reply provides a modified code example that addresses the formatting issue, suggesting that the format statement can fit on one line and that removing the leading space can be achieved by adjusting the format specifier.
  • One participant expresses satisfaction with the solution provided.

Areas of Agreement / Disagreement

Participants appear to agree on the solution to the formatting issue, as one participant confirms that the proposed changes work perfectly.

Contextual Notes

The discussion does not address potential limitations of the proposed solution or any assumptions regarding the specific requirements of .pvd file formatting.

Who May Find This Useful

Individuals working with Fortran, particularly those dealing with file formatting and output issues in scientific computing contexts.

cjm2176
Messages
8
Reaction score
0
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:
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?

Thanks!
cjm2176
 
Technology news on Phys.org
Which FORTRAN are you writing in? I'm guessing 95?
 
yes I'm using FORTRAN 95, the compiler is gfortran
 
Let me play with this. I'll get back to you shortly.
 
Just played with testing this out. Here is what I wrote.

Code:
      program testformat
      implicit none
	  
!23456789012345678901234567890123456789012345678901234567890123456789012	  

      real ttim
      character fname*13
  
      open(unit=10,file='test.txt')

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

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

      close(10)
 
      return
      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.
 
works perfectly thanks!
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K