[Paraview] Writing binary files: C/Fortran interface to VTK XMLfiles.

Dominik Szczerba domi at vision.ee.ethz.ch
Wed Feb 1 17:18:33 EST 2006


Thank you very much for the examples, I was only missing encoding="raw"
(not explained clearly by the VTK format specification PDF). Now I am
facing problems with compression, but not yet sure what is wrong.
thanks and regards,
Dominik

Berk Geveci wrote:
> Brad implemented the readers and writers so he would know a lot more
> than I do. I am including 3 examples of the same data. One ascii, one
> binary and one binary compressed. None of the binaries have base64
> encoding. I wrote them out from VTK by changing the settings of the
> writer.
> 
> On 2/1/06, Dominik Szczerba <domi at vision.ee.ethz.ch> wrote:
> 
>>After a few hours I am basically succesful only with ASCII versions,
>>tried binary inline/appended with various headers with no luck.
>>Does anyone have any clear definitions and/or examples? I found bits and
>>pieces on information on the mailinglist, but that was apparently not
>>enough.
>>thanks and regards,
>>DS
>>
>>Dominik Szczerba wrote:
>>
>>>OK, I didnt know it is possible. Will give it a try tomorrow evntl. come
>>>back.
>>>Thanks a lot,
>>>Dominik
>>>
>>>Berk Geveci wrote:
>>>
>>>
>>>>Why not go zlib compressed without base64 encoding? That's supported you know...
>>>>
>>>>On 1/31/06, Dominik Szczerba <domi at vision.ee.ethz.ch> wrote:
>>>>
>>>>
>>>>
>>>>>I see the point. And yes, I want to stay far away from ASCII. So what
>>>>>format would you recommend to STORE my results in a COMPRESSED way
>>>>>maintaining readability with Paraview? Any binary legacy file I produce
>>>>>takes gigabytes - crunched with gzip a fraction of it, but paraview
>>>>>won't read it. ASCII is simply prohibitive, base64'ed with
>>>>>zlibcompressor not much better. At the moment I store my results in my
>>>>>own gzipped format, and convert them to VTK format on demand - but that
>>>>>is pretty annoying.
>>>>>regards,
>>>>>--dsz
>>>>>
>>>>>Berk Geveci wrote:
>>>>>
>>>>>
>>>>>
>>>>>>Base64 encoding is only necessary if you want your XML file to be
>>>>>>ASCII. This is necessary if you want the file to conform to XML so
>>>>>>that the file can be opened in XML viewers (like a browser). Also,
>>>>>>some people prefer transferring ASCII files instead of binary files.
>>>>>>If you are not interested in either of these, there is no need to have
>>>>>>base64 encoding. I would recommend not using it in fact. One of these
>>>>>>days I will change the default in paraview so that it does not write
>>>>>>base64 encoded files.
>>>>>>
>>>>>>
>>>>>>On 1/31/06, Dominik Szczerba <domi at vision.ee.ethz.ch> wrote:
>>>>>>
>>>>>>Sorry to interupt your discussion but nobody ever explained me this: why
>>>>>>use base64 encoding at all? Isint it a step back to huge ASCII files??
>>>>>>E.g. I see no significant compression with the VTK's zlib compressor
>>>>>>when using XML data files because the compressed stream is converted to
>>>>>>ASCII. Will someone kindly explain me this paradox?
>>>>>>Thanks
>>>>>>Dominik
>>>>>>
>>>>>>Thierry Dubuis wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>There are lot of encoding Base 64 program on the web but only in C, Java
>>>>>>>or Visual Basic.
>>>>>>
>>>>>>>If you can use C/C++ compiler, I thing the best way for you is to use
>>>>>>>the Brad King's fortran code example (see my last email).
>>>>>>>To convert a data array to a string in C we use the memory copy in
>>>>>>>fortran I don't know.
>>>>>>>Could you use pointer? 2 pointer on the same memory adress
>>>>>>>1. the fist with the real*8 type
>>>>>>>2. the second with a character type
>>>>>>
>>>>>>>Try in this way.
>>>>>>
>>>>>>>Best regards,
>>>>>>>Thierry Dubuis
>>>>>>
>>>>>>>Stéphane Montésino wrote:
>>>>>>
>>>>>>
>>>>>>>>Thanks for all tese answers, but I 'm still like an an homosexual with
>>>>>>>>a wonderfull girl. I don't know how to use it (sorry her).
>>>>>>
>>>>>>>>In fact, I would like to directly write this type of file that I can
>>>>>>>>obtain when I save my data with Paraview:
>>>>>>
>>>>>>>><?xml version="1.0"?>
>>>>>>>><VTKFile type="RectilinearGrid" version="0.1"
>>>>>>>>byte_order="LittleEndian" compressor="vtkZLibDataCompressor">
>>>>>>>><RectilinearGrid WholeExtent="1 8 1 4 1 16">
>>>>>>>><Piece Extent="1 8 1 4 1 16">
>>>>>>>>  <PointData>
>>>>>>>>    <DataArray type="Float32" Name="pressure" format="appended"
>>>>>>>>offset="0"           />
>>>>>>>>  </PointData>
>>>>>>>>  <CellData>
>>>>>>>>  </CellData>
>>>>>>>>  <Coordinates>
>>>>>>>>    <DataArray type="Float32" Name="X_COORDINATES"
>>>>>>>>format="appended" offset="956"         />
>>>>>>>>    <DataArray type="Float32" Name="Y_COORDINATES"
>>>>>>>>format="appended" offset="1036"        />
>>>>>>>>    <DataArray type="Float32" Name="Z_COORDINATES"
>>>>>>>>format="appended" offset="1092"        />
>>>>>>>>  </Coordinates>
>>>>>>>></Piece>
>>>>>>>></RectilinearGrid>
>>>>>>>><AppendedData encoding="base64">
>>>>>>>>_AQAAAACAAAAACAAAuQIAAA==eJwVy8fvoFMUx+HDdIkyWOiG/0Bvmzfm   etc.....
>>>>>>>></AppendedData>
>>>>>>>></VTKFile>
>>>>>>
>>>>>>>>My knowledge are only reduces to Fluid mechanics.
>>>>>>
>>>>>>
>>>>>>>>>>>>>>>>>>>>>Encode in Base 64 ? More details please...How to ?
>>>>>>
>>>>>>>><<<<<<<<<<<<<<<<<<<<<<
>>>>>>
>>>>>>>>Link properly to vtkIO ? More details please.
>>>>>>
>>>>>>>>>>>>>>>>>>>>>>Does it mean that VTK IO library should be installed on
>>>>>>
>>>>>>>>the Computer where my CFD code run ?.
>>>>>>>>I don't run my code on my own computer. It runs in Computing center
>>>>>>>>where I can't install what I want.
>>>>>>
>>>>>>>>>>>>>>>>So I would like to obtain some fortran routine I could link
>>>>>>
>>>>>>>>myself  to my  CFD code  <<<<<<<<<<<<<<<<
>>>>>>
>>>>>>>>When I try  to write binary data in a formatted file:
>>>>>>>>run-time error F6204: WRITE(pressure.vtr)
>>>>>>>>- unformatted I/O not consistent with OPEN options
>>>>>>
>>>>>>>>When I try  to write formatted string in an unformatted file:
>>>>>>>>run-time error F6200: WRITE(pressure.vtr)
>>>>>>>>- formatted I/O not consistent with OPEN options
>>>>>>
>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>How to convert my data to a string ?
>>>>>>
>>>>>>>><<<<<<<<<<<<<<<<<<<<<
>>>>>>
>>>>>>
>>>>>>>>The format for raw appended binary data should be
>>>>>>
>>>>>>>><AppendedData encoding="raw">
>>>>>>>>_NNNN...........................
>>>>>>>></AppendedData>
>>>>>>
>>>>>>>>Where the underscore is literal (as you already have) and the NNNN is a
>>>>>>>>four-byte block containing an unsigned 32-bit count of the number of
>>>>>>>>"words" in the array.  A word is one value of the type of the array, so
>>>>>>>>in your case the NNNN would have the number of float values.  Then the
>>>>>>>>number of bytes of binary data to follow should be NNNN*sizeof(float).
>>>>>>
>>>>>>>>If you have another appended data array in the same file then start it
>>>>>>>>immediately after the end of the first array (with no newline or any
>>>>>>>>other character.  Then specify in the offset="..." attribute for the
>>>>>>>>corresponding DataArray the number of bytes beyond the underscore where
>>>>>>>>the second array begins.
>>>>>>
>>>>>>>>-Brad
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>>Thierry Dubuis wrote:
>>>>>>
>>>>>>
>>>>>>>>>Hello Stéphane,
>>>>>>>>>
>>>>>>>>>perhaps this email can help you ?
>>>>>>>>>
>>>>>>>>>Else if you want code directly your program in fortran :
>>>>>>>>>1. You must encode all you data in Base64
>>>>>>>>>2. And write them like a string.
>>>>>>>>>3. don't forget to add the size of your data block (integer*4)
>>>>>>>>>encoded in base64 before you block.
>>>>>>>>>
>>>>>>>>>Best regards,
>>>>>>>>>Thierry Dubuis
>>>>>>>>>
>>>>>>>>>-------- Original Message --------
>>>>>>>>>Subject:     Re: [Paraview] Writing binary files: C/Fortran interface
>>>>>>>>>to VTK XML files.
>>>>>>>>>Date:     Tue, 07 Jun 2005 10:06:51 -0400
>>>>>>>>>From:     Brad King <brad.king at kitware.com>
>>>>>>>>>To:     SamuelKey <samuelkey at comcast.net>
>>>>>>>>>CC:     paraview <paraview at paraview.org>, "Wylie, Brian"
>>>>>>>>><bnwylie at sandia.gov>
>>>>>>>>>References:
>>>>>>>>><200506030152.j531quWp005650 at rrcs-mta-04.hrndva.rr.com>
>>>>>>>>><42A05837.3010206 at kitware.com> <000a01c5684c$1d1a6740$6e01a8c0 at last>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>SamuelKey wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>Needing to have a C-compiler is not a problem for me; I have one.
>>>>>>>>>>
>>>>>>>>>>Let me try to work with what you commit next week and see if I have
>>>>>>>>>>any ideas. I will be gone all next week, so you won't hear from me
>>>>>>>>>>until week after next. With luck you may hear from someone else
>>>>>>>>>>that will help keep you busy, though I suspect "busy" is not a
>>>>>>>>>>problem for you.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>Okay, the C/Fortran interface is now available.  A C program can do
>>>>>>>>>
>>>>>>>>>#include "vtkXMLWriterC.h"
>>>>>>>>>
>>>>>>>>>and link to vtkIO.  A Fortran program can use the interface (see the
>>>>>>>>>example code below) but will need to compile one extra .c file to
>>>>>>>>>link properly to vtkIO.  See VTK/IO/vtkXMLWriterF.h for instructions.
>>>>>>>>>
>>>>>>>>>-Brad
>>>>>>>>>
>>>>>>>>>  PROGRAM Hello
>>>>>>>>>  INTEGER writer
>>>>>>>>>  INTEGER success
>>>>>>>>>  INTEGER*8 numpoints/8/
>>>>>>>>>  INTEGER*8 numcells/1/
>>>>>>>>>  INTEGER*8 cellsSize/9/
>>>>>>>>>  REAL*4 pdata(8)/0,0,0,0,1,1,1,1/
>>>>>>>>>  REAL*4 points(24)/0,0,0, 1,0,0, 1,1,0, 0,1,0,
>>>>>>>>> _                  0,0,1, 1,0,1, 1,1,1, 0,1,1/
>>>>>>>>>  INTEGER*8 cells(9)/8,0,1,2,3,4,5,6,7/
>>>>>>>>>  call vtkXMLWriterF_New(writer)
>>>>>>>>>  call vtkXMLWriterF_SetDataObjectType(writer, 4)
>>>>>>>>>  call vtkXMLWriterF_SetFileName(writer, 'test1.vtu')
>>>>>>>>>  call vtkXMLWriterF_SetPoints(writer, 10, points, numpoints)
>>>>>>>>>  call vtkXMLWriterF_SetCellsWithType(writer, 12, numcells, cells,
>>>>>>>>> _                                    cellsSize)
>>>>>>>>>  call vtkXMLWriterF_SetPointData(writer, 'example data', 10, pdata,
>>>>>>>>> _                                numpoints, 1, 'SCALARS')
>>>>>>>>>  call vtkXMLWriterF_Write(writer, success)
>>>>>>>>>  call vtkXMLWriterF_Delete(writer)
>>>>>>>>>  PRINT *, 'success =', success
>>>>>>>>>  END PROGRAM Hello
>>>>>>>>>_______________________________________________
>>>>>>>>>ParaView mailing list
>>>>>>>>>ParaView at paraview.org
>>>>>>>>>http://www.paraview.org/mailman/listinfo/paraview
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>Stéphane Montésino wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>With Asci, all is OK except the size of my file.
>>>>>>>>>>So how to write my data array in binary with my fortran code.
>>>>>>>>>>Does anyone have some details ?
>>>>>>>>>>
>>>>>>>>>>!
>>>>>>>>>>******************************************************************************
>>>>>>>>>>
>>>>>>>>>>!    ****                       subrout
>>>>>>>>>>paraview_scalar                        ****
>>>>>>>>>>!
>>>>>>>>>>******************************************************************************
>>>>>>>>>>
>>>>>>>>>>!    Export 3D scalar data upon a Non uniform rectilinear Grid
>>>>>>>>>>!
>>>>>>>>>>!    n1m,n2m,n3m: size of the data and the grid
>>>>>>>>>>!    y1,y2,y3: coordinates
>>>>>>>>>>!    scal_data: data to write
>>>>>>>>>>!    name: name of the data
>>>>>>>>>>!
>>>>>>>>>>  subroutine paraview_3d_scalar(n1m,n2m,n3m,y1,y2,y3,scal_data,name)
>>>>>>>>>>!
>>>>>>>>>>  implicit none
>>>>>>>>>>!
>>>>>>>>>>  INTEGER                      ,INTENT(IN)::n1m,n2m,n3m
>>>>>>>>>>  REAL*8,DIMENSION(n1m)        ,INTENT(IN)::y1
>>>>>>>>>>  REAL*8,DIMENSION(n2m)        ,INTENT(IN)::y2
>>>>>>>>>>  REAL*8,DIMENSION(n3m)        ,INTENT(IN)::y3
>>>>>>>>>>  REAL*8,DIMENSION(n1m,n2m,n3m),INTENT(IN)::scal_data
>>>>>>>>>>  CHARACTER(LEN=10)            ,INTENT(IN)::name
>>>>>>>>>>!
>>>>>>>>>>  integer::i,j,k,nfil
>>>>>>>>>>!
>>>>>>>>>>  nfil=41
>>>>>>>>>>  open(nfil,file=trim(name)//'.vtr')
>>>>>>>>>>  write(nfil,*)'<VTKFile type="RectilinearGrid" version="0.1"',
>>>>>>>>>> &         ' byte_order="LittleEndian">'
>>>>>>>>>>  write(nfil,*)'  <RectilinearGrid WholeExtent=',
>>>>>>>>>> &                '"1 ',n1m,' 1 ',n2m,' 1 ',n3m,'">'
>>>>>>>>>>  write(nfil,*)'    <Piece Extent=',
>>>>>>>>>> &                  '"1 ',n1m,' 1 ',n2m,' 1 ',n3m,'">'
>>>>>>>>>>  write(nfil,*)'      <Coordinates>'
>>>>>>>>>>  write(nfil,*)'        <DataArray type="Float32"',
>>>>>>>>>> &                             ' Name="X_COORDINATES"',
>>>>>>>>>> &                             ' NumberOfComponents="1">'
>>>>>>>>>>  write(nfil,*) (y1(i),i=1,n1m)
>>>>>>>>>>  write(nfil,*)'        </DataArray>'
>>>>>>>>>>  write(nfil,*)'        <DataArray type="Float32"',
>>>>>>>>>> &                             ' Name="Y_COORDINATES"',
>>>>>>>>>> &                             ' NumberOfComponents="1">'
>>>>>>>>>>  write(nfil,*) (y2(j),j=1,n2m)
>>>>>>>>>>  write(nfil,*)'        </DataArray>'
>>>>>>>>>>  write(nfil,*)'        <DataArray type="Float32"',
>>>>>>>>>> &                             ' Name="Z_COORDINATES"',
>>>>>>>>>> &                             ' NumberOfComponents="1">'
>>>>>>>>>>  write(nfil,*) (y3(k),k=1,n3m)
>>>>>>>>>>  write(nfil,*)'        </DataArray>'
>>>>>>>>>>  write(nfil,*)'      </Coordinates>'
>>>>>>>>>>  write(nfil,*)'      <PointData Scalars="scalar">'
>>>>>>>>>>  write(nfil,*)'        <DataArray Name="'//trim(name)//'"',
>>>>>>>>>> &                             ' type="Float32"',
>>>>>>>>>> &                             ' NumberOfComponents="1"',
>>>>>>>>>> &                             ' format="ascii">'
>>>>>>>>>>  write(nfil,*) (((scal_data(i,j,k),i=1,n1m),j=1,n2m),k=1,n3m)
>>>>>>>>>>  write(nfil,*)'        </DataArray>'
>>>>>>>>>>  write(nfil,*)'      </PointData>'
>>>>>>>>>>  write(nfil,*)'    </Piece>'
>>>>>>>>>>  write(nfil,*)'  </RectilinearGrid>'
>>>>>>>>>>  write(nfil,*)'</VTKFile>'
>>>>>>>>>>  close(nfil)
>>>>>>>>>>!
>>>>>>>>>>  return
>>>>>>>>>>  end
>>>>>>>>>>
>>>>>>>>>>_______________________________________________
>>>>>>>>>>ParaView mailing list
>>>>>>>>>>ParaView at paraview.org
>>>>>>>>>>http://www.paraview.org/mailman/listinfo/paraview
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>--
>>>>>>Dominik Szczerba, Dr.
>>>>>>Computer Vision Lab CH-8092 Zurich
>>>>>>http://www.vision.ee.ethz.ch/~domi
>>>>>
>>>>>_______________________________________________
>>>>>ParaView mailing list
>>>>>ParaView at paraview.org
>>>>>http://www.paraview.org/mailman/listinfo/paraview
>>>>>
>>>>>--
>>>>>Dominik Szczerba, Dr.
>>>>>Computer Vision Lab CH-8092 Zurich
>>>>>http://www.vision.ee.ethz.ch/~domi
>>>>>_______________________________________________
>>>>>ParaView mailing list
>>>>>ParaView at paraview.org
>>>>>http://www.paraview.org/mailman/listinfo/paraview
>>>>>
>>>
>>>
>>--
>>Dominik Szczerba, Dr.
>>Computer Vision Lab CH-8092 Zurich
>>http://www.vision.ee.ethz.ch/~domi
>>_______________________________________________
>>ParaView mailing list
>>ParaView at paraview.org
>>http://www.paraview.org/mailman/listinfo/paraview
>>

-- 
Dominik Szczerba, Dr.
Computer Vision Lab CH-8092 Zurich
http://www.vision.ee.ethz.ch/~domi


More information about the ParaView mailing list