RES: [Paraview] VTK formats and Fortran (again...)

Benjamin Ahrenholz ahrenholz at cab.bau.tu-bs.de
Thu Apr 26 11:21:48 EDT 2007


Hello,

I ran into similar problems as Renato and had a look into the Fortran source
code he provided in an earlier post. After reading through the documentation
and lots of posts on the mailing list I came up with the following solution
(actually because of that post:
http://public.kitware.com/pipermail/paraview/2006-October/004031.html)

subroutine writeXMLScalars(P, FileName, pfeld)
    use types
    
    implicit none

    type(parameter_store), intent(in)  :: P    
    character(len=charlen), intent(in) :: FileName
    real(sp), intent(in) :: pfeld(P%x_anf_loc-P%gn:P%x_end_loc+P%gn,
P%y_anf_loc-P%gn:P%y_end_loc+P%gn, P%z_anf_loc-P%gn:P%z_end_loc+P%gn)

    character(len=80) :: cbuffer
    character         :: lf
    integer           :: FileUnit, i, j, k, laenge

    FileUnit = 40
    lf = char(10) ! line feed character
    laenge = 27000
    
    open (unit=FileUnit, file=trim(FileName), err=99, form='binary')
      cbuffer = '<?xml version="1.0"?>'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '<VTKFile type="ImageData" version="0.1"
byte_order="LittleEndian">'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '  <ImageData WholeExtent="0 29 0 29 0 29" Origin="1 1 1"
Spacing="1 1 1">'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '    <Piece Extent="0 29 0 29 0 29">'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '      <PointData Scalars="Scalars">'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '        <DataArray type="Float32" Name="values"
format="appended" offset="4"/>'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '      </PointData>'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '      <CellData>'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '      </CellData>'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '    </Piece>'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '  </ImageData>'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '  <AppendedData encoding="raw">'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '_' ! leading char
      write(FileUnit) trim(cbuffer)
      write(FileUnit) laenge ! length of the array
      write(FileUnit) ((( pfeld(i,j,k), i=P%x_anf_loc,P%x_end_loc), &
                                      & j=P%y_anf_loc,P%y_end_loc), &
                                      & k=P%z_anf_loc,P%z_end_loc)      
      cbuffer = '  </AppendedData>'//lf
      write(FileUnit) trim(cbuffer)
      cbuffer = '</VTKFile>'//lf
      write(FileUnit) trim(cbuffer)
    close(FileUnit)

    return
    
    99  write(messg,'(a,a)') 'Oeffnen oder Schreiben der Scalar-Dump-Datei
misslungen! '
    call aerror(messg)
  
end subroutine writeXMLScalars

In that version above most values are hardcoded, however there are three
things you have to take care of:
- use the AppendedData option, because only there you have the option of raw
encoding (a.f.a.i.k.)
- you have to use _ (underscore) as leading character fort he binary data
- and, as Kent stated, you have to put the length of the array in front of
it. However, than you have to put the offset attribute to 4 (in my case)
Now it should work (tested with ParaView 2.6.0). I hope that helps, if you
still had that problem.

Cheers,

Ben
__________________________________

Institute for Computerapplications
in Civil Engineering (CAB)
Technical University of
Braunschweig
 
Pockelsstr. 3 (9th Floor)
Braunschweig
D-38106, Germany
 
phone +49 531/391-7584
fax   +49 531/391-7599
web   www.cab.bau.tu-bs.de
__________________________________


First of all I'd like to thank Fred, Kent and Bruno for the help...

I've finally got something working here... Fortran, Binary and VTK
(unfortunately only the Legacy format...)

I left a very simple Fortran90 program available in
http://www.nacad.ufrj.br/~rnelias/paraview/VTKFormat.f90 . Please, if you
find what's wrong with the XML version contact me.

Now, I have another very silly doubt regarding the Legacy format:

-- What is a "partitioned VTK Legacy" file? Would it be a simple VTK Legacy
file with *.pvtk extension?! 

BTW, I can't understand why there is a bunch of different file extensions
for those XML/VTK based files... if they are all XML files why they should
be distinguished by their extension and not by a simple XML tag?!
 
Regards

Renato N. Elias
===============================================
PhD student - http://www.nacad.ufrj.br/~rnelias
High Performance Computing Center (NACAD)
Federal University of Rio de Janeiro (UFRJ)
Rio de Janeiro, Brazil 


 
-----Mensagem original-----
De: paraview-bounces+rnelias=nacad.ufrj.br at paraview.org
[mailto:paraview-bounces+rnelias=nacad.ufrj.br at paraview.org] Em nome de fred
Enviada em: Friday, April 13, 2007 07:55
Para: vtkusers at vtk.org
Cc: paraview at paraview.org
Assunto: Re: RES: [Paraview] VTK formats and Fortran (again...)

Renato N. Elias a écrit :
> Fred wrote: You also have ASCII and binary (not base64) formats.
>
> I've reread and found this information hidden in the VTK file format's
> guide. A footnote in page 12 which says:
>
> "* There is one case in which the file is not a valid XML document. ***
When
> the AppendedData section is not encoded as base64,
> raw binary data *** is present that may violate the XML specification.
This
> is not default behavior, and must be explicitly enabled
> by the user."
>
>   
Yes, I know this, but not a problem for me.
By the way, XML base64 files size are little bigger than binary.
> However, there is no further information regarding such form of writing
raw
> binary data in "XML files" for VTK and PV. I'll try to write a file with
raw
> binary data in the AppendedData section to see what happen.
>   
I began to write my C code to write legacy VTK files, which does not 
require any VTK libs.
Then, I added a few routines, which do use VTK libs, to write my files 
in XML.
But once again, only in C.
But if it can help...

-- 
/F

_______________________________________________
ParaView mailing list
ParaView at paraview.org
http://www.paraview.org/mailman/listinfo/paraview

_______________________________________________
ParaView mailing list
ParaView at paraview.org
http://www.paraview.org/mailman/listinfo/paraview



More information about the ParaView mailing list