[Paraview] vtk UNSTRUCTURED_GRID binary format with fortran 2003

Burlen burlen at apollo.sr.unh.edu
Thu Apr 5 10:25:13 EDT 2007


hi, I am sure if you work with a small test example and a binary editor you 
can figure out what's going on. I would use VTK classes(python/tcl/c++) to 
produce a small test file in vtk binary format, which contained a very simple 
data set. Then try writing the same data set using your fortran routines. you 
can compare the results to see what your issue is.

That said, rather than writing your own vtk file writer, you'd probably be 
better off using the existing vtk writer classes directly. To do this you 
write a small c++ routine which you would call from your fortran code when 
you want to write the file. that way you leverage the vtk writer classes, and 
you won't have to worry about the specifics of the file format. 

-- 

Burlen Loring
Space Science Center
Institute for the Study of Earth, Oceans, and Space
University of New Hampshire
39 College Road, Durham, NH 03824
Phone: 603-862-1140
On Thursday 05 April 2007 09:35 am, Christophe Peyret wrote:
> Hello,
>
> I'm trying to write vtk UNSTRUCTURED_GRID binary format with fortran
> 2003. I am facing difficulties to find a complete description of the
> binary format. I wrote the ascii format without any problem using
> that program :
>
>      open(iens, file=trim(fileOut)//'_ascii.vtk',status='unknown',
> action='write')
>
>      write(iens,'(a)')"# vtk DataFile Version 3.0"
>      write(iens,'(a)')"vtk output"
>      write(iens,'(a)')"ASCII"
>      write(iens,'(a)')"DATASET UNSTRUCTURED_GRID"
>      write(iens,'("POINTS",i10,1x,"float")')nVert
>      select case(geo)
>      case(2) ; write(iens,'(3(e12.5,1x))')(vertices(1:2,i),real
> (0.,kind=4) , i=1,nVert)
>      case(3) ; write(iens,'(3(e12.5,1x))')(vertices
> (1:3,i)                 , i=1,nVert)
>      end select
>
>      write(iens,'(/"CELLS",2i10)' )nT4+nT3+nL2 , 5*nT4+4*nT3+3*nL2
>      if( nT4/=0 ) write(iens,'(i1,4i10)')(4, tetra(1:4,i)-1 , i=1,nT4)
>      if( nT3/=0 ) write(iens,'(i1,3i10)')(3, trian(1:3,i)-1 , i=1,nT3)
>      if( nL2/=0 ) write(iens,'(i1,2i10)')(2, edges(1:2,i)-1 , i=1,nL2)
>
>      write(iens,'(/a,i10)')'CELL_TYPES ',nT4+nT3+nL2
>      if( nT4/=0 )write(iens,'(i2)')( 10, i=1,nT4) ! Tetra
>      if( nT3/=0 )write(iens,'(i2)')(  5, i=1,nT3) ! Triangles
>      if( nL2/=0 )write(iens,'(i2)')(  3, i=1,nL2) ! Edges
>
>
> for the binary format it should be possible as fortran 2003 give the
> possibility to write C generic binary format.
>
> With intel ifort v10.0.12, I wrote the program :
>
>      open(unit=iens,file=trim(fileOut)//'_bin.vtk',&
>      &    form='unformatted',&
>      &    recordtype='STREAM_LF',&
>      &    action='write'                          ,&
>      &    convert='BIG_ENDIAN'                    ,&
>      &    access='sequential'                      )
>
>      cbuffer='# vtk DataFile Version 3.0' ; write(iens)trim(cbuffer)
>      cbuffer='vtk output'                 ; write(iens)trim(cbuffer)
>      cbuffer='BINARY'                     ; write(iens)trim(cbuffer)
>      cbuffer='DATASET UNSTRUCTURED_GRID'  ; write(iens)trim(cbuffer)
>
>      write(cbuffer,'("POINTS",i10,1x,"float")')nVert
>      write(iens)trim(cbuffer)
>
>      select case(geo)
>      case(2) ; write(iens)(vertices(1:2,i),real(0.,kind=4) , i=1,nVert)
>      case(3) ; write(iens)(vertices(1:3,i)                 , i=1,nVert)
>      end select
>
>      write(cbuffer,'("CELLS",2i10)')nT4+nT3+nL2,5*nT4+4*nT3+3*nL2
>      write(iens)trim(cbuffer)
>
>      if( nT4/=0 ) write(iens)(4, tetra(1:4,i)-1 , i=1,nT4)
>      if( nT3/=0 ) write(iens)(3, trian(1:3,i)-1 , i=1,nT3)
>      if( nL2/=0 ) write(iens)(2, edges(1:2,i)-1 , i=1,nL2)
>
>      write(cbuffer,'("CELL_TYPES",i10)')nT4+nT3+nL2
>      write(iens)trim(cbuffer)
>      if( nT4/=0 )write(iens)( 10, i=1,nT4) ! Tetra
>      if( nT3/=0 )write(iens)(  5, i=1,nT3) ! Triangles
>      if( nL2/=0 )write(iens)(  3, i=1,nL2) ! Edges
>
>
> When I open the binary file generated with paraview, the vertices are
> readed, I have a correct bounding box and the right number of
> vertices. But paraview fails on reading the CELLS and returns me the
> error message :
>
>
> # Error or warning: There was a VTK Error in file: /Users/berk/
> ParaViewReleaseRoot/ParaView-2.6.0/VTK/IO/
> vtkUnstructuredGridReader.cxx (350)
> vtkUnstructuredGridReader (0x19acd690): Unrecognized keyword:
> ErrorMessage end
>
>
> _______________________________________________
> ParaView mailing list
> ParaView at paraview.org
> http://www.paraview.org/mailman/listinfo/paraview

-- 

Burlen Loring
Space Science Center
Institute for the Study of Earth, Oceans, and Space
University of New Hampshire
39 College Road, Durham, NH 03824
Phone: 603-862-1140


More information about the ParaView mailing list