Fortran How to Fix Fortran Formatting Issues in .pvd Files?

  • Thread starter Thread starter cjm2176
  • Start date Start date
  • Tags Tags
    Format Fortran
AI Thread Summary
The discussion centers on generating a .pvd file using Fortran, specifically addressing formatting issues in the output. The original code produced unwanted spaces before the scientific notation of the timestep and resulted in a broken line in the output. A user sought a solution to ensure the output is on a single line and free of leading spaces. Another participant confirmed they were using Fortran 95 with the gfortran compiler and provided a revised code snippet that successfully formatted the output correctly. The key adjustments included using the `es13.7` format specifier to eliminate the leading space and ensuring the entire format statement fit within the 72-column limit of Fortran. The revised code produced the desired output without formatting issues.
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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
12
Views
3K
Replies
5
Views
5K
Replies
2
Views
1K
Replies
3
Views
3K
Replies
16
Views
3K
Replies
3
Views
4K
Replies
6
Views
2K
Replies
2
Views
2K
Replies
2
Views
2K
Back
Top