Вы находитесь на странице: 1из 76

LIB VTK IO

vtk input/output fortran library


Version 0.2

stefano zaghi

enrico cavallini and renato n. elias

07-01-2008

acknowledgements

I am very grateful to Renato N. Elias: whitout his support lib vtk io would not born. As a matter of facts lib vtk io is a collection of his tips. Despite the fact that Renato does not write the code he is a moral co-author of the code. I thank Enrico Cavallini for his help in debugging the code. He also develop the MS Windows version of lib vtk io and he is the rst co-author that I found. Finally I thank the ParaView mailing list for the great support of its members.

ii

introduction

I have not failed. Ive just found ten thousand ways that dont work. Thomas Edison

is a Fortran (actually only write) data conforming LIB VTK IOstandard bothlibrary to write and readthough there aretomany wrappers/porting the VTK binary and ascii. Even of the VTK source code (C++ code), there is not a fortran one. This library is not a porting or a wrapper of the VTK code, but it only an exporter/importer of the VTK data format written in pure fortran language (standard Fortran 95 with some extensions of non standard Fortran 2003) that can be used by fortran coders (yes, there are still a lot of these brave coders...) without mixing fortran with C++ language. The library is still in developing and testing, this is rst usable release, but there are not all the features of the stable release (the importer is totaly absent and the exporter is not complete). Surely there are a lot of bugs and the progamming style is not the best, but the exporter is usable for the 90% of the VTK data format. The lib vtk io is an open source project, it is distribuited under the GPL v3 (see appendix E). Anyone is interest to use, to develop or contribuite to lib vtk io is welcome.

vtk standard
VTK, Visualization Toolkit, is an open source software that provides a powerful framework for the computer grach, for the images processing and for 3D rendering. It is widely used in the world and so it has a very large comunity of users; besides the Kitware1 company provides professional support. The toolkit is written in C++ and a lot of porting/wrappers for Tcl/Tk, Java and Python are provided; unlucky there arent wrappers for Fortran. Because of its good features the VTK toolkit has been used to develop a large set of open source programs. For my work the most important family of programs is the scientic visualization programs. A lot of high-quality scientic visualization tool are available on the web but for me the best is ParaView: I think that it is one of the best scintic visualization program in the world and it is open source! Paraview is based on VTK.
1 The Kitware homepage can be found here: http://public.kitware.com.

iii

paraview
ParaView2 is an open source software voted to scientic visualization and able to use the power of parallel architectures. It has an architecture client-server in order to make easy the remote visualization of very large set of data. Because it is based on VTK it inherits all VTK features. ParaView is very useful for Computational Fluid Dynamics visualizations because it provides powerful post-processing tools; it provides a very large set of importers for the most used format like Plot3D and HDF (the list is very large). It is easy to extend ParaView because it supports all the scripting language supported by VTK.

lib vtk io
Even though the VTK toolkit is written in C++ and so it is possible to use it in mixed fortran/c++ code this is not the easiest way. Fortran is still the best language for high performance computing for scientic purpose, like CFD computing. It necessary a tool to deal with VTK standard directly by fortran code. The library lib vtk io was made to ll this empty: it is a simple fortran module able to export native fortran data into VTK data format and to import VTK data into a fortran code (actually this feature is missing), both in ascii and binary le format. The library provides an automatic way to deal with VTK data format: all the formatting processes is nested into the library and the users comunicate with it by a simple API passing only native fortran data (native fortran scalar, vector and matrix). The library lib vtk io is distribuited under the GNU GPL v3 license (see appendix E). Beyond to the source code there are some precompiled binaries for GNU-Linux (amd x86, amd x86 64, intel x86, intel x86 64) and WindowsXP (amd x86, intel x86). Actually the library is still in developing/testing phase (a lot of features are missing); this is not a stable release, but the exporter is quite complete and its API is quite stable. The exporter is usable and I use it for my work.

2 The ParaView homepage can be found here: http://www.paraview.org.

iv

news and changes

version v0.2
v0.2 is release. version there are only minor The versionthis newthe second testing introduce From features v0.1 does not x bugs: it changes; version does not new and is a simple code-cleaning. The character variables are now case-insensitive; the names of some variables have been changed. The comments have been translated in English (very poor translation...).
List of changes from v0.1

1. variable formato is changed in output format and now appears only in VTK INI and in VTK INI XML. 2. variable nomele is changed in lename. 3. variable titolo is changed in title. 4. variable topologia is changed in mesh topology and now appears only in VTK INI and in VTK INI XML. 5. variable NCelle is changed in NC. 6. variable Nnodi is changed in NN. 7. variable tipo in VTK CON and VTK CON XML is changed in cell type. 8. variable tipo in VTK DAT and VTK DAT XML is changed in var location. 9. variable azione in VTK DAT XML is changed in var block action. 10. variable tipo in VTK VAR is changed in vec type. 11. variable nomevar is changed in varname.

The only relevant news in the v0.2 version is about this guide: now the guide is integrated in the code. The code has particular comments: if the code is processed by the program

FortranDOC3 a latex source of this guide will be made; compiling the latex le with pdatex you will obtain this guide in PDF.

version v0.1

The version v0.1 is the rst testing release. There are not news and changes.

3 FortranDOC is an open-source fortran code available at: http://www.paraview.org. This code processing free-format fortran code generates a pretty-latex documentation le of the code structure.

vi

contents
Acknowledgements Introduction iii v ii

News and Changes

I
1

Compile and Install LIB VTK IO


2 Compile LIB VTK IO 1.1 Compile under GNU/Linux 1.2 Compile under MS Windows 3 3 4

Install and Link (Pre)Compiled LIB VTK IO 2.1 GNU/Linux 4 2.1.1 Static Library 4 2.1.2 Dynamic Library 5 2.2 MS Windows 6 LIB VTK IO Programming Style 7

II
4 5

LIB VTK IO API


Module LIB VTK IO 10

Auxiliary functions 13 5.1 Function GetUnit 13 5.2 Function Upper Case 14 VTK LEGACY functions 16 6.1 Function VTK INI 16 6.2 VTK GEO 17 6.2.1 VTK GEO STRUCTURED POINTS 18 19 6.2.2 VTK GEO STRUCTURED GRID 6.2.3 VTK GEO RECTILINEAR GRID 20 21 6.2.4 VTK GEO UNSTRUCTURED GRID

vii

Contents

6.3 6.4 6.5

6.6 7

Function VTK CON 22 Function VTK DAT 24 25 VTK VAR 6.5.1 VTK VAR SCALAR DATA 25 26 6.5.2 VTK VAR REAL VECTORIAL DATA 6.5.3 VTK VAR INTEGER VECTORIAL DATA 27 6.5.4 VTK VAR TEXTURE DATA 28 Function VTK END 29

VTK XML functions 31 7.1 Function VTK INI XML 32 7.2 VTK GEO XML 33 7.2.1 VTK GEO XML STRUCTURED GRID 33 7.2.2 VTK GEO XML RECTILINEAR GRID 34 36 7.2.3 VTK GEO XML UNSTRUCTURED GRID 7.2.4 VTK GEO XML CLOSE PIECE 37 7.3 Function VTK CON XML 37 7.4 Function VTK DAT XML 40 7.5 VTK VAR XML 41 7.5.1 VTK VAR XML SCALAR DATA 41 7.5.2 VTK VAR XML VECTORIAL DATA 42 43 7.6 Function VTK END XML VTK IO Usage Example 44 Legacy Rectilinear Grid 44 XML Rectilinear Grid 45 Legacy Unstructured Grid 46 XML Unstructured Grid 49 52

a LIB a.1 a.2 a.3 a.4 b

Fortran & Portable-Kind-Precision Selection 54

c Dynamic Dispatching d Known Bugs e 56

GNU GENERAL PUBLIC LICENSE

57

viii

Part I COMPILE AND INSTALL LIB VTK IO

1
compile lib vtk io
Contents
1.1 1.2 Compile under GNU/Linux Compile under MS Windows 3 3

The lib vtk io is open source and so anyone is encouraged to use the source code and to patch it.
The code is written in Fortran: the standard adopted is the Fortran 95 standard that is a minor upgrade to the Fortran 90 standard and that is widely supported by the almost all compilers actually available. Unluckily Fortran 95 does not allow the creation of C-binary le (Fortran inserts some bytes before and after each records despite the C standard) that is the standard adopted by VTK. Therefore in order to create binary les that are compatible whit VTK standard the only way is to use a non-standard 95 instructions. At today only Fortran 2003 can create C-binary le, but there are not any compilers that completely implement this standard. In the next year (2008) maybe a new minor upgrade of Fortran standard (unofcial named Fortran 2008) will be born and so the support to Fortran 2003/2008 probably will be improved. Luckily we need to use only some features of fortran 2003 that are supported by many compilers. The Fortran 2003 instructions are focused on the opening of the binary le, in particular in the functions vtk ini and vtk ini xml. In these functions there are opening instructions like the following: open(unit file form access action convert = = = = = = ..., ..., ..., ..., ..., BIG_ENDIAN, & & & & & &
Fortran 2003 instructions

1.1 compile under gnu/linux

recordtype = STREAM, buffered = YES, iostat = ...)

& &

The speciers convert, recordtype and buffered are non standard for Fortran 95. The buffered specier is not necessary and so can be commented or eliminated. The speciers convert and recordtype are instead necessary to write binary le but can be replaced by other speciers/instructions. In particular an alternative is opening the le with the specier form = binary 1 and using a compilers option2 to ensure the big endian encoding. big endian encoding is strictly necessary only for legacy binary le; for XML binary le one can choice also the little endian and so the conversion is not necessary. Actually there is also another instruction that is non-standard for Fortran 95: the instruction sizeof. This instruction is used to comptuing the number of bytes of the saved data in the XML binary les. Maybe there are others alternatives that are Fortran 95 compatible but at the moment I have not the time to implement them. Before you compile lib vtk io ensure that your compiler allows these Fortran 2003 extensions. I use the Intel Fortran Compiler3 that is free for non-commercial use and it has a strong support for Fortran 2003.

1.1 compile under gnu/linux


lib vtk io can be compiled as a stand-alone library or it can be integrated directly in your code. It is a self-contained module that can be safely included into others fortran codes. There are no any advices for compile lib vtk io excluding the above non standard instructions. For the GNU/Linux users there is available a makele already set to compile lib vtk io both as static and dynamic library with Intel Fortran. The makele has only one option: shared. This variable (default set to no) can assume two values: 1. no: makele creates a static library 2. yes: makele creates a dynamic library

1.2 compile under ms windows


For MS Windows users there is not any support at the moment. As soon as I have the time I will make available a MS Visual Studio Project to compile lib vtk io with Intel Visual Fortran for Windows.

1 Remember that also the value binary for form specier is non standard for Fortran 95. 2 Each compilers adopt differents option to achieve conversion of bytes order (if it allows conversion). See the user guide of your compiler. Intel Fortran allows the conversion both by open specier and by compiling option. 3 http://www.intel.com.

2
install and link (pre)compiled lib vtk io
Contents
2.1 GNU/Linux 2.1.1 2.1.2 2.2 4 4 5 Static Library Dynamic Library 6

MS Windows

