[Paraview] Re: write a binary xml file

Kent Eschenberg eschenbe at psc.edu
Tue Dec 18 14:37:32 EST 2007


Two additional hints.

Set the "byte_order" to BigEndian if the machine writing the file is big endian.

The offset to an array in the appended binary area must be the size of previous 
appended arrays AND that 4-byte integer in front of each appended array. 
Example: if the first array is 10,000 bytes the offset to the second is 10,004.

Kent
Pittsburgh Supercomputing Center

Adrian Croucher wrote:
> hi Renato
>> I'm new to this newsletter and to paraview, I'm trying to write a 
>> fortran subroutine to write a xml file with binary data (vtu file), if 
>> I use ASCII data everything is ok, but I don't know how to write 
>> "headers" in binary files.
>>   
> I've done this.  What I did was:
> 
> - open the xml file as a binary file:
> open(unit=vtu,file=vtufile,status='replace',form='binary')
> 
> - write the file headers, e.g.:
> write(vtu) '<?xml version="1.0"?>',lf
> write(vtu) '<VTKFile type="UnstructuredGrid" version="0.1" 
> byte_order="LittleEndian">',lf   write(vtu) '  <UnstructuredGrid>',lf
> 
> etc., where lf=char(10) (line feed).
> 
> You can write the rest of the main part of the file in a similar way 
> (except when referring to the appended data- see below).
> 
> - write the data out in raw binary at the end of the file:
> 
> <AppendedData encoding="raw">
> 
> then write an underscore character ('_') at the start of the data.  For 
> each data array, write the size of the array in bytes at the start (as a 
> 4-byte integer), then the data itself, making sure the variables have 
> the correct types to match what you have specified in the main part of 
> the file (e.g. if you have specified '<DataArray type="Float32"' then 
> the variable you write out to the appended data must be a 4-byte real.)  
> Write '</AppendedData>' at the end, just before '</VTKFile>'.
> 
> - when you refer to data arrays in the main part of the file, use 
> 'format="appended"' and specify the offset in bytes to the relevant 
> piece of appended data.  For example for the first data array you can 
> say 'format="appended" offset="0"' because it's at the start of the 
> appended data.
> 
> Hope this helps.  Using raw binary encoding, as I have done, means the 
> files probably aren't very platform-independent or strictly valid xml.  
> It would be better to use Base64 encoding or similar, but I couldn't 
> figure out how to do that easily.
> 
> Regards, Adrian


More information about the ParaView mailing list