[vtkusers] RES: RES: RES: [Paraview] VTK formats and Fortran (again...)
Renato N. Elias
rnelias at nacad.ufrj.br
Fri Apr 27 19:33:45 EDT 2007
Thanks a lot Kent for unveiling me some of the VTK's mysteries, your text
was very clarifying...
(it surely must be written somewhere in VTK's books).
I left the last piece of code available in
http://www.nacad.ufrj.br/~rnelias/paraview/VTKFormats.f90
I hope it can be useful for other Fortran programmers willing to write
binary VTK files (legacy or XML) without having to use C/C++ code.
[]'s
Renato.
Ps: Now I proved myself that Fortran (at least Fortran90/95/03) is able to
write a raw binary XML/VTK format ;o)
-----Mensagem original-----
De: Kent Eschenberg [mailto:eschenbe at psc.edu]
Enviada em: Friday, April 27, 2007 08:59
Para: Renato N. Elias; ParaView
Assunto: Re: RES: RES: [Paraview] VTK formats and Fortran (again...)
Some quick answers:
Renato N. Elias wrote:
> I'm now trying to fix my Fortran routine to write a simple triangle as
> unstructured data following your suggestions, but I still have some
doubts:
>
> - Silly question number 1: What is such offset in VTK/XML files?
The offset for appended raw binary data is the number of bytes beyond the
underscore ("_") at the start of the binary section. For example, the offset
for the first binary array is always 0.
Each binary array must start with a 4-byte integer that is the length or
number
of bytes in the array that immediately follows. You must take into account
whether the array is, for example, 16-bit shorts or 32-bit integers. The
number
of bytes does not include the length itself. For example, the length for
10000
32-bit floats is 40000.
The offset for the second and later arrays must include the lengths. For
example, if the first binary array is 10000 32-bit floats then the offset
for
the second array will be 40004.
These offsets are completely different than the offsets used with
unstructured
data.
> 2). In the AppendedData section must I put all arrays (raw binary)
> contiguously or can I call Fortran "write" statements more than once?
I haven't tried this but I think you can leave gaps between arrays - it
merely
wastes space. The VTK code that reads this does a "seek" using the provided
offset so would not care if there was extra space. Two things to check:
1) How much is actually written to the file? You'll need to know this to
calculate the offset for the following array. For example, lets say the
first
array is 10000 32-bit floats plus the 32-bit length. And, lets say it is
padded
to a multiple of 512 bytes. It will occupy 79 512-byte chunks or 40448
bytes.
The offset to the second array will therefore be 40448.
2) Be sure Fortran adds no padding before the binary data. Some add an extra
byte; others will add an extra 512-byte section.
Warning: although I've created this type of VTK file from C I haven't done
so
from Fortran. Hopefully those with relevant experience will point out my
errors.
Kent
Pittsburgh Supercomputing Center
More information about the vtkusers
mailing list