io is (other code): The lib vtklinkingdistribuited in two different versionand thethan sourcedynamicthe rst is a static version (extensions are .a and .lib) second is linking version (extensions are .so and .dll). The use of these two version is different and it depends on the OS used. The library is been tested only on GNU/Linux (several different distro) and on MS Windows (Windows XP). The library is distribuited with two different archive: lib vtk io-bin-x.x.tar for GNU/Linux systems and lib vtk io-bin-x.x.zip for MS Windows systems. Into the archives there is the source code of the library (lib vtk io.f90), there are both static and dynamic version of the librabry and there is also this guide (lib vtk io guide.pdf).

2.1 gnu/linux
2.1.1 static library
The static version of the precompiled library (lib vtk io.a) does not require any kind of installations. It is enough to link against it in the linking phase. It is important to use the interface module lib vtk io.mod distribuited with the library: this is the interface of the subroutines and functions that constitute the library.

2.1 gnu/linux

To use the functions and subroutines of the library it is mandatory to use the module. Suppose one has a program (or subprogram) named test that use the library; the correct use is: program test USE LIB_VTK_IO ... ... ... endprogram test
The lib vtk io must to be loaded with the USE statement

With the instruction USE LIB\_VTK\_IO the program test can use the functions and subroutines of the library. To compile, without link, this code one must give the module interface lib vtk io.mod to the compiler: ifort -c lib_vtk_io.mod test.f90 -o test.o
Static Compiling Phase

In this example ifort is the Intel Fortran Compiler1 and the -c ag compiles preventing linking; the compiler must see the module interface: the le lib vtk io.mod must be placed in a folder visible by the compiler. In the linking phase one simply give the library to the compiler:
Static Linking Phase

ifort test.o LIB_VTK_IO.a -o test.out

The library must be placed in a folder visible by the compiler.

2.1.2 dynamic library


The dynamic version of the precompiled library must be installed. The operating system must know where is the library so it is necessary to install the library in a folder where the OS search its shared objects. In the most of the GNU/Linux distro the folder /usr/lib/ is scanned to nd shared objects. After you have copied the lib vtk io.so le in this folder, update the list of the shared objects with the command ldconfig -v and the OS is ready to use the library. After you set your OS the compiling and linking phase is identical to the previous (remember to you the module interface at the compiling phase). The only difference is to use the dynamic library at the linking phase: ifort test.o LIB_VTK_IO.so -o test.out
Dynamic Linking Phase

1 Da aggiungere.

2.2 ms windows

2.2 ms windows
Unluckily for MS Windows there is not any support at the moment. As soon as I have the time, I make some instructions on how use lib vtk io with MS Visual Studio and Intel Visual Fortran for MS Windows.

3
lib vtk io programming style
are 4-byte integer lib All the is anvtk io functions if the function calling functions: the output of these>functions integer that is 0 has been done right while it is 0 if some errors occur (the error handling is only at its embryonal phase). Therefore the functions calling must be done in the following way:
Functions Calling

