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!
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

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