[Paraview] vtk UNSTRUCTURED_GRID binary format with fortran 2003

Christophe Peyret christophe.peyret at onera.fr
Thu Apr 5 09:35:04 EDT 2007


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




More information about the ParaView mailing list