... integer(4):: E_IO ... E_IO = VTK_INI(.... ...

The lib vtk io programming style is based on two main principles: portable kindprecision of reals and integers variables and dynamic dispatching. In the appendix B and C there are more details about these choices. I just remark some consequences of these choices. Using dynamic dispatching the lib vtk io has a simple API. The user calls a generic procedure (VTK INI, VTK GEO,...) and the library, depending on the type of the inputs passed, calls the correct internal function (i.e. VTK GEO for 8-byte real type if the input passed is 8-byte real type). By this interface only few functions are used whitout the necessity of calling a different function for every different inputs type. dynamic dispatching is valid also for the different kind of topology and variables-data-dimensions; the function VTK GEO is the same for all topologies, just the inputs passed to the functions change as the topology changes. Also the dimensions of variables-data use the dynamic dispatching: the function (VTK VAR) used to save vectorial data is identical to the one used for scalar data, depending on the dimensions of the data lib vtk io calls the correct internal function. dynamic dispatching is based on the internal kind-precision selecting convention: Fortran 90/95 standard has some useful functions to achive the portability of reals and integers precision and lib vtk io uses these functions to dene portable kind-precision; because it is

important to make portable the code on different architectures I suggest to use this programming style. The data handled by lib vtk io can be classied into two main categories: 1. Geometric Data. These are the geometric informations of the mesh and they can be of different kind and different number depending on the topology choiced. The mesh points coordinates type must be of 4-byte real type or 8-byte real type. 2. Variable Data. These are the scalar or vectorial variables appended to the mesh points (both at the cell-nodes and the cell-centers of the mesh). The type of these data can be of 8-byte real type, 4-byte real type and 4-byte integer type (for the XML output there are also the 8-byte integer type, 2-byte integer type and 1-byte integer type). In the following chapters theare the details of lib vtk io API.

Part II LIB VTK IO API

4
module lib vtk io
lib vtk io is a library of functions for Input and Output pure fortran data (both ascii and binary) in VTK format. The VTK standard can be separated into two main catagories: the vtk legacy standard and the vtk xml standard. The latter is more powerful and will has a stronger support from VTk comunity than legacy standard; XML le format would to be preferred despite the legacy one. At the present only a few functions of the nal library have been implemented. The InPut functions are totaly absent, but the OutPut functions are almost complete (the polydata functions are the only missing). The functions actually present are: 1. V T K I N I 2. V T K G E O 3. V T K C O N 4. V T K D A T 5. V T K V A R 6. V T K E N D
Functions for Legacy VTK le format

1. V T K I N I X M L 2. V T K G E O X M L

Functions for XML VTK le format

10

3. V T K C O N X M L 4. V T K D A T X M L 5. V T K V A R X M L 6. V T K E N D X M L

lib vtk io has a small set of internal variables and parameters some of which have public visibility. The lib vtk io uses a partable kind parameters for real and integer variables. The following are the kind parameters used: these parameters are public and their use is strong encouraged. Real precision denitions:

lib vtk io variables


integer integer integer integer , , , , parameter parameter parameter parameter :: :: :: :: R16P R8P R4P R P = = = = s e l e c t e d r e a l k i n d (33 ,4931) s e l e c t e d r e a l k i n d (15 ,307) s e l e c t e d r e a l k i n d (6 ,37) R8P ! ! ! ! 33 digits, range [104931 , 10+4931 1] 15 digits, range [10307 , 10+307 1] 6 digits, range [1037 , 10+37 1] default real precision

Integer precision denitions:

lib vtk io variables


integer integer integer integer integer , , , , , parameter parameter parameter parameter parameter :: :: :: :: :: I8P I4P I2P I1P I P = = = = = selected selected selected selected I4P int int int int kind kind kind kind (18) (9) (4) (2) ! ! ! ! ! range [263 , +263 1] range [231 , +231 1] range [215 , +215 1] range [27 , +27 1] default integer precision

Besides the kind parameters there are also the format parameters useful for writing in a well-ascii-format numeric variables. Also these parameters are public. Real output formats:

lib vtk io variables


c h a r a c t e r ( 1 0 ) , parameter : : c h a r a c t e r ( 1 0 ) , parameter : : c h a r a c t e r ( 9 ) , parameter : : c h a r a c t e r ( 1 0 ) , parameter : : FR16P FR8P FR4P FR P = = = = '(E41 .33E4)' '(E23 .15E3)' '(E14.6E2)' '(E23 .15E3)' ! ! ! ! R16P output format R8P output format R4P output format R P output format

Integer output formats:

11

lib vtk io variables


character (5) character (5) character (4) character (4) character (5) , , , , , parameter parameter parameter parameter parameter :: :: :: :: :: FI8P FI4P FI2P FI1P FI P = = = = = '(I21)' '(I12)' '(I7)' '(I5)' '(I12)' ! ! ! ! ! I8P output format I4P output format I2P output format I1P output format I P output format

lib vtk io uses a small set of internal variables that are private (not accessible from the outside). The following are private variables:

lib vtk io variables


i n t e g e r ( I4P ) , parameter c h a r a c t e r ( 1 ) , parameter i n t e g e r ( I4P ) , parameter i n t e g e r ( I4P ) , parameter i n t e g e r ( I4P ) : : c h a r a c t e r ( len=maxlen ) : : i n t e g e r ( I4P ) : : i n t e g e r ( I4P ) : : i n t e g e r ( I4P ) : : r e a l ( R8P ) : : r e a l ( R4P ) : : i n t e g e r ( I8P ) : : i n t e g e r ( I4P ) : : i n t e g e r ( I2P ) : : i n t e g e r ( I1P ) : : i n t e g e r ( I4P ) : : i n t e g e r ( I4P ) : : : : maxlen = 500 = char (10) : : end rec :: f out ascii = 0 : : f out binary = 1 = f out ascii f out topology Unit VTK Unit VTK Append N Byte tipo R8 tipo R4 tipo I8 tipo I4 tipo I2 tipo I1 ioffset indent ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! max number of characters os static string end-character for binary-record nalize ascii-output-format parameter identier binary-output-format parameter identier current output-format (initialized to ascii format) mesh topology internal logical unit internal logical unit for raw binary XML append le number of byte to be written/read prototype of R8P real prototype of R4P real prototype of I8P integer prototype of I4P integer prototype of I2P integer prototype of I1P integer offset pointer indent pointer

In the following chapters there is the API reference of all functions of lib vtk io .

12

5
auxiliary functions
Contents
5.1 5.2 Function GetUnit 13 14 Function Upper Case

lib vtk io uses two auxiliary functions that are not connected with the VTK standard. These functions are private and so they cannot be called outside the library.

5.1 function getunit

getunit signature function GetUnit ( ) r e s u l t ( F r e e U n i t )

The GetUnit function is used for getting a free logic unit. The users of lib vtk io does not know which is the logical unit: lib vtk io handels this information without boring the users. The logical unit used is safe-free: if the program calling lib vtk io has others logical units used lib vtk io will never use these units, but will choice one that is free.

getunit variables
i n t e g e r ( I4P ) : : F r e e U n i t i n t e g e r ( I4P ) : : n1 i n t e g e r ( I4P ) : : i o s logical ( 4 ) : : lopen ! ! ! ! free logic unit counter inquiring ag inquiring ag

13

5.2 function upper case

The following is the code snippet of GetUnit function: the units 0, 5, 6, 9 and all non-free units are discarded.
GetUnit Code Snippet
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530

F r e e U n i t = 1 I 4 P ! initializing free logic unit ! initializing counter n1=1 I 4 P do i f ( ( n1/=5 I 4 P ) .AND. ( n1/=6 I 4 P ) .AND. ( n1/=9 I 4 P ) ) then i n q u i r e ( u n i t=n1 , opened= l o p e n , i o s t a t = i o s ) ! verify logic units i f ( i o s ==0 I 4 P ) then i f ( . NOT. l o p e n ) then F r e e U n i t = n1 ! assignment of free logic return endif endif endif n1=n1+1 I 4 P ! updating counter enddo return

GetUnit function is private and cannot be called outside lib vtk io . If you are interested to use it change its scope to public.

5.2 function upper case

upper case signature function Upper Case ( s t r i n g )

The Upper Case function converts the lower case characters of a string to upper case one. lib vtk io uses this function in order to achieve case-insensitive: all character variables used within lib vtk io functions are pre-processed by Uppper Case function before these variables are used. So the users can call lib vtk io functions whitout pay attention of the case of the kwywords passed to the functions: calling the function VTK INI with the string E IO = VTK INI ( 'Ascii ' , . . . ) or with the string E IO = VTK INI ( 'AscII ' , . . . ) is equivalent.

upper case variables


c h a r a c t e r ( len = * ) , i n t e n t ( IN ) : : s t r i n g ! string to be converted c h a r a c t e r ( len=len ( s t r i n g ) ) : : U p p e r C a s e ! converted string integer : : n1 ! characters counter

The following is the code snippet of Upper Case function.


Upper Case Code Snippet

14

5.2 function upper case


Upper Case = s t r i n g do n1 =1 , len ( s t r i n g ) s e l e c t c a s e ( i c h a r ( s t r i n g ( n1 : n1 ) ) ) case ( 9 7 : 1 2 2 ) U p p e r C a s e ( n1 : n1 )= c h a r ( i c h a r ( s t r i n g ( n1 : n1 )) 32) ! Upper case conversion endselect enddo return

557 558 559 560 561 562 563 564

Upper Case function is private and cannot be called outside lib vtk io . If you are interested to use it change its scope to public.

15

6
vtk legacy functions
Contents
6.1 6.2 Function VTK INI VTK GEO 6.2.1 6.2.2 6.2.3 6.2.4 6.3 6.4 6.5 17 18 19 20 21 16 VTK GEO STRUCTURED POINTS VTK GEO STRUCTURED GRID VTK GEO RECTILINEAR GRID VTK GEO UNSTRUCTURED GRID 22 24 25 26 27

Function VTK CON Function VTK DAT VTK VAR 6.5.1 6.5.2 6.5.3 6.5.4 25

VTK VAR SCALAR DATA

VTK VAR REAL VECTORIAL DATA VTK VAR TEXTURE DATA 29 28

VTK VAR INTEGER VECTORIAL DATA

6.6

Function VTK END

6.1 function vtk ini

vtk ini signature f u n c t i o n VTK INI ( o u t p u t f o r m a t , f i l e n a m e , t i t l e , m e s h t o p o l o g y ) r e s u l t ( E IO )

16

6.2 vtk geo

The VTK INI function is used for initializing le. This function must be the rst to be called.

vtk ini variables


character ( * ) , character ( * ) , character ( * ) , character ( * ) , i n t e g e r ( I4P ) : : i n t e n t ( IN ) : : o u t p u t f o r m a t i n t e n t ( IN ) : : f i l e n a m e i n t e n t ( IN ) : : t i t l e i n t e n t ( IN ) : : m e s h t o p o l o g y E IO ! ! ! ! ! output format: ASCII or BINARY name of le title mesh topology Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

The VTK INI variables have the following meaning: output format indicates the format of output le. It can assume the following values: A. ascii (it is case insensitive) creating an ascii output le. B. binary (it is case insensitive) creating a binary (big endian encoding) output le. lename contains the name (with its path) of the output le. title contains the title of the VTK dataset. topology indicates the topology of the mesh and can assume the following values: A. B. C. D. STRUCTURED POINTS. STRUCTURED GRID. UNSTRUCTURED GRID. RECTILINEAR GRID.

E IO contains the inquiring integer ag for error handling. The following is an example of VTK INI calling:
VTK INI Calling

... E_IO = VTK_INI(Binary,example.vtk,VTK legacy file,UNSTRUCTURED_GRID) ...

Note that the .vtk extension is necessary in the le name.

6.2 vtk geo


VTK GEO is an interface to 8 different functions; there are 2 functions for each 4 different topologies actually supported: one function for mesh coordinates with R8P precision and one for mesh coordinates with R4P precision. This function must be called after VTK INI. It saves the mesh geometry. The inputs that must be passed change depending on the topologies choiced. Not all VTK topologies have been implemented (polydata topologies are absent). The signatures for all implemented topologies are now reported.

17

6.2 vtk geo

6.2.1 vtk geo structured points

vtk geo structured points signature f u n c t i o n VTK GEO( Nx , Ny , Nz , X0 , Y0 , Z0 , Dx , Dy , Dz ) r e s u l t ( E IO )

The topology structured points is useful for structured grid with uniform discretization steps.

vtk geo structured points variables


i n t e g e r ( I4P ) , i n t e g e r ( I4P ) , i n t e g e r ( I4P ) , r e a l ( R8P o r R4P ) r e a l ( R8P o r R4P ) r e a l ( R8P o r R4P ) r e a l ( R8P o r R4P ) r e a l ( R8P o r R4P ) r e a l ( R8P o r R4P ) i n t e g e r ( I4P ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : Nx Ny Nz X0 Y0 Z0 Dx Dy Dz E IO ! ! ! ! ! ! ! ! ! ! number of nodes in x direction number of nodes in y direction number of nodes in z direction x coordinate of origin y coordinate of origin z coordinate of origin space step in x space step in y space step in z Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

, , , , , ,

Note that the variables X0,Y0,Z0,Dx,Dy,Dz can be passed both as 8-byte real kind and 4byte real kind; the dynamic displacement interface will call the correct function. Mixing 8-byte real kind and 4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-byte real kind. The VTK GEO structured point variables have the following meaning: Nx indicates the number of nodes in X direction. Ny indicates the number of nodes in Y direction. NZ indicates the number of nodes in Z direction. X0 indicates the X value of coordinates system origin. It is a scalar. Y0 indicates the Y value of coordinates system origin. It is a scalar. Z0 indicates the Z value of coordinates system origin. It is a scalar. Dx indicates the uniform grid step discretization in X direction. It is a scalar. Dy indicates the uniform grid step discretization in Y direction. It is a scalar. DZ indicates the uniform grid step discretization in Z direction. It is a scalar. E IO contains the inquiring integer ag for error handling. The following is an example of VTK GEO structured point calling:
VTK GEO Structured Points Calling

18

6.2 vtk geo

... integer(4):: Nx,Ny,Nz real(8):: X0,Y0,Z0 real(8):: Dx,Dy,Dz ... E_IO = VTK_GEO(Nx,Ny,Nz, & X0,Y0,Z0,Dx,Dy,Dz) ...

6.2.2 vtk geo structured grid

vtk geo structured grid signature f u n c t i o n VTK GEO( Nx , Ny , Nz ,NN, X, Y , Z ) r e s u l t ( E IO )

The topology structured grid is useful for structured grid with non-uniform discretization steps.

vtk geo structured grid variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : Nx Ny Nz NN X ( 1 :NN) Y ( 1 :NN) Z ( 1 :NN) E IO ! ! ! ! ! ! ! ! number of nodes in x direction number of nodes in y direction number of nodes in z direction number of all nodes x coordinates y coordinates z coordinates Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

Note that the variables X,Y,Z can be passed both as 8-byte real kind and 4-byte real kind; the dynamic displacement interface will call the correct function. Mixing 8-byte real kind and 4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-byte real kind. The VTK GEO structured grid variables have the following meaning: Nx indicates the number of nodes in X direction. Ny indicates the number of nodes in Y direction. NZ indicates the number of nodes in Z direction. NN indicates the number of all nodes, NN = Nx Ny Nz. X contains the X coordinates values of all nodes. It is a vector of [1 : NN]. Y contains the Y coordinates values of all nodes. It is a vector of [1 : NN].

19

6.2 vtk geo

Z contains the Z coordinates values of all nodes. It is a vector of [1 : NN]. E IO contains the inquiring integer ag for error handling. The following is an example of VTK GEO structured grid calling: ... integer(4), parameter:: Nx=10,Ny=10,Nz=10 integer(4), parameter:: Nnodi=Nx*Ny*Nz real(8):: X(1:Nnodi),Y(1:Nnodi),Z(1:Nnodi) ... E_IO = VTK_GEO(Nx,Ny,Nz,Nnodi,X,Y,Z) ...
VTK GEO Structured Grid Calling

6.2.3 vtk geo rectilinear grid

vtk geo rectilinear grid signature f u n c t i o n VTK GEO( Nx , Ny , Nz , X, Y , Z ) r e s u l t ( E IO )

The topology rectilinear grid is useful for structured grid with non-uniform discretization steps even in generalized coordinates.

vtk geo rectilinear grid signature


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : Nx Ny Nz X ( 1 : Nx ) Y ( 1 : Ny ) Z ( 1 : Nz ) E IO ! ! ! ! ! ! ! number of nodes in x direction number of nodes in y direction number of nodes in z direction x coordinates y coordinates z coordinates Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

Note that the variables X,Y,Z can be passed both as 8-byte real kind and 4-byte real kind; the dynamic displacement interface will call the correct function. Mixing 8-byte real kind and 4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-byte real kind. The VTK GEO rectilinear grid variables have the following meaning: Nx indicates the number of nodes in X direction. Ny indicates the number of nodes in Y direction. Nz indicates the number of nodes in Z direction.

20

6.2 vtk geo

X contains the X coordinates values of nodes. It is a vector of [1 : Nx]. Y contains the Y coordinates values of nodes. It is a vector of [1 : Ny]. Z contains the Z coordinates values of nodes. It is a vector of [1 : Nz]. E IO contains the inquiring integer ag for error handling. The following is an example of VTK GEO rectilinear grid calling: ... integer(4), parameter:: Nx=10,Ny=20,Nz=30 real(4):: X(1:Nx),Y(1:Ny),Z(1:Nz) ... E_IO = VTK_GEO(Nx,Ny,Nz,X,Y,Z) ...
VTK GEO Rectilinear Grid Calling

6.2.4 vtk geo unstructured grid

vtk geo unstructured grid signature f u n c t i o n VTK GEO( Nnodi , X, Y , Z ) r e s u l t ( E IO )

The topology unstructured grid is necessary for unstructured grid, the most general mesh format. This topology is also useful for scructured mesh in order to save only a non-structured clip of mesh.

vtk geo unstructured grid variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : NN X ( 1 :NN) Y ( 1 :NN) Z ( 1 :NN) E IO ! ! ! ! ! number of nodes x coordinates of all nodes y coordinates of all nodes z coordinates of all nodes Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

Note that the variables X,Y,Z can be passed both as 8-byte real kind and 4-byte real kind; the dynamic displacement interface will call the correct function. Mixing 8-byte real kind and 4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-byte real kind. The VTK GEO unstructured grid variables have the following meaning: NN indicates the number of all nodes. X contains the X coordinates values of nodes. It is a vector of [1 : NN].

21

6.3 function vtk con

Y contains the Y coordinates values of nodes. It is a vector of [1 : NN]. Z contains the Z coordinates values of nodes. It is a vector of [1 : NN]. E IO contains the inquiring integer ag for error handling. The following is an example of VTK GEO unstructured grid calling: ... integer(4), parameter:: NN=100 real(4):: X(1:NN),Y(1:NN),Z(1:NN) ... E_IO = VTK_GEO(NN,X,Y,Z) ...
VTK GEO Unstructured Grid Calling

In order to use the unstructured grid it is necessary to save also the connectivity of the grid. The connectivity must be saved with the function vtk con.

6.3 function vtk con

vtk con signature f u n c t i o n VTK CON(NC, c o n n e c t , c e l l t y p e ) r e s u l t ( E IO )

This function must be used when unstructured grid is used. It saves the connectivity of the unstructured mesh.

vtk con variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : c h a r a c t e r ( len=maxlen ) : : i n t e g e r ( I4P ) : : NC connect ( : ) c e l l t y p e ( 1 :NC) E IO s buffer ncon ! ! ! ! ! ! number of cells mesh connectivity VTK cell type Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done buffer string dimension of connectivity vector

The VTK CON variables have the following meaning: NC indicates the number of all cells. connect contains the connectivity of the mesh. It is a vector. cell type contains the type of every cells. It is a vector of [1 : NC]. E IO contains the inquiring integer ag for error handling.

22

6.3 function vtk con

The vector connect must follow the VTK legacy standard. It is passed as assumedshape array because its dimensions is related to the mesh dimensions in a complex way. Its dimensions can be calculated by the following equation:
NC

dc = NC +
i=1

nvertexi

(6.1)

where dc is connectivity vector dimension and nvertexi is the number of vertices of ith cell. The VTK legacy standard for the mesh connectivity is quite obscure at least at rst sight. It is more simple analizing an example. Suppose we have a mesh composed by 2 cells, one hexahedron (8 vertices) and one pyramid with square basis (5 vertices); suppose that the basis of pyramid is constitute by a face of the hexahedron and so the two cells share 4 vertices. The equation 6.1 gives dc = 2 + 8 + 5 = 15; the connectivity vector for this mesh can be: ! first cell connect(1) = connect(2) = connect(3) = connect(4) = connect(5) = connect(6) = connect(7) = connect(8) = connect(9) = ! second cell connect(10) = connect(11) = connect(12) = connect(13) = connect(14) = connect(15) =
Connectivity vector example for VTK legacy standard

8 0 1 2 3 4 5 6 7 5 0 1 2 3 8

=> => => => => => => => => => => => => => =>

number of vertices of 1 cell identification flag of 1 vertex identification flag of 2 vertex identification flag of 3 vertex identification flag of 4 vertex identification flag of 5 vertex identification flag of 6 vertex identification flag of 7 vertex identification flag of 8 vertex number of vertices of 2 cell identification flag of 1 vertex identification flag of 2 vertex identification flag of 3 vertex identification flag of 4 vertex identification flag of 5 vertex

of of of of of of of of

1 1 1 1 1 1 1 1

cell cell cell cell cell cell cell cell

of of of of of

2 2 2 2 2

cell cell cell cell cell

Note that the rst 4 identication ags of pyramid vertices as the same of the rst 4 identication ags of the hexahedron because the two cells share this face. It is also important to note that the identication ags start form 0 value: this is impose to the VTK standard. The function VTK CON does not calculate the connectivity vector: it writes the connectivity vector conforming the VTK standard, but does not calculate it. In the future release of lib vtk io will be included a function to calculate the connectivity vector. The vector variable tipo must conform the VTK standard 1 . It contains the type of each cells. For the above example this vector is:
Cell-Type vector example for VTK legacy standard

tipo(1) = 12 tipo(2) = 14

=> VTK hexahedron type of 1 cell => VTK pyramid type of 2 cell

1 See the le VTK-Standard at the Kitware homepage.

23

6.4 function vtk dat

The following is an example of VTK CON calling:


VTK CON Calling

... integer(4), parameter:: NC=2 integer(4), parameter:: Nvertex1=8 integer(4), parameter:: Nvertex2=5 integer(4), parameter:: dc=NC+Nvertex1+Nvertex2 integer(4):: connect(1:dc) integer(4):: cell_type(1:NC) ... E_IO = VTK_CON(NC,connect,cell_type) ...

6.4 function vtk dat

vtk dat signature f u n c t i o n VTK DAT(NC NN, v a r l o c a t i o n ) r e s u l t ( E IO )

This function must be called before saving the data related to geometric mesh. This function initializes the saving of data variables indicating the type of variables that will be saved.

vtk dat variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : NC NN c h a r a c t e r ( * ) , i n t e n t ( IN ) : : v a r l o c a t i o n i n t e g e r ( I4P ) : : E IO c h a r a c t e r ( len=maxlen ) : : s buffer ! ! ! ! number of cells or nodes of eld location of saving variables: cell for cell-centered, node for node-centered Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done buffer string

The VTK DAT variables have the following meaning: NC NN indicates the number of all cells or all nodes according to the value of tipo. var location contains the location-type of variables that will be saved after VTK DAT. It is a scalar and cab assume the following values: A. cell (it is case insensitive) variables will be cell-centered. B. node (it is case insensitive) variables will be node-centered. E IO contains the inquiring integer ag for error handling.

24

6.5 vtk var

Of course a single le can contain both cell and node centered variables; in this case the VTK DAT function must be called two times, before saving cell-centered variables and before saving node-centered variables. The following is an example of VTK DAT calling:
VTK DAT Calling

... E_IO = VTK_DAT(50,node) ...

6.5 vtk var


VTK VAR is an interface to 8 different functions; there are 3 functions for scalar variables, 3 functions for vectorial variables and 2 function texture variables. This function saves the data variables related to geometric mesh. The inputs that must be passed change depending on the data variables type.

6.5.1 vtk var scalar data

vtk var scalar data signature f u n c t i o n VTK VAR( f o r m a t o , NC NN, varname , v a r ) r e s u l t ( E IO )

This kind of call is used to save scalar data.

vtk var scalar data variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : character ( * ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) o r i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : > 0 if IO is not done NC NN varname v a r ( 1 : NC NN) E IO ! ! ! ! number of nodes or cells variable name variable to be saved Input/Output inquiring ag: 0 if IO is done,

The VTK VAR variables have the following meaning: NC NN indicates the number of all cells or all nodes according to the value of tipo passed to VTK DAT. varname contains the name attribuited the variable saved. var contains the values of variables in each nodes or cells. It is a vector of [1 : NC NN]. E IO contains the inquiring integer ag for error handling.

25

6.5 vtk var

Note that the variables var can be passed both as 8-byte real kind, 4-byte real kind and 4-byte integer; the dynamic displacement interface will call the correct function. The following is an example of VTK VAR scalar data calling: ... integer(4), parameter:: NC_NN=100 real(4):: var(1:NC_NN) ... E_IO = VTK_VAR(NC_NN,Scalar Data,var) ...
VTK V Scalar Data AR Calling

6.5.2 vtk var real vectorial data

vtk var real vectorial data signature f u n c t i o n VTK VAR( t i p o , NC NN, varname , varX , varY , varZ ) r e s u l t ( E IO )

This kind of call is used to save real vectorial data.

vtk var real vectorial data variables


character ( * ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : character ( * ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : vec type NC NN varname varX ( 1 : NC NN) varY ( 1 : NC NN) varZ ( 1 : NC NN) E IO ! ! ! ! ! ! ! vector type: vect = generic vector , norm = normal vector number of nodes or cells variable name x component of vector y component of vector z component of vector Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

The VTK VAR variables have the following meaning: tipo indicates the type of vector. It can assume the following value: A. vect generic vector. B. norm normal vector of face. NC NN indicates the number of all cells or all nodes according to the value of tipo passed to VTK DAT. varname contains the name attribuited the variable saved. varX contains the values of X component in each nodes or cells. It is a vector of [1 : NC NN]. varY contains the values of Y component in each nodes or cells. It is a vector of [1 : NC NN].

26

6.5 vtk var

varZ contains the values of Z component in each nodes or cells. It is a vector of [1 : NC NN]. E IO contains the inquiring integer ag for error handling. Note that the variables varX,varY,varZ can be passed both as 8-byte real kind and 4-byte real kind; the dynamic displacement interface will call the correct function. The following is an example of VTK VAR real vectorial data calling: ... integer(4), parameter:: NC_NN=100 real(4):: varX(1:NC_NN) real(4):: varZ(1:NC_NN) real(4):: varZ(1:NC_NN) ... E_IO = VTK_VAR(vect,NC_NN,Real Vectorial Data,... ...varX,varY,varZ) ...
VTK V Real AR Vectorial Data Calling

6.5.3 vtk var integer vectorial data

vtk var integer vectorial data signature f u n c t i o n VTK VAR(NC NN, varname , varX , varY , varZ ) r e s u l t ( E IO )

This kind of call is used to save integer vectorial data.

vtk var integer vectorial data variables


i n t e g e r ( R4P ) , character ( * ) , i n t e g e r ( R4P ) , i n t e g e r ( R4P ) , i n t e g e r ( R4P ) , i n t e g e r ( R4P ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : NC NN varname varX ( 1 : NC NN) varY ( 1 : NC NN) varZ ( 1 : NC NN) E IO ! ! ! ! ! ! number of nodes or cells variable name x component of vector y component of vector z component of vector Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

The VTK VAR variables have the following meaning: NC NN indicates the number of all cells or all nodes according to the value of tipo passed to VTK DAT. varname contains the name attribuited the variable saved. varX contains the values of X component in each nodes or cells. It is a vector of [1 : NC NN].

27

6.5 vtk var

varY contains the values of Y component in each nodes or cells. It is a vector of [1 : NC NN]. varZ contains the values of Z component in each nodes or cells. It is a vector of [1 : NC NN]. E IO contains the inquiring integer ag for error handling. The following is an example of VTK VAR real vectorial data calling: ... integer(4), parameter:: NC_NN=100 integer(4):: varX(1:NC_NN) integer(4):: varZ(1:NC_NN) integer(4):: varZ(1:NC_NN) ... E_IO = VTK_VAR(NC_NN,Integer Vectorial Data, & varX,varY,varZ) ...
VTK V Integer AR Vectorial Data Calling

6.5.4 vtk var texture data

vtk var texture data signature f u n c t i o n VTK VAR(NC NN, , dimm , varname , t e x t C o o ) r e s u l t ( E IO )

This kind of call is used to save texture data.

vtk var texture data variables


i n t e g e r ( R4P ) , i n t e g e r ( R4P ) , character ( * ) , r e a l ( R8P o r R4P ) , i n t e g e r ( R4P ) : : is not done i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : i n t e n t ( IN ) : : NC NN dimm varname t e x t C o o ( 1 : NC NN, 1 : dimm ) E IO ! ! ! ! ! number of nodes or cells texture dimensions variable name texture Input/Output inquiring ag: 0 if IO is done, > 0 if IO

The VTK VAR variables have the following meaning: NC NN indicates the number of all cells or all nodes according to the value of tipo passed to VTK DAT. dimm indicates the dimensions of the texture coordinates. It can assume the value: A. 1 scalar texture. B. 2 twodimensional texture.

28

6.6 function vtk end

C. 3 threedimensional texture. varname contains the name attribuited the variable saved. textCoo contains the coordinates of texture in each nodes or cells. It is a vector of [1 : NC NN, 1 : dimm]. E IO contains the inquiring integer ag for error handling. Note that the variable textCoo can be passed both as 8-byte real kind and 4-byte real kind; the dynamic displacement interface will call the correct function. The following is an example of VTK VAR texture data calling: ... integer(4), parameter:: NC_NN=100 integer(4), parameter:: dimm=2 real(4):: textCoo(1:NC_NN,1:dimm) ... E_IO = VTK_VAR(NC_NN,dimm,Texture Data,textCoo) ...
VTK V Texture AR Data Calling

6.6 function vtk end

vtk end signature f u n c t i o n VTK END ( ) r e s u l t ( E IO )

This function is used to nalize the le opened and it has not inputs. The lib vtk io manages the le unit without the users action.

vtk end variables


i n t e g e r ( I4P ) : : E IO ! Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

The VTK END variables have the following meaning: E IO contains the inquiring integer ag for error handling. The following is an example of VTK END calling:
VTK END Calling

29

6.6 function vtk end

... E_IO = VTK_END() ...

30

7
vtk xml functions
Contents
7.1 7.2 Function VTK INI XML VTK GEO XML 7.2.1 7.2.2 7.2.3 7.2.4 7.3 7.4 7.5 33 33 34 36 32 VTK GEO XML STRUCTURED GRID VTK GEO XML RECTILINEAR GRID VTK GEO XML UNSTRUCTURED GRID VTK GEO XML CLOSE PIECE 37 40 41 42 37

Function VTK CON XML Function VTK DAT XML VTK VAR XML 7.5.1 7.5.2 41

VTK VAR XML SCALAR DATA 43

VTK VAR XML VECTORIAL DATA

7.6

Function VTK END XML

legacy one. It the The XML standard is more powerful thanusing a library is more exible and free but onthan other hand is more (but not so more like lib vtk io ...) complex legacy standard. The output of XML functions is a well-formated XML le at least for the ascii format (in the binary format lib vtk io use raw-data format that does not produce a well formated XML le). The XML functions follow the same calling-convention of the legacy functions; all the lib vtk io XML functions are 4-byte integer function: the output of these functions is an integer that is 0 if the function calling has been done right while it is > 0 if some errors occur. The functions calling is the same as legacy functions:
Functions Calling

...

31

7.1 function vtk ini xml

integer(4):: E_IO ... E_IO = VTK_INI_XML(.... ...

Note that the XML functions have the same name of legacy functions with the sufx XML.

7.1 function vtk ini xml

vtk ini xml signature

f u n c t i o n VTK INI XML ( o u t p u t f o r m a t , f i l e n a m e , m e s h t o p o l o g y , nx1 , nx2 , ny1 , ny2 , nz1 , nz2

The VTK INI XML function is used for initializing le. This function must be the rst to be called.

vtk ini xml variables


c h a r a c t e r ( * ) , i n t e n t ( IN ) : : output format c h a r a c t e r ( * ) , i n t e n t ( IN ) : : filename c h a r a c t e r ( * ) , i n t e n t ( IN ) : : mesh topology i n t e g e r ( I4P ) , i n t e n t ( IN ) , o p t i o n a l : : nx1 , nx2 i n t e g e r ( I4P ) , i n t e n t ( IN ) , o p t i o n a l : : ny1 , ny2 i n t e g e r ( I4P ) , i n t e n t ( IN ) , o p t i o n a l : : nz1 , nz2 i n t e g e r ( I4P ) : : E IO not done c h a r a c t e r ( len=maxlen ) : : s buffer ! ! ! ! ! ! ! output format: ASCII or BINARY le name mesh topology initial and nal nodes of x axis initial and nal nodes of y axis initial and nal nodes of z axis Input/Output inquiring ag: 0 if IO is done, > 0 if IO is

! buffer string

The VTK INI XML variables have the following meaning: output format indicates the format of output le. It can assume the following values: A. ascii (it is case insensitive) creating an ascii output le. B. binary (it is case insensitive) creating a binary (big endian encoding) output le. lename contains the name (with its path) of the output le. topology indicates the topology of the mesh and can assume the following values: A. StructuredGrid. B. RectilinearGrid. C. UnstructuredGrid. nx1,nx2 contains the extent of X axis; nx1 is the initial node and nx2 is the nal. ny1,ny2 contains the extent of Y axis; ny1 is the initial node and ny2 is the nal. nz1,nz2 contains the extent of Z axis; nz1 is the initial node and nz2 is the nal.

32

7.2 vtk geo xml

E IO contains the inquiring integer ag for error handling. This function is quite more complex than the rispective legacy function; it needs more inputs: the XML standard needs more informations to initialize the le. The following is an example of VTK INI XML calling: ... ... E_IO = VTK_INI_XML(BINARY,XML_RECT_BINARY.vtr, RectilinearGrid, nx1=nx1,nx2=nx2, ny1=ny1,ny2=ny2, nz1=nz1,nz2=nz2) ...
VTK INI XML Calling

& & & &

Note that the le extension is necessary in the le name. The XML standard has different extensions for each different topologies (i.e. .vtr for rectilinear topology). See the VTKstandard le for more information.

7.2 vtk geo xml


VTK GEO XML is an interface to 6 different functions; there are 2 functions for each 3 topologies supported. This function must be called after VTK INI XML. It saves the mesh geometry. The inputs that must be passed change depending on the topologies choiced. Not all VTK topologies have been implemented (polydata topologies are absent). The signatures for all implemented topologies are now reported.

7.2.1 vtk geo xml structured grid

vtk geo xml structured grid signature f u n c t i o n VTK GEO XML( nx1 , nx2 , ny1 , ny2 , nz1 , nz2 ,NN, & X, Y , Z) r e s u l t ( E IO )

The topology structured grid is useful for structured grid with non-uniform discretization steps.

vtk geo xml structured grid variables


i n t e g e r ( I4P ) , i n t e g e r ( I4P ) , i n t e g e r ( I4P ) , i n t e n t ( IN ) : : nx1 , nx2 i n t e n t ( IN ) : : ny1 , ny2 i n t e n t ( IN ) : : nz1 , nz2 ! initial and nal nodes of x axis ! initial and nal nodes of y axis ! initial and nal nodes of z axis

33

7.2 vtk geo xml

i n t e g e r ( I4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : :

NN X ( 1 :NN) Y ( 1 :NN) Z ( 1 :NN) E IO

! ! ! ! !

number of all nodes x coordinates y coordinates z coordinates Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

Note that the variables X,Y,Z can be passed both as 8-byte real kind and 4-byte real kind; the dynamic displacement interface will call the correct function. Mixing 8-byte real kind and 4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-byte real kind. The VTK GEO XML structured grid variables have the following meaning: nx1,nx2 contains the extent of X axis; nx1 is the initial node and nx2 is the nal. ny1,ny2 contains the extent of Y axis; ny1 is the initial node and ny2 is the nal. nz1,nz2 contains the extent of Z axis; nz1 is the initial node and nz2 is the nal. NN contains the global number of nodes NN = (nx2 nx1 + 1) (ny2 ny1 + 1) (nz2 nz1 + 1). X contains the X coordinates values of all nodes. It is a vector of [1 : NN]. Y contains the Y coordinates values of all nodes. It is a vector of [1 : NN]. Z contains the Z coordinates values of all nodes. It is a vector of [1 : NN]. E IO contains the inquiring integer ag for error handling. The following is an example of VTK GEO XML structured grid calling: ... integer(4):: nx1,nx2 integer(4):: ny1,ny2 integer(4):: nz1,nz2 integer(4):: NN real(4):: X(1:NN),Y(1:NN),Z(1:NN) ... E_IO = VTK_GEO_XML(nx1,nx2,ny1,ny2,nz1,nz2, & NN, & X,Y,Z) ...
VTK GEO XML Structured Grid Calling

7.2.2 vtk geo xml rectilinear grid

34

7.2 vtk geo xml

vtk geo xml rectilinear grid signature f u n c t i o n VTK GEO XML( nx1 , nx2 , ny1 , ny2 , nz1 , nz2 , & X, Y , Z) r e s u l t ( E IO )

The topology rectilinear grid is useful for structured grid with non-uniform discretization steps even in generalized coordinates.

vtk geo xml rectilinear grid variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : nx1 , nx2 ny1 , ny2 nz1 , nz2 X( nx1 : nx2 ) Y ( ny1 : ny2 ) Z ( nz1 : nz2 ) E IO ! ! ! ! ! ! ! initial and nal nodes of x axis initial and nal nodes of y axis initial and nal nodes of z axis x coordinates y coordinates z coordinates Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

Note that the variables X,Y,Z can be passed both as 8-byte real kind and 4-byte real kind; the dynamic displacement interface will call the correct function. Mixing 8-byte real kind and 4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-byte real kind. The VTK GEO XML rectilinear grid variables have the following meaning: nx1,nx2 contains the extent of X axis; nx1 is the initial node and nx2 is the nal. ny1,ny2 contains the extent of Y axis; ny1 is the initial node and ny2 is the nal. nz1,nz2 contains the extent of Z axis; nz1 is the initial node and nz2 is the nal. X contains the X coordinates values of X nodes. It is a vector of [nx1 : nx2]. Y contains the Y coordinates values of Y nodes. It is a vector of [ny1 : ny2]. Z contains the Z coordinates values of Z nodes. It is a vector of [nz1 : nz2]. E IO contains the inquiring integer ag for error handling. The following is an example of VTK GEO XML rectilinear grid calling: ... integer(4):: nx1,nx2 integer(4):: ny1,ny2 integer(4):: nz1,nz2 real(4):: X(nx1:nx2),Y(ny1:ny2),Z(nz1:nz2) ... E_IO = VTK_GEO_XML(nx1,nx2,ny1,ny2,nz1,nz2, & X,Y,Z) ...
VTK GEO XML Structured Grid Calling

35

7.2 vtk geo xml

7.2.3 vtk geo xml unstructured grid

vtk geo xml unstructured grid signature f u n c t i o n VTK GEO XML( Nnodi , N C e l l e , X, Y , Z ) r e s u l t ( E IO ) The topology unstructured grid is necessary for unstructured grid, the most general mesh format. This topology is also useful for scructured mesh in order to save only a non-structured clip of mesh.

vtk geo xml unstructured grid variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : r e a l ( R8P o r R4P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : NN NC X ( 1 :NN) Y ( 1 :NN) Z ( 1 :NN) E IO ! ! ! ! ! ! number of nodes number of cells x coordinates y coordinates z coordinates Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

Note that the variables X,Y,Z can be passed both as 8-byte real kind and 4-byte real kind; the dynamic displacement interface will call the correct function. Mixing 8-byte real kind and 4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-byte real kind. The VTK GEO XML unstructured grid variables have the following meaning: Nnodi indicates the number of all nodes. NCelle indicates the number of all cells. X contains the X coordinates values of nodes. It is a vector of [1 : Nnodi]. Y contains the Y coordinates values of nodes. It is a vector of [1 : Nnodi]. Z contains the Z coordinates values of nodes. It is a vector of [1 : Nnodi]. E IO contains the inquiring integer ag for error handling. The following is an example of VTK GEO XML unstructured grid calling: ... integer(4), parameter:: Nnodi=100 integer(4), parameter:: NCelle=50 real(4):: X(1:Nnodi),Y(1:Nnodi),Z(1:Nnodi) ... E_IO = VTK_GEO_XML(ascii,Nnodi,NCelle,X,Y,Z) ...
VTK GEO XML Unstructured Grid Calling

In order to use the unstructured grid it is necessary to save also the connectivity of the grid. The connectivity must be saved with the function vtk con xml.

36

7.3 function vtk con xml

7.2.4 vtk geo xml close piece

vtk geo xml close piece signature f u n c t i o n VTK GEO XML ( ) r e s u l t ( E IO )

As we said before the XML standard is more powerful than legacy. XML le can contain more than 1 mesh with its associated variables. Thus there is the necessity to close each pieces that compose the data-set saved in the XML le. The vtk geo xml called in the close piece format is used just to close the current piece before saving another piece or closing the le.

vtk geo xml close piece variables


i n t e g e r ( I4P ) : : E IO ! Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

The VTK GEO XML close piece variables have the following meaning: E IO contains the inquiring integer ag for error handling. The following is an example of VTK GEO XML close piece calling: ... E_IO = VTK_GEO_XML() ...
VTK GEO XML Unstructured Grid Calling

7.3 function vtk con xml

vtk con xml signature f u n c t i o n VTK CON XML(NC, c o n n e c t , o f f s e t , c e l l t y p e ) r e s u l t ( E IO )

This function must be used when unstructured grid is used. It saves the connectivity of the unstructured mesh.

vtk con xml variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : NC i n t e g e r ( I4P ) , i n t e n t ( IN ) : : c o n n e c t ( : ) i n t e g e r ( I4P ) , i n t e n t ( IN ) : : o f f s e t ( 1 :NC) ! number of cells ! mesh connectivity ! cell offset

37

7.3 function vtk con xml

i n t e g e r ( I1P ) , i n t e n t ( IN ) : : c e l l t y p e ( 1 :NC) i n t e g e r ( I4P ) : : E IO c h a r a c t e r ( len=maxlen ) : : s buffer i n t e g e r ( I4P ) : : n1

! ! ! !

VTK cell type Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done buffer string counter

The VTK CON XML variables have the following meaning: NCelle indicates the number of all cells. connect contains the connectivity of the mesh. It is a vector. oset contains the offset1 of every cells. It is a vector of [1 : NCelle]. tipo contains the type of every cells. It is a vector of [1 : NCelle]. E IO contains the inquiring integer ag for error handling. The vector connect must follow the VTK XML standard. It is passed as assumed-shape array because its dimensions is related to the mesh dimensions in a complex way. Its dimensions can be calculated by the following equation:
NCelle

dc =
i=1

nvertexi

(7.1)

where dc is connectivity vector dimension and nvertexi is the number of vertices of ith cell. Note that this equation is different from the legacy one (eq. 6.1). The XML connectivity convention is quite different from the legacy standard. As an example considering the same mesh of section ??: suppose we have a mesh composed by 2 cells, one hexahedron (8 vertices) and one pyramid with square basis (5 vertices); suppose that the basis of pyramid is constitute by a face of the hexahedron and so the two cells share 4 vertices. The equation 7.1 gives dc = 8 + 5 = 13; the connectivity vector for this mesh can be: ! first cell connect(1) = connect(2) = connect(3) = connect(4) = connect(5) = connect(6) = connect(7) = connect(8) = ! second cell connect(9) = connect(10) = connect(11) = connect(12) = connect(13) =
Connectivity vector example for VTK XML standard

0 1 2 3 4 5 6 7 0 1 2 3 8

=> => => => => => => => => => => => =>

identification identification identification identification identification identification identification identification identification identification identification identification identification

flag flag flag flag flag flag flag flag flag flag flag flag flag

of of of of of of of of of of of of of

1 2 3 4 5 6 7 8 1 2 3 4 5

vertex vertex vertex vertex vertex vertex vertex vertex vertex vertex vertex vertex vertex

of of of of of of of of of of of of of

1 1 1 1 1 1 1 1 2 2 2 2 2

cell cell cell cell cell cell cell cell cell cell cell cell cell

1 The summ of nodes of all previous cells included the current cell.

38

7.3 function vtk con xml

Therefore this connectivity vector convention is more simple than the legacy convention, now we must create also the offset vector that contains the data now missing in the connect vector. The offset vector for this mesh can be: ! first cell offset(1) = 8 => summ of nodes of 1 cell ! second cell offset(2) = 13 => summ of nodes of 1 and 2 cells
Offset vector example for VTK XML standard

The value of every cell-offset can be calculated by the following equation:


c

offsetc =
i=1

nvertexi

(7.2)

where offsetc is the value of cth cell and nvertexi is the number of vertices of ith cell. The function VTK CON XML does not calculate the connectivity and offset vectors: it writes the connectivity and offset vectors conforming the VTK XML standard, but does not calculate them. In the future release of lib vtk io will be included a function to calculate the connectivity and offset vector. The vector variable tipo must conform the VTK XML standard 2 that is the same of the legacy standard presented previous (sec. ??). It contains the type of each cells. For the above example this vector is: tipo(1) = 12 tipo(2) = 14 => VTK hexahedron type of 1 cell => VTK pyramid type of 2 cell
Cell-Type vector example for VTK legacy standard

The following is an example of VTK CON XML calling: ... integer(4), parameter:: NCelle=2 integer(4), parameter:: Nvertex1=8 integer(4), parameter:: Nvertex2=5 integer(4), parameter:: dc=Nvertex1+Nvertex2 integer(4):: connect(1:dc) integer(4):: offset(1:NCelle) integer(4):: tipo(1:NCelle) ... E_IO = VTK_CON_XML(NCelle,connect,offset,tipo) ...
VTK CON XML Calling

2 See the le VTK-Standard at the Kitware homepage.

39

7.4 function vtk dat xml

7.4 function vtk dat xml

vtk dat xml signature f u n c t i o n VTK DAT XML( v a r l o c a t i o n , v a r b l o c k a c t i o n ) r e s u l t ( E IO )

This function must be called before saving the data related to geometric mesh. This function initializes the saving of data variables indicating the type of variables that will be saved.

vtk dat xml variables


c h a r a c t e r ( * ) , i n t e n t ( IN ) : : v a r l o c a t i o n ! location of saving variables: CELL for cell-centered, NODE for node-centered c h a r a c t e r ( * ) , i n t e n t ( IN ) : : v a r b l o c k a c t i o n ! variables block action: OPEN or CLOSE block i n t e g e r ( I4P ) : : E IO ! Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

The VTK DAT XML variables have the following meaning: var location contains the location-type of variables that will be saved after VTK DAT. It is a scalar and cab assume the following values: A. cell (it is case insensitive) variables will be cell-centered. B. node (it is case insensitive) variables will be node-centered. var block action indicates if the block-data-variables is being opened or closed; it can assume the following values: A. open (it is case insensitive) block-data is being opened. B. close (it is case insensitive) block-data is being closed. E IO contains the inquiring integer ag for error handling. Of course a single le can contain both cell and node centered variables. The vtk dat xml must be called two times, before saving a block-data-variables in order to open the block, and after the block-data-variables has been saved in order to close the block. XML le can contains as many blocks as you want. The following is an example of VTK DAT XML calling: ... E_IO = VTK_DAT_XML(node,OPEN) ... SAVE YOUR DATA WITH VTK_VAR_XML ... E_IO = VTK_DAT_XML(node,CLOSE) ...
VTK DAT XML Calling

40

7.5 vtk var xml

7.5 vtk var xml


VTK VAR XML is an interface to 12 different functions; there are 6 functions for scalar variables (1 for each supported precision: R8P, R4P, I8P, I4P, I2P and I1P) and 6 for vectorial variables (1 for each supported precision: R8P, R4P, I8P, I4P, I2P and I1P) This function saves the data variables related to geometric mesh. The inputs that must be passed change depending on the data variables type.

7.5.1 vtk var xml scalar data

vtk var xml scalar data signature f u n c t i o n VTK VAR XML(NC NN, varname , v a r ) r e s u l t ( E IO )

This kind of call is used to save scalar data.

vtk var xml scalar data variables


i n t e g e r ( I4P ) , i n t e n t ( IN ) : : c h a r a c t e r ( * ) , i n t e n t ( IN ) : : r e a l ( R8P o r . . . R4P ) o r . . . i n t e g e r ( I8P o r . . . I4P o r . . . I2P o r . . . I1P ) , i n t e n t ( IN ) : : i n t e g e r ( I4P ) : : NC NN varname ! number of cells or nodes ! variable name

v a r ( 1 : NC NN) ! variable to be saved E IO ! Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done

The VTK VAR XML variables have the following meaning: NC NN indicates the number of all cells or all nodes according to the value of var location passed to VTK DAT XML. varname contains the name attribuited the variable saved. var contains the values of variables in each nodes or cells. It is a vector of [1 : NC NN]. E IO contains the inquiring integer ag for error handling. Note that the variables var can be passed both 8-byte real kind, 4-byte real kind, 8-byte integer, 4-byte integer, 2-byte integer and 1-byte integer; XML is very exible; the dynamic displacement interface will call the correct function. The following is an example of VTK VAR XML scalar data calling:
VTK V AR XML Scalar Data Calling

41

7.5 vtk var xml

... integer(4), parameter:: NC_NN=100 integer(2):: var(1:NC_NN) ... E_IO = VTK_VAR_XML(NC_NN,Scalar Data,var) ...

7.5.2 vtk var xml vectorial data

vtk var xml vectorial data signature f u n c t i o n VTK VAR XML(NC NN, varname , & varX , varY , varZ ) r e s u l t ( E IO )

This kind of call is used to save vectorial data.

vtk var xml vectorial data variables


i n t e g e r ( I4P ) , character ( * ) , r e a l ( R8P o r R4P ) o r . . . i n t e g e r ( I8P o r I4P o r I2P o r I1P ) , r e a l ( R8P o r R4P ) o r . . . i n t e g e r ( I8P o r I4P o r I2P o r I1P ) , r e a l ( R8P o r R4P ) o r . . . i n t e g e r ( I8P o r I4P o r I2P o r I1P ) , i n t e g e r ( I4P ) : : > 0 if IO is not done i n t e n t ( IN ) : : NC NN i n t e n t ( IN ) : : varname ! number of cells or nodes ! variable name

i n t e n t ( IN ) : : varX ( 1 : NC NN) ! x component i n t e n t ( IN ) : : varY ( 1 : NC NN) ! y component i n t e n t ( IN ) : : varZ ( 1 : NC NN) ! z component ! Input/Output inquiring ag: 0 if IO is done, E IO

The VTK VAR XML variables have the following meaning: NC NN indicates the number of all cells or all nodes according to the value of var location passed to VTK DAT XML. varname contains the name attribuited the variable saved. varX contains the values of X component in each nodes or cells. It is a vector of [1 : NC NN]. varY contains the values of Y component in each nodes or cells. It is a vector of [1 : NC NN]. varZ contains the values of Z component in each nodes or cells. It is a vector of [1 : NC NN]. E IO contains the inquiring integer ag for error handling. Note that the variables varX,varY,varZ can be passed both 8-byte real kind, 4-byte real kind, 8-byte integer, 4-byte integer, 2-byte integer and 1-byte integer; XML is very exible; the dynamic displacement interface will call the correct function.

42

7.6 function vtk end xml

The following is an example of VTK VAR XML vectorial data calling: ... integer(4), parameter:: NC_NN=100 integer(4):: varX(1:NC_NN) integer(4):: varZ(1:NC_NN) integer(4):: varZ(1:NC_NN) ... E_IO = VTK_VAR_XML(NC_NN,Vectorial Data, & varX,varY,varZ) ...
VTK V AR XML Vectorial Data Calling

7.6 function vtk end xml

vtk end xml signature f u n c t i o n VTK END XML ( ) r e s u l t ( E IO )

This function is used to nalize the le opened. The lib vtk io manages the le unit without the users action.

vtk end xml variables


i n t e g e r ( I4P ) : : character ( 2 ) : : r e a l ( R8P ) , r e a l ( R4P ) , i n t e g e r ( I8P ) , i n t e g e r ( I4P ) , i n t e g e r ( I2P ) , i n t e g e r ( I1P ) , i n t e g e r ( I4P ) : : i n t e g e r ( I4P ) : : E IO var type v R8 ( : ) v R4 ( : ) v I8 ( : ) v I4 ( : ) v I2 ( : ) v I1 ( : ) N v n1 ! ! ! ! ! ! ! ! ! ! Input/Output inquiring ag: 0 if IO is done, > 0 if IO is not done var type = R8,R4,I8,I4,I2,I1 R8 vector for IO in AppendData R4 vector for IO in AppendData I8 vector for IO in AppendData I4 vector for IO in AppendData I2 vector for IO in AppendData I1 vector for IO in AppendData vector dimension counter

allocatable allocatable allocatable allocatable allocatable allocatable

:: :: :: :: :: ::

The following is an example of VTK END XML calling: ... E_IO = VTK_END_XML() ...
VTK END XML Calling

43

A
lib vtk io usage example
Contents
a.1 a.2 a.3 a.4 Legacy Rectilinear Grid XML Rectilinear Grid XML Unstructured Grid Legacy Unstructured Grid 44 45 46 49

of lib io is quite simple. this chapter there example vtk The usageSome ofvtk following examplesInare present also inare sometest lib of libio.f90io usage. the the le vtk distributed within the lib vtk io .

a.1 legacy rectilinear grid


... integer(4), intent(IN):: real(8), intent(IN):: real(8), intent(IN):: real(8), intent(IN):: real(8), intent(IN):: character(*), intent(IN):: real(8):: integer(4):: ... x=(/(i, i=1, Nx, 1)/)
Legacy Rectilinear Grid

Nx p(1:Nx) rho(1:Nx) u(1:Nx) gamma(1:Nx) filename x(1:Nx) i

44

A.2 xml rectilinear grid

E_IO = VTK_INI(output_format = ascii, & filene = trim(filename)//.vtk, & title = Field, & mesh_topology = RECTILINEAR_GRID) E_IO = VTK_GEO(Nx = Nx, & Ny = 1, & Nz = 1, & X = x, & Y = (/0.0_8/), & Z = (/0.0_8/)) E_IO = VTK_DAT(NC_NN = Nx, & tipo = node) E_IO = VTK_VAR(NC_NN = Nx, & varname = p, & var = p) E_IO = VTK_VAR(NC_NN = Nx, & varname = rho, & var = rho) E_IO = VTK_VAR(NC_NN = Nx, & varname = u, & var = u) E_IO = VTK_VAR(NC_NN = Nx, & varname = gamma, & var = gamma) E_IO = VTK_VAR(NC_NN = Nx, & varname = a, & var = sqrt(gamma*p/rho)) E_IO = VTK_END() ...

a.2 xml rectilinear grid


XML Rectilinear Grid

... integer(4), integer(4), real(8), real(8), real(8), real(8), character(*), real(8):: integer(4)::

intent(IN):: intent(IN):: intent(IN):: intent(IN):: intent(IN):: intent(IN):: intent(IN)::

n Nx p(1:Nx) rho(1:Nx) u(1:Nx) gamma(1:Nx) filename x(1:Nx) i

45

A.3 legacy unstructured grid

... x=(/(i, i=1, Nx, 1)/) E_IO = VTK_INI_XML(output_format = ascii, & filename = trim(filename)//.vtr, & mesh_topology = RectilinearGrid, & nx1=1,nx2=Nx,ny1=1,ny2=1,nz1=1,nz2=1) E_IO = VTK_GEO_XML(nx1=1,nx2=Nx,ny1=1,ny2=1,nz1=1,nz2=1, & X=x,Y=(/0.0_8/),Z=(/0.0_8/)) E_IO = VTK_DAT_XML(tipo = node, & azione = OPEN) E_IO = VTK_VAR_XML(NC_NN = Nx, & varname = p, & var = p) E_IO = VTK_VAR_XML(NC_NN = Nx, & varname = rho, & var = rho) E_IO = VTK_VAR_XML(NC_NN = Nx, & varname = u, & var = u) E_IO = VTK_VAR_XML(NC_NN = Nx, & varname = gamma, & var = gamma) E_IO = VTK_VAR_XML(NC_NN = Nx, & varname = a, & var = sqrt(gamma*p/rho)) E_IO = VTK_DAT_XML(tipo = node, & azione = CLOSE) E_IO = VTK_GEO_XML() E_IO = VTK_END_XML() ...

a.3 legacy unstructured grid


... integer(4), integer(4), real(4), real(4), real(4), integer(4), integer(4), real(8),
Legacy Unstructured Grid

parameter:: parameter:: dimension(1:Nn):: dimension(1:Nn):: dimension(1:Nn):: dimension(1:Ne):: dimension(1:60):: dimension(1:Nn)::

Nn = 27 Ne = 11 x_uns y_uns z_uns tipo connect var_uns_grid

46

A.3 legacy unstructured grid

integer(4), dimension(1:Nn):: integer(4), dimension(1:Nn):: integer(4), dimension(1:Nn):: ... E_IO = VTK_INI(output_format filename title mesh_topology x_uns=(/0,1,2,0,1,2, 0,1,2,0,1,2, 0,1,2,0,1,2, 0,1,2,0,1,2, 0,1,2/) y_uns=(/0,0,0,1,1,1, 0,0,0,1,1,1, 1,1,1,1,1,1, 1,1,1,1,1,1, 1,1,1/) z_uns=(/0,0,0,0,0,0, 1,1,1,1,1,1, 2,2,2,3,3,3, 4,4,4,5,5,5, 6,6,6/) & & & & & & & & & & & &

var_uns_grid_X var_uns_grid_Y var_uns_grid_Z = = = = BINARY, & UNST_GRID_BIN.vtk, & Unstructured Grid Example & UNSTRUCTURED_GRID)

E_IO = VTK_GEO(Nnodi = Nn, & X=x_uns,Y=y_uns,Z=z_uns) connect = (/ 8, 0, 1, 4, 3, 6, 7,10, 9, 8, 1, 2, 5, 4, 7, 8,11,10, 4, 6,10, 9,12, 4, 5,11,10,14, 6,15,16,17,14,13,12, 6,18,15,19,16,20,17, 4,22,23,20,19, 3,21,22,18, 3,22,19,18, 2,26,25, 1,24/) tipo = (/12, & 12, & 10, & 10, & 7, & 6, & 9, & 5, & & & & & & & & & & &

47

A.3 legacy unstructured grid

5, & 3, & 1/) E_IO = VTK_CON(NCelle connect tipo E_IO = VTK_DAT(NC_NN tipo

= = = = =

Ne, connect, tipo) Nn, node)

& & &

var_uns_grid =(/ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,10.0,11.0, 12.0,13.0,14.0,15.0,16.0,17.0, 18.0,19.0,20.0,21.0,22.0,23.0, 24.0,25.0,26.0/) E_IO = VTK_VAR(NC_NN = Nn, & varname = scalars, & var = var_uns_grid) var_uns_grid_X=(/1,1,0,1,1,0, & 1,1,0,1,1,0, & 0,0,0,0,0,0, & 0,0,0,0,0,0, & 0,0,0/) var_uns_grid_Y=(/0,1,2,0,1,2, & 0,1,2,0,1,2, & 0,0,0,0,0,0, & 0,0,0,0,0,0, & 0,0,0/) var_uns_grid_Z=(/0,0,0,0,0,0, & 0,0,0,0,0,0, & 1,1,1,1,1,1, & 1,1,1,1,1,1, & 1,1,1/) E_IO = VTK_VAR(NC_NN = Nn, varname = vectors, varX = var_uns_grid_X, varY = var_uns_grid_Y, varZ = var_uns_grid_Z) E_IO = VTK_END() ...

& & & &

& & & &

48

A.4 xml unstructured grid

a.4 xml unstructured grid


... integer(4), parameter:: Nn = 27 integer(4), parameter:: Ne = 11 real(4), dimension(1:Nn):: x_uns real(4), dimension(1:Nn):: y_uns real(4), dimension(1:Nn):: z_uns integer(4), dimension(1:Ne):: tipo integer(4), dimension(1:49):: connect_xml integer(4), dimension(1:Ne):: offset_xml real(8), dimension(1:Nn):: var_uns_grid integer(4), dimension(1:Nn):: var_uns_grid_X integer(4), dimension(1:Nn):: var_uns_grid_Y integer(4), dimension(1:Nn):: var_uns_grid_Z ... E_IO = VTK_INI_XML(output_format = BINARY, & filename = XML_UNST_BINARY.vtu, & mesh_topology = UnstructuredGrid) x_uns=(/0,1,2,0,1,2, 0,1,2,0,1,2, 0,1,2,0,1,2, 0,1,2,0,1,2, 0,1,2/) y_uns=(/0,0,0,1,1,1, 0,0,0,1,1,1, 1,1,1,1,1,1, 1,1,1,1,1,1, 1,1,1/) z_uns=(/0,0,0,0,0,0, 1,1,1,1,1,1, 2,2,2,3,3,3, 4,4,4,5,5,5, 6,6,6/) & & & & & & & & & & & &
XML Unstructured Grid

E_IO = VTK_GEO_XML(Nnodi = Nn, & NCelle = Ne, & X=x_uns,Y=y_uns,Z=z_uns) connect_xml = (/ 0, 1, 4, 3, 6, 7,10, 9, 1, 2, 5, 4, 7, 8,11,10, 6,10, 9,12, 5,11,10,14, 15,16,17,14,13,12, & & & & &

49

A.4 xml unstructured grid

18,15,19,16,20,17, 22,23,20,19, 21,22,18, 22,19,18, 26,25, 24/) offset_xml = (/ 8, & 16, & 20, & 24, & 30, & 36, & 40, & 43, & 46, & 48, & 49/) E_IO = VTK_CON_XML(NCelle connect offset tipo = = = =

& & & & &

Ne, & connect_xml, & offset_xml, & (/12_1, & 12_1, & 10_1, & 10_1, & 7_1, & 6_1, & 9_1, & 5_1, & 5_1, & 3_1, & 1_1/))

E_IO = VTK_DAT_XML(tipo azione

= node, & = OPEN) & & & &

var_uns_grid =(/ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,10.0,11.0, 12.0,13.0,14.0,15.0,16.0,17.0, 18.0,19.0,20.0,21.0,22.0,23.0, 24.0,25.0,26.0/) E_IO = VTK_VAR_XML(NC_NN = Nn, & varname = scalars, & var = var_uns_grid) var_uns_grid_X=(/1,1,0,1,1,0, &

50

A.4 xml unstructured grid

1,1,0,1,1,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0/) var_uns_grid_Y=(/0,1,2,0,1,2, 0,1,2,0,1,2, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0/) var_uns_grid_Z=(/0,0,0,0,0,0, 0,0,0,0,0,0, 1,1,1,1,1,1, 1,1,1,1,1,1, 1,1,1/) E_IO = VTK_VAR_XML(NC_NN varname varX varY varZ E_IO = VTK_DAT_XML(tipo azione E_IO = VTK_GEO_XML() E_IO = VTK_END_XML() ... = = = = = = =

& & & & & & & & & & &

Nn, vector, var_uns_grid_X, var_uns_grid_Y, var_uns_grid_Z) node, & CLOSE)

& & & &

51

B
fortran & portable-kind-precision selection
popular programming language for fortran Fortran is the most obtain fast code and manage large scientic computing. WithBecause it is quite simple multidimensional array. fortran permits the achivment of high performance it is also used on great range of different computer-architettures, and often on the fastest supercomputer in the world. Therefore fortran programs must be portable: portability means that the code will give the same results on every different computer-architettures. One of the most important goal of the numeric code is to control the the numeric error due to nite precision of numerical operations. Fortran uses the ieee rappresentations; integers and reals (oating point) are represented with a nite precision. So when the code computes an operation it has a trunction error due to the truncation of the numerical nite rappresentaions. For numerical and more in general scientic applications this source of errors must be controlled. The programmer must know which is the precision associated to the code variables. Before the standard fortran 90/95 there are not any way to select the precision of the numerical variables in a portable fashion. With the possibility to specify a kind parameter for variables, the standard fortran 90/95 makes avaible two useful functions to select the kind precision of integers and reals:
selected real kind & selected int kind

function selected_real_kind(p,r) result(kind_id) integer, intent(IN), optional:: p integer, intent(IN), optional:: r integer:: kind_id The result, kind_id, is a scalar of type default integer. If both arguments are absent, the result is zero. Otherwise, the result has a value equal to a value of the kind parameter of a real data type with decimal precision, as returned by the function PRECISION, of at

52

least p digits and a decimal exponent range, as returned by the function RANGE, of at least r. function selected_int_kind(p) result(kind_id) integer, intent(IN), optional:: p integer:: kind_id The result, kind_id, is a scalar of type default integer. The result has a value equal to the value of the kind parameter of the integer data type that represents all values n in the range of about values n with -10^p < n < 10^p.

Using these two functions the programmer can accurately control the precision of its own variables in a portable manner. Note that specing the kind precision without using these two functions is not portable: real(8) means different precisions on different architettures. Parametrizing the kind of all numerical variables using these two functions makes the portable. The lib vtk io uses this principle to achive portable-kind-precision selection; in the library are dened some parameters by which all variables kind-precisions are parametrized: REAL PRECISION DEFINITIONS R16P real with 33 digits, range [+ 104931 , + 10+4931 1] R8P real with 15 digits, range [+ 10307 , + 10+307 1] R4P real with 6 digits, range [+ 1037 , + 10+ 37 1] INTEGER PRECISION DEFINITIONS I8P range [263 , +263 1] I4P range [231 , +231 1] I2P range [215 , +215 1] I1P range [27 , +27 1]
lib vtk io Kind-Precision Parameters

In order to avoid strange results porting your code the use of parametrized-kind-precision is very useful. The lib vtk io makes avaible to the external its own kind-parameters that can be used to parametrize the code.

53

C
dynamic dispatching
not (OOp) programming language. is a procedural Fortran is withan object oriented(ineritance, user-denited data type,Itpolimorphism...) language some of the the goals of OOp. Fortran most important aim is to ensure the performance of the code not its friendliness... Despite its nature, fortran 90/95 makes avaible some interesting features: it permits the dynamic dispatching of functions and subroutine ensuring the best performance. This goal is achived with use of interface construct. In the lib vtk io there are, at today, 4 interface blocks: interface VTK_GEO module procedure VTK_GEO_UNST_R8, VTK_GEO_UNST_R4, VTK_GEO_STRP_R8, VTK_GEO_STRP_R4, VTK_GEO_STRG_R8, VTK_GEO_STRG_R4, VTK_GEO_RECT_R8, VTK_GEO_RECT_R4 endinterface interface VTK_VAR module procedure VTK_VAR_SCAL_R8, VTK_VAR_SCAL_R4, VTK_VAR_SCAL_I4, VTK_VAR_VECT_R8, VTK_VAR_VECT_R4, VTK_VAR_VECT_I4, VTK_VAR_TEXT_R8, VTK_VAR_TEXT_R4
lib vtk io Interface Blocks

& & & & & & &

& & & & & & &

54

endinterface interface VTK_GEO_XML module procedure VTK_GEO_XML_STRG_R4, VTK_GEO_XML_STRG_R8, VTK_GEO_XML_RECT_R8, VTK_GEO_XML_RECT_R4, VTK_GEO_XML_UNST_R8, VTK_GEO_XML_UNST_R4, VTK_GEO_XML_CLOSEP endinterface interface VTK_VAR_XML module procedure VTK_VAR_XML_SCAL_R8, VTK_VAR_XML_SCAL_R4, VTK_VAR_XML_SCAL_I8, VTK_VAR_XML_SCAL_I4, VTK_VAR_XML_SCAL_I2, VTK_VAR_XML_SCAL_I1, VTK_VAR_XML_VECT_R8, VTK_VAR_XML_VECT_R4, VTK_VAR_XML_VECT_I8, VTK_VAR_XML_VECT_I4, VTK_VAR_XML_VECT_I2, VTK_VAR_XML_VECT_I1 endinterface

& & & & & &

& & & & & & & & & & &

By the interface construct lib vtk io has a more simple API. The user deals with a few functions without non-sense-long-name... Dynamic dispatching is not the magic wand to solve all problems but it is an useful tool to simplify the code API. It is not powerful as the C++ template, but it is a quantum-leap for fortran programmers.

55

D
known bugs
project it is a The lib vtkis io is a very youngtested. Itandused bygood example of wrong programming style... It unstable and not is only one user (... me of course!) and there are a lot of bugs that are still hidden. At the moment several features are missing (the input functions and the poly-data topology...), but it is useful to export fortran data to VTK standard, and this goal was the most important for me. At today only one main bug was found. Fortran allows the automatic reshape of arrays: as an example 2D array can be automatically (in the function calling) transformed to a 1D array with the same number of element of 2D array. The use of dynamic dispatching had disable this feature: dynamic dispatching use the array-shape information to dectet, at compile-time, the correct function to be called. So reshape arrays at calling phase is not allowed. In the next release I will x this bug introducing the function to reshape arrays between 1D, 2D and 3D arrays. A possible, not already found, bug is the non correct kind detection. It is possible that a code uses kind-precision parameter that does not match the lib vtk io parameters. I never observe this bug but it is possible. To avoid it the simple way is to use always the lib vtk io kind-precision parameters; if the parameters actually present do not match your necessities, dene new parameters in lib vtk io and redistribuite lib vtk io with your pacth! Finally there is a strong inefciency when saving XML binary le. To write XML binary lib vtk io uses a temporary scratch le to save binary data while saving all formatting data to the nal XML le; only when all XML formatting data have been written the scratch le is rewinded and the binary data is saved in the nal tag of XML le as raw data. This algorithm is obviously inefcient. Any tip is welcome!

56

E
gnu general public license
VERSION 3, 29 JUNE 2007 Copyright 2007 Free Software Foundation, Inc. http://fsf.org/ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a programto make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.

57

Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers and authors protection, the GPL clearly explains that there is no warranty for this free software. For both users and authors sake, the GPL requires that modied versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modied versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modication follow.

Terms and Conditions


0. Denitions. This License refers to version 3 of the GNU General Public License. Copyright also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. The Program refers to any copyrightable work licensed under this License. Each licensee is addressed as you. Licensees and recipients may be individuals or organizations. To modify a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a modied version of the earlier work or a work based on the earlier work. A covered work means either the unmodied Program or a work based on the Program. To propagate a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modication), making available to the public, and in some countries other activities as well. To convey a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.

58

An interactive user interface displays Appropriate Legal Notices to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The source code for a work means the preferred form of the work for making modications to it. Object code means any non-source form of a work. A Standard Interface means an interface that either is an ofcial standard dened by a recognized standards body, or, in the case of interfaces specied for a particular programming language, one that is widely used among developers working in that language. The System Libraries of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A Major Component, in this context, means a major essential component (kernel, window system, and so on) of the specic operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The Corresponding Source for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the works System Libraries, or general-purpose tools or generally available free programs which are used unmodied in performing those activities but which are not part of the work. For example, Corresponding Source includes interface denition les associated with source les for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specically designed to require, such as by intimate data communication or control ow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly afrms your unlimited permission to run the unmodied Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modications exclusively for you, or

59

provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fullling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modication of the work as a means of enforcing, against the works users, your or third parties legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Programs source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any nonpermissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modied Source Versions. You may convey a work based on the Program, or the modications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modied it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modies the requirement in section 4 to keep intact all notices. c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.

60

d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an aggregate if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilations users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source xed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to nd the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code

61

work. A User Product is either (1) a consumer product, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, normally used refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only signicant mode of use of the product. Installation Information for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modied versions of a covered work in that User Product from a modied version of its Corresponding Source. The information must sufce to ensure that the continued functioning of the modied object code is in no case prevented or interfered with solely because modication has been made. If you convey an object code work under this section in, or with, or specically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a xed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modied object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modied or installed by the recipient, or for the User Product in which it has been modied or installed. Access to a network may be denied when the modication itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. Additional permissions are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may

62

be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specied reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modied versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnication of licensors and authors of that material by anyone who conveys the material (or modied versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered further restrictions within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source les, a statement of the additional terms that apply to those les, or a notice indicating where to nd the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and nally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.

63

Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder noties you of the violation by some reasonable means, this is the rst time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An entity transaction is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the partys predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or afrmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A contributor is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributors contributor version. A contributors essential patent claims are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further

64

modication of the contributor version. For purposes of this denition, control includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributors essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a patent license is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To grant such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benet of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. Knowingly relying means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipients use of the covered work in a country, would infringe one or more identiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specic copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is discriminatory if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specic products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your

65

obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program species that a certain numbered version of the GNU General Public License or any later version applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program species that a proxy can decide which future versions of the GNU General Public License can be used, that proxys public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU

66

FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.

End of Terms and Conditions


How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source le to most effectively state the exclusion of warranty; and each le should have at least the copyright line and a pointer to where the full notice is found.
<one line to give the programs name and a brief idea of what it does.> Copyright (C) <textyear> <name of author>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>

This program comes with ABSOLUTELY NO WARRANTY; for details type show w. This is free software, and you are welcome to redistribute it under certain conditions; type show c for details.

67

The hypothetical commands show w and show c should show the appropriate parts of the General Public License. Of course, your programs commands might be different; for a GUI interface, you would use an about box. You should also get your employer (if you work as a programmer) or school, if any, to sign a copyright disclaimer for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see http://www.gnu.org/licenses/. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But rst, please read http://www.gnu.org/philosophy/why-not-lgpl.html.

68