CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Generating binary data files in fortran to read in paraview

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 22, 2017, 06:32
Smile Generating binary data files in fortran to read in paraview
  #1
New Member
 
Nadeem Malik
Join Date: May 2017
Posts: 3
Rep Power: 7
nadeem_malik is on a distinguished road
Hi, I am new here, and I am also new to paraview -- so my apologies in advance for what will (I am sure) seem like a naive question for seasoned workers in this field.

My question is quite simple. I have inherited a fortran DNS (Direct Numerical Simulation) code for vortex interaction studies. I want to output and store variables such as the velocity field U(x,y,z,t) into a file (fort.42 say) and then read it in to paraview for the usual plots and visualisations and movies, etc.

The problem is the very first step. I have very large output data even in binary -- at the moment it is about 4GB, but it will increase to terabytes in the future for larger systems. The data is written in the fortran program in a simple binary format, e.g. (assuming regular cubic grid).

f1=1.
nx=260
ny=260
nz=260
open(unit=3,file='fort.42',form='unformatted')
write(3) nx,ny,nz
write(3) f1,f1,f1,f1
write(3) (((f1,i=1,nx),j=1,ny),k=1,nz), &
(((U(i,j,k,1),i=1,nx),j=1,ny),k=1,nz), &
(((U(i,j,k,2),i=1,nx),j=1,ny),k=1,nz), &
(((U(i,j,k,3),i=1,nx),j=1,ny),k=1,nz), &
(((f1,i=1,nx),j=1,ny),k=1,nz)

I compile using gfortran.

When I attempt to read fort.42 in paraview, it returns an error - it cannot read the binary file.

I would greatly appreciate an explanation. If someone would be kind enough to suggest how the above code could be modified, or maybe write a simple code to convert the fort.42 in to paraview readable binary data, I would be very grateful.

I guess for non-uniform grid, you would be write out each grid coordinate explicitly as well?

Thanks
Nadeem
nadeem_malik is offline   Reply With Quote

Old   May 22, 2017, 11:00
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,062
Rep Power: 64
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
I am quite sure that Paraview has documentations for the input data files...have read it?
FMDenaro is offline   Reply With Quote

Old   May 23, 2017, 11:23
Smile
  #3
New Member
 
Nadeem Malik
Join Date: May 2017
Posts: 3
Rep Power: 7
nadeem_malik is on a distinguished road
Quote:
Originally Posted by FMDenaro View Post
I am quite sure that Paraview has documentations for the input data files...have read it?

Dear FMDenaro,

I have looked through the help menu, and a few websites offering some advice. But this simple looking problem has not been addressed directly - at least I cannot find it.

On the paraview help menu, it mentions reading all kinds of data files, from *.csv to RAW data, etc. The problem is how to get he data in to any one of these formats from inside a fortran code in the first place?

Searching through the web, I found an example for reading in a simple *.csv file containing a scalar field f(x,y,z) laid out on a regular cubic grid. I got it read in by paraview -- although now I want to know how to produce is isoscalar surfaces s(x,y,z)=f=C, where C can be any constant in the range of scalar values? But *.csv are ASCII files.

How do I generate an equivalent binary *csv file using fortran -- is there such a things as a binary *.csv file ?

One way, in principle, could be to write a short interface file in C or C++, which reads fortran binary (is this possible in c++ ?), and then print out the same data but in paraview readable binary ?

But whay can't I do this directly in fortran ?

Thanks
Nadeem
nadeem_malik is offline   Reply With Quote

Old   May 23, 2017, 14:32
Default
  #4
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,062
Rep Power: 64
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
I personally don't use paraview but tecplot, however have a look here

http://people.sc.fsu.edu/~jburkardt/...io/vtk_io.html

https://github.com/szaghi/VTKFortran
FMDenaro is offline   Reply With Quote

Old   May 24, 2017, 03:55
Default
  #5
Senior Member
 
Join Date: Oct 2011
Posts: 166
Rep Power: 12
naffrancois is on a distinguished road
Hello,

Here is a piece of code I am using for unstructured data sets. The important bit here is the list of arguments set in the open statement. Then, for your special case of structured grids, the syntax may be simpler. Have a look to this pdf:

http://www.vtk.org/wp-content/upload...le-formats.pdf

Good luck
Attached Files
File Type: txt binary.txt (2.8 KB, 73 views)
naffrancois is offline   Reply With Quote

Old   May 24, 2017, 07:03
Default
  #6
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,809
Blog Entries: 29
Rep Power: 36
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
You can't expect paraview to know how your data is organized, less than ever if it is also in Fortran binary form, which typically (I don't know if this is standardized) uses 4 + 4 bytes at the beginning and end of records.

You should use the STREAM format as per naffrancois example.

But I suggest to open the file-format file also linked by naffrancois, to look for the specific format more suited to you (note that Structured Points or vtkImageData might be the most suitable ones, depending on the method you use, i.e. Finite Differences or Finite Volumes).
sbaffini is offline   Reply With Quote

Old   May 24, 2017, 07:47
Smile
  #7
New Member
 
Nadeem Malik
Join Date: May 2017
Posts: 3
Rep Power: 7
nadeem_malik is on a distinguished road


Thank you to naffrancois and to sbaffini and to FMDenaro for your various responses and suggestions.

I'll get back to you in case of problems arising -- but I suspect that the information supplied is enough. Thanks.

Best
Nadeem Malik
nadeem_malik is offline   Reply With Quote

Reply

Tags
binary file, fortran, large data, paraview

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[General] Extracting ParaView Data into Python Arrays Jeffzda ParaView 19 June 11, 2020 15:54
[OpenFOAM] Paraview doesn't seem to be picking up data generated by icofoam MikeHersee ParaView 2 January 6, 2015 08:27
[OpenFOAM] paraview cannot read data from time directories shuoxue ParaView 2 June 9, 2013 23:15
[OpenFOAM] How to compress results files so that paraview can still read them mirko ParaView 2 January 20, 2011 11:07
Fortran: Seeking data in files. cfd guy Main CFD Forum 6 May 23, 2002 22:30


All times are GMT -4. The time now is 02:13.