Lib Vtk Io Guide

76
LIB VTK IO vtk input / output fortran library Version 0.2 stefano zaghi enrico cavallini and renato n . elias 07-01-2008

description

This is a document that explain hoe to create a vtk file with fortran

Transcript of Lib Vtk Io Guide

Page 1: Lib Vtk Io Guide

L I B V T K I O

vtk input/output fortran library

Version 0.2

stefano zaghi

enrico cavallini and renato n . elias

07-01-2008

Page 2: Lib Vtk Io Guide

acknowledgements

I am very grateful to Renato N. Elias: whitout his support lib vtk io would not born. Asa matter of facts lib vtk io is a collection of his tips. Despite the fact that Renato does notwrite 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 Win-dows version of lib vtk io and he is the first co-author that I found.

Finally I thank the ParaView mailing list for the great support of its members.

ii

Page 3: Lib Vtk Io Guide

introduction

I have not failed. I’ve just found ten thousandways that don’t work.

Thomas Edison

LIB VTK IO is a Fortran library to write and read (actually only to write) data conformingthe VTK standard both binary and ascii. Even though there are many wrappers/porting

of the VTK source code (C++ code), there is not a fortran one. This library is not a porting or awrapper of the VTK code, but it only an exporter/importer of the VTK data format written inpure 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...) withoutmixing fortran with C++ language.

The library is still in developing and testing, this is first usable release, but there are not allthe 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 isusable 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 appendixE). 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 forthe computer grafich, for the images processing and for 3D rendering. It is widely used in theworld and so it has a very large comunity of users; besides the Kitware1 company providesprofessional support. The toolkit is written in C++ and a lot of porting/wrappers for Tcl/Tk,Java and Python are provided; unlucky there aren’t wrappers for Fortran.

Because of its good features the VTK toolkit has been used to develop a large set of opensource programs. For my work the most important family of programs is the scientific visu-alization programs. A lot of high-quality scientific visualization tool are available on the webbut for me the best is ParaView: I think that it is one of the best scintific visualization programin 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

Page 4: Lib Vtk Io Guide

paraview

ParaView2 is an open source software voted to scientific visualization and able to use thepower of parallel architectures. It has an architecture client-server in order to make easy theremote visualization of very large set of data. Because it is based on VTK it inherits all VTKfeatures. ParaView is very useful for Computational Fluid Dynamics visualizations because itprovides powerful post-processing tools; it provides a very large set of importers for the mostused format like Plot3D and HDF (the list is very large). It is easy to extend ParaView becauseit 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 for-tran/c++ code this is not the easiest way. Fortran is still the best language for high perfor-mance computing for scientific purpose, like CFD computing. It necessary a tool to deal withVTK standard directly by fortran code. The library lib vtk io was made to fill this empty:it is a simple fortran module able to export native fortran data into VTK data format and toimport VTK data into a fortran code (actually this feature is missing), both in ascii and binaryfile format.

The library provides an automatic way to deal with VTK data format: all the formattingprocesses is nested into the library and the users comunicate with it by a simple API passingonly 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 isnot a stable release, but the exporter is quite complete and its API is quite stable. The exporteris usable and I use it for my work.

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

iv

Page 5: Lib Vtk Io Guide

news and changes

version v0 .2

The version v0.2 is the second testing release. From version v0.1 there are only minorchanges; this new version does not introduce new features and does not fix bugs: it

is a simple code-cleaning. The character variables are now case-insensitive; the names ofsome variables have been changed. The comments have been translated in English (very poortranslation...).

List of changes fromv0.1

1. variable formato is changed in output format and now appears only in VTK INI and inVTK INI XML.

2. variable nomefile is changed in filename.

3. variable titolo is changed in title.

4. variable topologia is changed in mesh topology and now appears only in VTK INI andin 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 integratedin the code. The code has particular comments: if the code is processed by the program

v

Page 6: Lib Vtk Io Guide

FortranDOC3 a latex source of this guide will be made; compiling the latex file with “pdflatex”you will obtain this guide in PDF.

version v0 .1

The version v0.1 is the first 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-formatfortran code generates a pretty-latex documentation file of the code structure.

vi

Page 7: Lib Vtk Io Guide

contents

Acknowledgements ii

Introduction iii

News and Changes v

I Compile and Install LIB VTK IO 1

1 Compile LIB VTK IO 2

1.1 Compile under GNU/Linux 3

1.2 Compile under MS Windows 3

2 Install and Link (Pre)Compiled LIB VTK IO 4

2.1 GNU/Linux 4

2.1.1 Static Library 4

2.1.2 Dynamic Library 5

2.2 MS Windows 6

3 LIB VTK IO Programming Style 7

II LIB VTK IO API 9

4 Module LIB VTK IO 10

5 Auxiliary functions 13

5.1 Function GetUnit 13

5.2 Function Upper Case 14

6 VTK LEGACY functions 16

6.1 Function VTK INI 16

6.2 VTK GEO 17

6.2.1 VTK GEO STRUCTURED POINTS 18

6.2.2 VTK GEO STRUCTURED GRID 19

6.2.3 VTK GEO RECTILINEAR GRID 20

6.2.4 VTK GEO UNSTRUCTURED GRID 21

vii

Page 8: Lib Vtk Io Guide

Contents

6.3 Function VTK CON 22

6.4 Function VTK DAT 24

6.5 VTK VAR 25

6.5.1 VTK VAR SCALAR DATA 25

6.5.2 VTK VAR REAL VECTORIAL DATA 26

6.5.3 VTK VAR INTEGER VECTORIAL DATA 27

6.5.4 VTK VAR TEXTURE DATA 28

6.6 Function VTK END 29

7 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

7.2.3 VTK GEO XML UNSTRUCTURED GRID 36

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

7.6 Function VTK END XML 43

a LIB VTK IO Usage Example 44

a.1 Legacy Rectilinear Grid 44

a.2 XML Rectilinear Grid 45

a.3 Legacy Unstructured Grid 46

a.4 XML Unstructured Grid 49

b Fortran & Portable-Kind-Precision Selection 52

c Dynamic Dispatching 54

d Known Bugs 56

e GNU GENERAL PUBLIC LICENSE 57

viii

Page 9: Lib Vtk Io Guide

Part I

C O M P I L E A N D I N S T A L L L I B V T K I O

Page 10: Lib Vtk Io Guide

1compile lib vtk io

Contents1.1 Compile under GNU/Linux 31.2 Compile under MS Windows 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 aminor upgrade to the Fortran 90 standard and that is widely supported by the almost allcompilers actually available. Unluckily Fortran 95 does not allow the creation of C-binary file(Fortran inserts some bytes before and after each records despite the C standard) that is thestandard adopted by VTK. Therefore in order to create binary files that are compatible whitVTK standard the only way is to use a non-standard 95 instructions. At today only Fortran2003 can create C-binary file, but there are not any compilers that completely implement thisstandard. In the next year (2008) maybe a new minor upgrade of Fortran standard (unofficialnamed Fortran 2008) will be born and so the support to Fortran 2003/2008 probably will beimproved. Luckily we need to use only some features of fortran 2003 that are supported bymany compilers.

The Fortran 2003 instructions are focused on the opening of the binary file, in particular inthe functions vtk ini and vtk ini xml. In these functions there are opening instructionslike the following:

Fortran 2003instructionsopen(unit = ..., &

file = ..., &form = ..., &access = ..., &action = ..., &convert = ’BIG_ENDIAN’, &

2

Page 11: Lib Vtk Io Guide

1.1 compile under gnu/linux

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

The specifiers convert, recordtype and buffered are non standard for Fortran 95. Thebuffered specifier is not necessary and so can be commented or eliminated. The specifiersconvert and recordtype are instead necessary to write binary file but can be replacedby other specifiers/instructions. In particular an alternative is opening the file with the spec-ifier form = binary

1 and using a compiler’s option2 to ensure the big endian encoding.big endian encoding is strictly necessary only for legacy binary file; for XML binary file onecan 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 instructionsizeof. This instruction is used to comptuing the number of bytes of the saved data in theXML binary files. Maybe there are others alternatives that are Fortran 95 compatible but at themoment I have not the time to implement them.

Before you compile lib vtk io ensure that your compiler allows these Fortran 2003 exten-sions. I use the Intel Fortran Compiler3 that is free for non-commercial use and it has a strongsupport 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 yourcode. It is a self-contained module that can be safely included into others fortran codes. Thereare no any advices for compile lib vtk io excluding the above non standard instructions.

For the GNU/Linux users there is available a makefile already set to compile lib vtk io

both as static and dynamic library with Intel Fortran. The makefile has only one option:shared. This variable (default set to “no”) can assume two values:

1. no: makefile creates a static library

2. yes: makefile 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 Iwill make available a MS Visual Studio Project to compile lib vtk io with Intel Visual Fortranfor Windows.

1 Remember that also the value binary for form specifier 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 specifier and by compiling option.3 http://www.intel.com.

3

Page 12: Lib Vtk Io Guide

2install and link (pre)compiled

lib vtk io

Contents2.1 GNU/Linux 4

2.1.1 Static Library 4

2.1.2 Dynamic Library 5

2.2 MS Windows 6

The lib vtk io is distribuited in two different version (other than source code): the firstis a static linking version (extensions are .a and .lib) and the second is dynamic linking

version (extensions are .so and .dll). The use of these two version is different and it dependson the OS used. The library is been tested only on GNU/Linux (several different distro) andon MS Windows (Windows XP).

The library is distribuited with two different archive: lib vtk io-bin-x .x.tar for GNU/Linuxsystems and lib vtk io-bin-x .x.zip for MS Windows systems. Into the archives there is thesource code of the library (lib vtk io.f90), there are both static and dynamic version of thelibrabry 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 instal-lations. It is enough to link against it in the linking phase. It is important to use the interfacemodule lib vtk io.mod distribuited with the library: this is the interface of the subroutines andfunctions that constitute the library.

4

Page 13: Lib Vtk Io Guide

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:

The lib vtk io

must to be loaded withthe USE statement

program testUSE LIB_VTK_IO.........endprogram test

With the instruction USE LIB\_VTK\_IO the program test can use the functions and subrou-tines of the library. To compile, without link, this code one must give the module interfacelib vtk io.mod to the compiler:

Static CompilingPhaseifort -c lib_vtk_io.mod test.f90 -o test.o

In this example ifort is the Intel Fortran Compiler1 and the -c flag compiles preventinglinking; the compiler must “see” the module interface: the file lib vtk io.mod must be placed ina 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 mustknow where is the library so it is necessary to install the library in a folder where the OS searchits shared objects. In the most of the GNU/Linux distro the folder /usr/lib/ is scanned to findshared objects. After you have copied the lib vtk io.so file in this folder, update the list ofthe 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 (rememberto you the module interface at the compiling phase). The only difference is to use the dynamiclibrary at the linking phase:

Dynamic LinkingPhaseifort test.o LIB_VTK_IO.so -o test.out

1 Da aggiungere.

5

Page 14: Lib Vtk Io Guide

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 thetime, I make some instructions on how use lib vtk io with MS Visual Studio and Intel VisualFortran for MS Windows.

6

Page 15: Lib Vtk Io Guide

3lib vtk io programming style

All the lib vtk io functions are 4-byte integer functions: the output of these func-tions is an integer that is 0 if the function calling has been done right while it is > 0 if

some errors occur (the error handling is only at its embryonal phase). Therefore the functionscalling 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 kind-precision of reals and integers variables and dynamic dispatching. In the appendix Band C there are more details about these choices. I just remark some consequences of thesechoices. Using dynamic dispatching the lib vtk io has a simple API. The user calls ageneric procedure (VTK INI, VTK GEO,...) and the library, depending on the type of the in-puts passed, calls the correct internal function (i.e. VTK GEO for 8-byte real type if the inputpassed is 8-byte real type). By this interface only few functions are used whitout the neces-sity 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 functionVTK GEO is the same for all topologies, just the inputs passed to the functions change as thetopology 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. dy-namic dispatching is based on the internal kind-precision selecting convention: Fortran90/95 standard has some useful functions to achive the portability of reals and integers pre-cision and lib vtk io uses these functions to define portable kind-precision; because it is

7

Page 16: Lib Vtk Io Guide

important to make portable the code on different architectures I suggest to use this program-ming style.

The data handled by lib vtk io can be classified into two main categories:

1. Geometric Data. These are the geometric informations of the mesh and they can beof different kind and different number depending on the topology choiced. The meshpoints 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 of8-byte real type, 4-byte real type and 4-byte integer type (for the XML output there arealso 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.

8

Page 17: Lib Vtk Io Guide

Part II

L I B V T K I O A P I

Page 18: Lib Vtk Io Guide

4module lib vtk io

lib vtk io is a library of functions for Input and Output pure fortran data (both ascii andbinary) 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 supportfrom VTk comunity than legacy standard; XML file format would to be preferred despite thelegacy one.

At the present only a few functions of the final library have been implemented. The InPutfunctions are totaly absent, but the OutPut functions are almost complete (the “polydata”functions are the only missing).

The functions actually present are:

Functions for LegacyVTK file format

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 XMLVTK file format

1. V T K I N I X M L

2. V T K G E O X M L

10

Page 19: Lib Vtk Io Guide

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 publicvisibility.

The lib vtk io uses a partable kind parameters for real and integer variables. The fol-lowing are the kind parameters used: these parameters are public and their use is strongencouraged.

Real precision definitions:

lib vtk io variables

integer , parameter : : R16P = s e l e c t e d r e a l k i n d ( 3 3 , 4 9 3 1 ) ! 33 digits, range [±10−4931,±10+4931 − 1]

integer , parameter : : R8P = s e l e c t e d r e a l k i n d ( 1 5 , 3 0 7 ) ! 15 digits, range [±10−307 ,±10+307 − 1]

integer , parameter : : R4P = s e l e c t e d r e a l k i n d ( 6 , 3 7 ) ! 6 digits, range [±10−37 ,±10+37 − 1]integer , parameter : : R P = R8P ! default real precision

Integer precision definitions:

lib vtk io variables

integer , parameter : : I8P = s e l e c t e d i n t k i n d ( 1 8 ) ! range [−263, +263 − 1]

integer , parameter : : I4P = s e l e c t e d i n t k i n d ( 9 ) ! range [−231, +231 − 1]

integer , parameter : : I2P = s e l e c t e d i n t k i n d ( 4 ) ! range [−215, +215 − 1]

integer , parameter : : I1P = s e l e c t e d i n t k i n d ( 2 ) ! range [−27 , +27 − 1]integer , parameter : : I P = I4P ! default integer precision

Besides the kind parameters there are also the format parameters useful for writing in awell-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 : : FR16P = '(E41.33E4)' ! R16P output formatc h a r a c t e r ( 1 0 ) , parameter : : FR8P = '(E23.15E3)' ! R8P output formatc h a r a c t e r ( 9 ) , parameter : : FR4P = '(E14.6E2)' ! R4P output formatc h a r a c t e r ( 1 0 ) , parameter : : FR P = '(E23.15E3)' ! R P output format

Integer output formats:

11

Page 20: Lib Vtk Io Guide

lib vtk io variables

c h a r a c t e r ( 5 ) , parameter : : FI8P = '(I21)' ! I8P output formatc h a r a c t e r ( 5 ) , parameter : : FI4P = '(I12)' ! I4P output formatc h a r a c t e r ( 4 ) , parameter : : FI2P = '(I7)' ! I2P output formatc h a r a c t e r ( 4 ) , parameter : : FI1P = '(I5)' ! I1P output formatc h a r a c t e r ( 5 ) , parameter : : FI P = '(I12)' ! I P output format

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

lib vtk io variables

in teger ( I4P ) , parameter : : maxlen = 500 ! max number of characters os static stringc h a r a c t e r ( 1 ) , parameter : : e n d r e c = c h a r ( 1 0 ) ! end-character for binary-record finalizein teger ( I4P ) , parameter : : f o u t a s c i i = 0 ! ascii-output-format parameter identifierin teger ( I4P ) , parameter : : f o u t b i n a r y = 1 ! binary-output-format parameter identifierin teger ( I4P ) : : f o u t = f o u t a s c i i ! current output-format (initialized to ascii format)c h a r a c t e r ( len=maxlen ) : : t o p o l o g y ! mesh topologyin teger ( I4P ) : : Unit VTK ! internal logical unitin teger ( I4P ) : : Unit VTK Append ! internal logical unit for raw binary XML append filein teger ( I4P ) : : N Byte ! number of byte to be written/readr e a l ( R8P ) : : t i p o R 8 ! prototype of R8P realr e a l ( R4P ) : : t i p o R 4 ! prototype of R4P realin teger ( I8P ) : : t i p o I 8 ! prototype of I8P integerin teger ( I4P ) : : t i p o I 4 ! prototype of I4P integerin teger ( I2P ) : : t i p o I 2 ! prototype of I2P integerin teger ( I1P ) : : t i p o I 1 ! prototype of I1P integerin teger ( I4P ) : : i o f f s e t ! offset pointerin teger ( I4P ) : : i n d e n t ! indent pointer

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

12

Page 21: Lib Vtk Io Guide

5auxiliary functions

Contents5.1 Function GetUnit 135.2 Function Upper Case 14

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 notknow 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 unitsused lib vtk io will never use these units, but will choice one that is free.

getunit variables

in teger ( I4P ) : : F r e e U n i t ! free logic unitin teger ( I4P ) : : n1 ! counterin teger ( I4P ) : : i o s ! inquiring flagl o g i c a l ( 4 ) : : l o p e n ! inquiring flag

13

Page 22: Lib Vtk Io Guide

5.2 function upper case

The following is the code snippet of GetUnit function: the units 0, 5, 6, 9 and all non-free unitsare discarded.

GetUnit Code Snippet

516 F r e e U n i t = −1 I4P ! initializing free logic unit517 n1=1 I4P ! initializing counter518 do519 i f ( ( n1/=5 I4P ) .AND . ( n1/=6 I4P ) .AND . ( n1/=9 I4P ) ) then520 inquire ( unit=n1 , opened= l open , i o s t a t = i o s ) ! verify logic units521 i f ( i o s ==0 I4P ) then522 i f ( .NOT . l o p e n ) then523 F r e e U n i t = n1 ! assignment of free logic524 return525 endif526 endif527 endif528 n1=n1+1 I4P ! updating counter529 enddo530 return

GetUnit function is private and cannot be called outside lib vtk io . If you are interestedto 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 variablesused within lib vtk io functions are pre-processed by Uppper Case function before thesevariables are used. So the users can call lib vtk io functions whitout pay attention of thecase of the kwywords passed to the functions: calling the function VTK INI with the stringE 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 en t ( IN ) : : s t r i n g ! string to be convertedc h a r a c t e r ( len=len ( s t r i n g ) ) : : Upper Case ! converted stringin teger : : n1 ! characters counter

The following is the code snippet of Upper Case function.

Upper Case CodeSnippet

14

Page 23: Lib Vtk Io Guide

5.2 function upper case

557 Upper Case = s t r i n g558 do n1 =1 , len ( s t r i n g )559 s e l e c t case ( i c h a r ( s t r i n g ( n1 : n1 ) ) )560 case ( 9 7 : 1 2 2 )561 Upper Case ( n1 : n1 )= c h a r ( i c h a r ( s t r i n g ( n1 : n1 )) −32) ! Upper case conversion562 endselect563 enddo564 return

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

15

Page 24: Lib Vtk Io Guide

6vtk legacy functions

Contents6.1 Function VTK INI 166.2 VTK GEO 17

6.2.1 VTK GEO STRUCTURED POINTS 18

6.2.2 VTK GEO STRUCTURED GRID 19

6.2.3 VTK GEO RECTILINEAR GRID 20

6.2.4 VTK GEO UNSTRUCTURED GRID 21

6.3 Function VTK CON 226.4 Function VTK DAT 246.5 VTK VAR 25

6.5.1 VTK VAR SCALAR DATA 25

6.5.2 VTK VAR REAL VECTORIAL DATA 26

6.5.3 VTK VAR INTEGER VECTORIAL DATA 27

6.5.4 VTK VAR TEXTURE DATA 28

6.6 Function VTK END 29

6 .1 function vtk ini

vtk ini signature

function 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

Page 25: Lib Vtk Io Guide

6.2 vtk geo

The VTK INI function is used for initializing file. This function must be the first to be called.

vtk ini variables

c h a r a c t e r ( * ) , i n t en t ( IN ) : : o u t p u t f o r m a t ! output format: ASCII or BINARYc h a r a c t e r ( * ) , i n t en t ( IN ) : : f i l e n a m e ! name of filec h a r a c t e r ( * ) , i n t en t ( IN ) : : t i t l e ! titlec h a r a c t e r ( * ) , i n t en t ( IN ) : : m e s h t o p o l o g y ! mesh topologyin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 file. It can assume the following values:

A. ascii (it is case insensitive)→ creating an ascii output file.B. binary (it is case insensitive)→ creating a binary (big endian encoding) output file.

filename contains the name (with its path) of the output file.

title contains the title of the VTK dataset.

topology indicates the topology of the mesh and can assume the following values:

A. STRUCTURED POINTS.B. STRUCTURED GRID.C. UNSTRUCTURED GRID.D. RECTILINEAR GRID.

E IO contains the inquiring integer flag 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 file name.

6 .2 vtk geo

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

17

Page 26: Lib Vtk Io Guide

6.2 vtk geo

6 .2 .1 vtk geo structured points

vtk geo structured points signature

function 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 discretizationsteps.

vtk geo structured points variables

in teger ( I4P ) , i n t en t ( IN ) : : Nx ! number of nodes in x directionin teger ( I4P ) , i n t en t ( IN ) : : Ny ! number of nodes in y directionin teger ( I4P ) , i n t en t ( IN ) : : Nz ! number of nodes in z directionr e a l ( R8P or R4P ) , i n t en t ( IN ) : : X0 ! x coordinate of originr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Y0 ! y coordinate of originr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Z0 ! z coordinate of originr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Dx ! space step in xr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Dy ! space step in yr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Dz ! space step in zin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 4-byte real kind; the dynamic displacement interface will call the correct function. Mixing 8-bytereal kind and 4-byte real kind is not allowed: be sure that all variables are 8-byte real kind orall 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 flag for error handling.

The following is an example of VTK GEO structured point calling:

VTK GEO StructuredPoints Calling

18

Page 27: Lib Vtk Io Guide

6.2 vtk geo

...integer(4):: Nx,Ny,Nzreal(8):: X0,Y0,Z0real(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

function 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 discretizationsteps.

vtk geo structured grid variables

in teger ( I4P ) , i n t en t ( IN ) : : Nx ! number of nodes in x directionin teger ( I4P ) , i n t en t ( IN ) : : Ny ! number of nodes in y directionin teger ( I4P ) , i n t en t ( IN ) : : Nz ! number of nodes in z directionin teger ( I4P ) , i n t en t ( IN ) : : NN ! number of all nodesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : X ( 1 :NN) ! x coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Y ( 1 :NN) ! y coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Z ( 1 :NN) ! z coordinatesin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 and4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-bytereal 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

Page 28: Lib Vtk Io Guide

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 flag for error handling.

The following is an example of VTK GEO structured grid calling:

VTK GEO StructuredGrid Calling...

integer(4), parameter:: Nx=10,Ny=10,Nz=10integer(4), parameter:: Nnodi=Nx*Ny*Nzreal(8):: X(1:Nnodi),Y(1:Nnodi),Z(1:Nnodi)...E_IO = VTK_GEO(Nx,Ny,Nz,Nnodi,X,Y,Z)...

6 .2 .3 vtk geo rectilinear grid

vtk geo rectilinear grid signature

function 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 discretizationsteps even in generalized coordinates.

vtk geo rectilinear grid signature

in teger ( I4P ) , i n t en t ( IN ) : : Nx ! number of nodes in x directionin teger ( I4P ) , i n t en t ( IN ) : : Ny ! number of nodes in y directionin teger ( I4P ) , i n t en t ( IN ) : : Nz ! number of nodes in z directionr e a l ( R8P or R4P ) , i n t en t ( IN ) : : X ( 1 : Nx ) ! x coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Y ( 1 : Ny ) ! y coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Z ( 1 : Nz ) ! z coordinatesin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 and4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-bytereal 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

Page 29: Lib Vtk Io Guide

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 flag for error handling.

The following is an example of VTK GEO rectilinear grid calling:

VTK GEO RectilinearGrid Calling...

integer(4), parameter:: Nx=10,Ny=20,Nz=30real(4):: X(1:Nx),Y(1:Ny),Z(1:Nz)...E_IO = VTK_GEO(Nx,Ny,Nz,X,Y,Z)...

6 .2 .4 vtk geo unstructured grid

vtk geo unstructured grid signature

function 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 meshformat. This topology is also useful for scructured mesh in order to save only a non-structuredclip of mesh.

vtk geo unstructured grid variables

in teger ( I4P ) , i n t en t ( IN ) : : NN ! number of nodesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : X ( 1 :NN) ! x coordinates of all nodesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Y ( 1 :NN) ! y coordinates of all nodesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Z ( 1 :NN) ! z coordinates of all nodesin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 and4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-bytereal 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

Page 30: Lib Vtk Io Guide

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 flag for error handling.

The following is an example of VTK GEO unstructured grid calling:

VTK GEOUnstructured GridCalling

...integer(4), parameter:: NN=100real(4):: X(1:NN),Y(1:NN),Z(1:NN)...E_IO = VTK_GEO(NN,X,Y,Z)...

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

6 .3 function vtk con

vtk con signature

function VTK CON(NC, connec 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 theunstructured mesh.

vtk con variables

in teger ( I4P ) , i n t en t ( IN ) : : NC ! number of cellsin teger ( I4P ) , i n t en t ( IN ) : : c o n n e c t ( : ) ! mesh connectivityin teger ( I4P ) , i n t en t ( IN ) : : c e l l t y p e ( 1 :NC) ! VTK cell typein teger ( I4P ) : : E IO ! Input/Output inquiring flag: 0 if IO is done, > 0 if IO is not donec h a r a c t e r ( len=maxlen ) : : s b u f f e r ! buffer stringin teger ( I4P ) : : ncon ! 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 flag for error handling.

22

Page 31: Lib Vtk Io Guide

6.3 function vtk con

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

dc = NC +

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 first sight. Itis more simple analizing an example. Suppose we have a mesh composed by 2 cells, onehexahedron (8 vertices) and one pyramid with square basis (5 vertices); suppose that the basisof pyramid is constitute by a face of the hexahedron and so the two cells share 4 vertices. Theequation 6.1 gives dc = 2 + 8 + 5 = 15; the connectivity vector for this mesh can be:

Connectivity vectorexample for VTKlegacy standard

! first cellconnect(1) = 8 => number of vertices of 1 cellconnect(2) = 0 => identification flag of 1 vertex of 1 cellconnect(3) = 1 => identification flag of 2 vertex of 1 cellconnect(4) = 2 => identification flag of 3 vertex of 1 cellconnect(5) = 3 => identification flag of 4 vertex of 1 cellconnect(6) = 4 => identification flag of 5 vertex of 1 cellconnect(7) = 5 => identification flag of 6 vertex of 1 cellconnect(8) = 6 => identification flag of 7 vertex of 1 cellconnect(9) = 7 => identification flag of 8 vertex of 1 cell! second cellconnect(10) = 5 => number of vertices of 2 cellconnect(11) = 0 => identification flag of 1 vertex of 2 cellconnect(12) = 1 => identification flag of 2 vertex of 2 cellconnect(13) = 2 => identification flag of 3 vertex of 2 cellconnect(14) = 3 => identification flag of 4 vertex of 2 cellconnect(15) = 8 => identification flag of 5 vertex of 2 cell

Note that the first 4 identification flags of pyramid vertices as the same of the first 4 identi-fication flags of the hexahedron because the two cells share this face. It is also important tonote that the identification flags start form 0 value: this is impose to the VTK standard. Thefunction VTK CON does not calculate the connectivity vector: it writes the connectivity vectorconforming 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 vectorexample for VTKlegacy standardtipo(1) = 12 => VTK hexahedron type of 1 cell

tipo(2) = 14 => VTK pyramid type of 2 cell

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

23

Page 32: Lib Vtk Io Guide

6.4 function vtk dat

The following is an example of VTK CON calling:

VTK CON Calling

...integer(4), parameter:: NC=2integer(4), parameter:: Nvertex1=8integer(4), parameter:: Nvertex2=5integer(4), parameter:: dc=NC+Nvertex1+Nvertex2integer(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

function 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 functioninitializes the saving of data variables indicating the type of variables that will be saved.

vtk dat variables

in teger ( I4P ) , i n t en t ( IN ) : : NC NN ! number of cells or nodes of fieldc h a r a c t e r ( * ) , i n t en t ( IN ) : : v a r l o c a t i o n ! location of saving variables: cell for cell-centered, node for node-centeredin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 0 if IO is done, > 0 if IO is not donec h a r a c t e r ( len=maxlen ) : : s b u f f e r ! 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 ascalar 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 flag for error handling.

24

Page 33: Lib Vtk Io Guide

6.5 vtk var

Of course a single file can contain both cell and node centered variables; in this case theVTK DAT function must be called two times, before saving cell-centered variables and beforesaving 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 datavariables related to geometric mesh. The inputs that must be passed change depending on thedata variables type.

6 .5 .1 vtk var scalar data

vtk var scalar data signature

function VTK VAR ( f o rmato ,NC NN, varname , var ) r e s u l t ( E IO )

This kind of call is used to save scalar data.

vtk var scalar data variables

in teger ( I4P ) , i n t en t ( IN ) : : NC NN ! number of nodes or cellsc h a r a c t e r ( * ) , i n t en t ( IN ) : : varname ! variable namer e a l ( R8P or R4P ) or in teger ( I4P ) , i n t en t ( IN ) : : var ( 1 :NC NN) ! variable to be savedin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 toVTK 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 flag for error handling.

25

Page 34: Lib Vtk Io Guide

6.5 vtk var

Note that the variables var can be passed both as 8-byte real kind, 4-byte real kind and4-byte integer; the dynamic displacement interface will call the correct function.

The following is an example of VTK VAR scalar data calling:

VTK VAR Scalar DataCalling...

integer(4), parameter:: NC_NN=100real(4):: var(1:NC_NN)...E_IO = VTK_VAR(NC_NN,’Scalar Data’,var)...

6 .5 .2 vtk var real vectorial data

vtk var real vectorial data signature

function 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

c h a r a c t e r ( * ) , i n t en t ( IN ) : : v e c t y p e ! vector type: vect = generic vector , norm = normal vectorin teger ( I4P ) , i n t en t ( IN ) : : NC NN ! number of nodes or cellsc h a r a c t e r ( * ) , i n t en t ( IN ) : : varname ! variable namer e a l ( R8P or R4P ) , i n t en t ( IN ) : : varX ( 1 :NC NN) ! x component of vectorr e a l ( R8P or R4P ) , i n t en t ( IN ) : : varY ( 1 :NC NN) ! y component of vectorr e a l ( R8P or R4P ) , i n t en t ( IN ) : : varZ ( 1 :NC NN) ! z component of vectorin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 toVTK 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

Page 35: Lib Vtk Io Guide

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 flag for error handling.

Note that the variables varX,varY,varZ can be passed both as 8-byte real kind and 4-bytereal kind; the dynamic displacement interface will call the correct function.

The following is an example of VTK VAR real vectorial data calling:

VTK VAR RealVectorial Data Calling...

integer(4), parameter:: NC_NN=100real(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)...

6 .5 .3 vtk var integer vectorial data

vtk var integer vectorial data signature

function 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

in teger ( R4P ) , i n t en t ( IN ) : : NC NN ! number of nodes or cellsc h a r a c t e r ( * ) , i n t en t ( IN ) : : varname ! variable namein teger ( R4P ) , i n t en t ( IN ) : : varX ( 1 :NC NN) ! x component of vectorin teger ( R4P ) , i n t en t ( IN ) : : varY ( 1 :NC NN) ! y component of vectorin teger ( R4P ) , i n t en t ( IN ) : : varZ ( 1 :NC NN) ! z component of vectorin teger ( R4P ) : : E IO ! Input/Output inquiring flag: 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 toVTK 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

Page 36: Lib Vtk Io Guide

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 flag for error handling.

The following is an example of VTK VAR real vectorial data calling:

VTK VAR IntegerVectorial Data Calling...

integer(4), parameter:: NC_NN=100integer(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)...

6 .5 .4 vtk var texture data

vtk var texture data signature

function 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

in teger ( R4P ) , i n t en t ( IN ) : : NC NN ! number of nodes or cellsin teger ( R4P ) , i n t en t ( IN ) : : dimm ! texture dimensionsc h a r a c t e r ( * ) , i n t en t ( IN ) : : varname ! variable namer e a l ( R8P or R4P ) , i n t en t ( IN ) : : t e x t C o o ( 1 : NC NN , 1 : dimm ) ! texturein teger ( R4P ) : : E IO ! Input/Output inquiring flag: 0 if IO is done, > 0 if IOis 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 toVTK DAT.

dimm indicates the dimensions of the texture coordinates. It can assume the value:

A. 1→ scalar texture.B. 2→ twodimensional texture.

28

Page 37: Lib Vtk Io Guide

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 flag 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:

VTK VAR TextureData Calling...

integer(4), parameter:: NC_NN=100integer(4), parameter:: dimm=2real(4):: textCoo(1:NC_NN,1:dimm)...E_IO = VTK_VAR(NC_NN,dimm,’Texture Data’,textCoo)...

6 .6 function vtk end

vtk end signature

function VTK END ( ) r e s u l t ( E IO )

This function is used to finalize the file opened and it has not inputs. The lib vtk io

manages the file unit without the user’s action.

vtk end variables

in teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 flag for error handling.

The following is an example of VTK END calling:

VTK END Calling

29

Page 38: Lib Vtk Io Guide

6.6 function vtk end

...E_IO = VTK_END()...

30

Page 39: Lib Vtk Io Guide

7vtk xml functions

Contents7.1 Function VTK INI XML 327.2 VTK GEO XML 33

7.2.1 VTK GEO XML STRUCTURED GRID 33

7.2.2 VTK GEO XML RECTILINEAR GRID 34

7.2.3 VTK GEO XML UNSTRUCTURED GRID 36

7.2.4 VTK GEO XML CLOSE PIECE 37

7.3 Function VTK CON XML 377.4 Function VTK DAT XML 407.5 VTK VAR XML 41

7.5.1 VTK VAR XML SCALAR DATA 41

7.5.2 VTK VAR XML VECTORIAL DATA 42

7.6 Function VTK END XML 43

The XML standard is more powerful than legacy one. It is more flexible and free but on theother hand is more (but not so more using a library like lib vtk io ...) complex than

legacy standard. The output of XML functions is a well-formated XML file at least for the asciiformat (in the binary format lib vtk io use raw-data format that does not produce a wellformated XML file).

The XML functions follow the same calling-convention of the legacy functions; all thelib vtk io XML functions are 4-byte integer function: the output of these functionsis an integer that is 0 if the function calling has been done right while it is > 0 if some errorsoccur. The functions calling is the same as legacy functions:

Functions Calling

...

31

Page 40: Lib Vtk Io Guide

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 suffix “ XML”.

7 .1 function vtk ini xml

vtk ini xml signature

function 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 ) r e s u l t ( E IO )

The VTK INI XML function is used for initializing file. This function must be the first to becalled.

vtk ini xml variables

c h a r a c t e r ( * ) , i n t en t ( IN ) : : o u t p u t f o r m a t ! output format: ASCII or BINARYc h a r a c t e r ( * ) , i n t en t ( IN ) : : f i l e n a m e ! file namec h a r a c t e r ( * ) , i n t en t ( IN ) : : m e s h t o p o l o g y ! mesh topologyin teger ( I4P ) , i n t en t ( IN ) , optional : : nx1 , nx2 ! initial and final nodes of x axisin teger ( I4P ) , i n t en t ( IN ) , optional : : ny1 , ny2 ! initial and final nodes of y axisin teger ( I4P ) , i n t en t ( IN ) , optional : : nz1 , nz2 ! initial and final nodes of z axisin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 0 if IO is done, > 0 if IO is

not donec h a r a c t e r ( len=maxlen ) : : s b u f f e r ! buffer string

The VTK INI XML variables have the following meaning:

output format indicates the “format” of output file. It can assume the following values:

A. ascii (it is case insensitive)→ creating an ascii output file.B. binary (it is case insensitive)→ creating a binary (big endian encoding) output file.

filename contains the name (with its path) of the output file.

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 final.

ny1,ny2 contains the extent of Y axis; ny1 is the initial node and ny2 is the final.

nz1,nz2 contains the extent of Z axis; nz1 is the initial node and nz2 is the final.

32

Page 41: Lib Vtk Io Guide

7.2 vtk geo xml

E IO contains the inquiring integer flag 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 file.

The following is an example of VTK INI XML calling:

VTK INI XMLCalling...

...E_IO = VTK_INI_XML(’BINARY’,’XML_RECT_BINARY.vtr’, &

’RectilinearGrid’, &nx1=nx1,nx2=nx2, &ny1=ny1,ny2=ny2, &nz1=nz1,nz2=nz2)

...

Note that the file extension is necessary in the file name. The XML standard has differentextensions for each different topologies (i.e. .vtr for rectilinear topology). See the VTK-standard file 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 topolo-gies 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 VTKtopologies have been implemented (“polydata” topologies are absent). The signatures for allimplemented topologies are now reported.

7 .2 .1 vtk geo xml structured grid

vtk geo xml structured grid signature

function 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 discretizationsteps.

vtk geo xml structured grid variables

in teger ( I4P ) , i n t en t ( IN ) : : nx1 , nx2 ! initial and final nodes of x axisin teger ( I4P ) , i n t en t ( IN ) : : ny1 , ny2 ! initial and final nodes of y axisin teger ( I4P ) , i n t en t ( IN ) : : nz1 , nz2 ! initial and final nodes of z axis

33

Page 42: Lib Vtk Io Guide

7.2 vtk geo xml

in teger ( I4P ) , i n t en t ( IN ) : : NN ! number of all nodesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : X ( 1 :NN) ! x coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Y ( 1 :NN) ! y coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Z ( 1 :NN) ! z coordinatesin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 and4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-bytereal 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 final.

ny1,ny2 contains the extent of Y axis; ny1 is the initial node and ny2 is the final.

nz1,nz2 contains the extent of Z axis; nz1 is the initial node and nz2 is the final.

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 flag for error handling.

The following is an example of VTK GEO XML structured grid calling:

VTK GEO XMLStructured GridCalling

...integer(4):: nx1,nx2integer(4):: ny1,ny2integer(4):: nz1,nz2integer(4):: NNreal(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)

...

7 .2 .2 vtk geo xml rectilinear grid

34

Page 43: Lib Vtk Io Guide

7.2 vtk geo xml

vtk geo xml rectilinear grid signature

function 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 discretizationsteps even in generalized coordinates.

vtk geo xml rectilinear grid variables

in teger ( I4P ) , i n t en t ( IN ) : : nx1 , nx2 ! initial and final nodes of x axisin teger ( I4P ) , i n t en t ( IN ) : : ny1 , ny2 ! initial and final nodes of y axisin teger ( I4P ) , i n t en t ( IN ) : : nz1 , nz2 ! initial and final nodes of z axisr e a l ( R8P or R4P ) , i n t en t ( IN ) : : X( nx1 : nx2 ) ! x coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Y ( ny1 : ny2 ) ! y coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Z ( nz1 : nz2 ) ! z coordinatesin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 and4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-bytereal 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 final.

ny1,ny2 contains the extent of Y axis; ny1 is the initial node and ny2 is the final.

nz1,nz2 contains the extent of Z axis; nz1 is the initial node and nz2 is the final.

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 flag for error handling.

The following is an example of VTK GEO XML rectilinear grid calling:

VTK GEO XMLStructured GridCalling

...integer(4):: nx1,nx2integer(4):: ny1,ny2integer(4):: nz1,nz2real(4):: X(nx1:nx2),Y(ny1:ny2),Z(nz1:nz2)...E_IO = VTK_GEO_XML(nx1,nx2,ny1,ny2,nz1,nz2, &

X,Y,Z)...

35

Page 44: Lib Vtk Io Guide

7.2 vtk geo xml

7 .2 .3 vtk geo xml unstructured grid

vtk geo xml unstructured grid signature

function VTK GEO XML( Nnodi , NCelle , X , Y , Z ) r e s u l t ( E IO )

The topology “unstructured grid” is necessary for unstructured grid, the most general meshformat. This topology is also useful for scructured mesh in order to save only a non-structuredclip of mesh.

vtk geo xml unstructured grid variables

in teger ( I4P ) , i n t en t ( IN ) : : NN ! number of nodesin teger ( I4P ) , i n t en t ( IN ) : : NC ! number of cellsr e a l ( R8P or R4P ) , i n t en t ( IN ) : : X ( 1 :NN) ! x coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Y ( 1 :NN) ! y coordinatesr e a l ( R8P or R4P ) , i n t en t ( IN ) : : Z ( 1 :NN) ! z coordinatesin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 and4-byte real kind is not allowed: be sure that all variables are 8-byte real kind or all are 4-bytereal 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 flag for error handling.

The following is an example of VTK GEO XML unstructured grid calling:

VTK GEO XMLUnstructured GridCalling

...integer(4), parameter:: Nnodi=100integer(4), parameter:: NCelle=50real(4):: X(1:Nnodi),Y(1:Nnodi),Z(1:Nnodi)...E_IO = VTK_GEO_XML(’ascii’,Nnodi,NCelle,X,Y,Z)...

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

36

Page 45: Lib Vtk Io Guide

7.3 function vtk con xml

7 .2 .4 vtk geo xml close piece

vtk geo xml close piece signature

function VTK GEO XML ( ) r e s u l t ( E IO )

As we said before the XML standard is more powerful than legacy. XML file can containmore 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 file. 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 file.

vtk geo xml close piece variables

in teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 flag for error handling.

The following is an example of VTK GEO XML close piece calling:

VTK GEO XMLUnstructured GridCalling

...E_IO = VTK_GEO_XML()...

7 .3 function vtk con xml

vtk con xml signature

function VTK CON XML(NC, connec 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 theunstructured mesh.

vtk con xml variables

in teger ( I4P ) , i n t en t ( IN ) : : NC ! number of cellsin teger ( I4P ) , i n t en t ( IN ) : : c o n n e c t ( : ) ! mesh connectivityin teger ( I4P ) , i n t en t ( IN ) : : o f f s e t ( 1 :NC) ! cell offset

37

Page 46: Lib Vtk Io Guide

7.3 function vtk con xml

in teger ( I1P ) , i n t en t ( IN ) : : c e l l t y p e ( 1 :NC) ! VTK cell typein teger ( I4P ) : : E IO ! Input/Output inquiring flag: 0 if IO is done, > 0 if IO is not donec h a r a c t e r ( len=maxlen ) : : s b u f f e r ! buffer stringin teger ( I4P ) : : n1 ! 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.

offset 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 flag 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 dimen-sions can be calculated by the following equation:

dc =

NCelle∑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 connectivityconvention is quite different from the legacy standard. As an example considering the samemesh 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 constituteby a face of the hexahedron and so the two cells share 4 vertices. The equation 7.1 givesdc = 8 + 5 = 13; the connectivity vector for this mesh can be:

Connectivity vectorexample for VTKXML standard

! first cellconnect(1) = 0 => identification flag of 1 vertex of 1 cellconnect(2) = 1 => identification flag of 2 vertex of 1 cellconnect(3) = 2 => identification flag of 3 vertex of 1 cellconnect(4) = 3 => identification flag of 4 vertex of 1 cellconnect(5) = 4 => identification flag of 5 vertex of 1 cellconnect(6) = 5 => identification flag of 6 vertex of 1 cellconnect(7) = 6 => identification flag of 7 vertex of 1 cellconnect(8) = 7 => identification flag of 8 vertex of 1 cell! second cellconnect(9) = 0 => identification flag of 1 vertex of 2 cellconnect(10) = 1 => identification flag of 2 vertex of 2 cellconnect(11) = 2 => identification flag of 3 vertex of 2 cellconnect(12) = 3 => identification flag of 4 vertex of 2 cellconnect(13) = 8 => identification flag of 5 vertex of 2 cell

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

38

Page 47: Lib Vtk Io Guide

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 con-nect vector. The offset vector for this mesh can be:

Offset vector examplefor VTK XMLstandard

! first celloffset(1) = 8 => summ of nodes of 1 cell! second celloffset(2) = 13 => summ of nodes of 1 and 2 cells

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

offsetc =

c∑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 calculatethem. In the future release of lib vtk io will be included a function to calculate the connec-tivity and offset vector.

The vector variable tipo must conform the VTK XML standard 2 that is the same of thelegacy standard presented previous (sec. ??). It contains the type of each cells. For the aboveexample this vector is:

Cell-Type vectorexample for VTKlegacy standard

tipo(1) = 12 => VTK hexahedron type of 1 celltipo(2) = 14 => VTK pyramid type of 2 cell

The following is an example of VTK CON XML calling:

VTK CON XMLCalling...

integer(4), parameter:: NCelle=2integer(4), parameter:: Nvertex1=8integer(4), parameter:: Nvertex2=5integer(4), parameter:: dc=Nvertex1+Nvertex2integer(4):: connect(1:dc)integer(4):: offset(1:NCelle)integer(4):: tipo(1:NCelle)...E_IO = VTK_CON_XML(NCelle,connect,offset,tipo)...

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

39

Page 48: Lib Vtk Io Guide

7.4 function vtk dat xml

7 .4 function vtk dat xml

vtk dat xml signature

function 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 functioninitializes 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 en t ( IN ) : : v a r l o c a t i o n ! location of saving variables: CELL for cell-centered, NODE fornode-centered

c h a r a c t e r ( * ) , i n t en t ( IN ) : : v a r b l o c k a c t i o n ! variables block action: OPEN or CLOSE blockin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 ascalar 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 assumethe 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 flag for error handling.

Of course a single file 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, andafter the block-data-variables has been saved in order to close the block. XML file can containsas many blocks as you want.

The following is an example of VTK DAT XML calling:

VTK DAT XMLCalling...

E_IO = VTK_DAT_XML(’node’,’OPEN’)...SAVE YOUR DATA WITH VTK_VAR_XML...E_IO = VTK_DAT_XML(’node’,’CLOSE’)...

40

Page 49: Lib Vtk Io Guide

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 vari-ables (1 for each supported precision: R8P, R4P, I8P, I4P, I2P and I1P) and 6 for vectorial vari-ables (1 for each supported precision: R8P, R4P, I8P, I4P, I2P and I1P) This function saves thedata variables related to geometric mesh. The inputs that must be passed change dependingon the data variables type.

7 .5 .1 vtk var xml scalar data

vtk var xml scalar data signature

function VTK VAR XML(NC NN, varname , var ) r e s u l t ( E IO )

This kind of call is used to save scalar data.

vtk var xml scalar data variables

in teger ( I4P ) , i n t en t ( IN ) : : NC NN ! number of cells or nodesc h a r a c t e r ( * ) , i n t en t ( IN ) : : varname ! variable namer e a l ( R8P or . . .

R4P ) or . . .in teger ( I8P or . . .

I4P or . . .I2P or . . .I1P ) , i n t en t ( IN ) : : var ( 1 :NC NN) ! variable to be saved

in teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 locationpassed 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 flag for error handling.

Note that the variables var can be passed both 8-byte real kind, 4-byte real kind, 8-byteinteger, 4-byte integer, 2-byte integer and 1-byte integer; XML is very flexible; the dynamicdisplacement interface will call the correct function.

The following is an example of VTK VAR XML scalar data calling:

VTK VAR XMLScalar Data Calling

41

Page 50: Lib Vtk Io Guide

7.5 vtk var xml

...integer(4), parameter:: NC_NN=100integer(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

function 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

in teger ( I4P ) , i n t en t ( IN ) : : NC NN ! number of cells or nodesc h a r a c t e r ( * ) , i n t en t ( IN ) : : varname ! variable namer e a l ( R8P or R4P ) or . . .in teger ( I8P or I4P or I2P or I1P ) , i n t en t ( IN ) : : varX ( 1 :NC NN) ! x componentr e a l ( R8P or R4P ) or . . .in teger ( I8P or I4P or I2P or I1P ) , i n t en t ( IN ) : : varY ( 1 :NC NN) ! y componentr e a l ( R8P or R4P ) or . . .in teger ( I8P or I4P or I2P or I1P ) , i n t en t ( IN ) : : varZ ( 1 :NC NN) ! z componentin teger ( I4P ) : : E IO ! Input/Output inquiring flag: 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 locationpassed 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 flag for error handling.

Note that the variables varX,varY,varZ can be passed both 8-byte real kind, 4-byte realkind, 8-byte integer, 4-byte integer, 2-byte integer and 1-byte integer; XML is very flexible; thedynamic displacement interface will call the correct function.

42

Page 51: Lib Vtk Io Guide

7.6 function vtk end xml

The following is an example of VTK VAR XML vectorial data calling:

VTK VAR XMLVectorial Data Calling...

integer(4), parameter:: NC_NN=100integer(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)...

7 .6 function vtk end xml

vtk end xml signature

function VTK END XML ( ) r e s u l t ( E IO )

This function is used to finalize the file opened. The lib vtk io manages the file unitwithout the user’s action.

vtk end xml variables

in teger ( I4P ) : : E IO ! Input/Output inquiring flag: 0 if IO is done, > 0 if IO is not donec h a r a c t e r ( 2 ) : : v a r t y p e ! var type = R8,R4,I8,I4,I2,I1r e a l ( R8P ) , a l l o c a t a b l e : : v R8 ( : ) ! R8 vector for IO in AppendDatar e a l ( R4P ) , a l l o c a t a b l e : : v R4 ( : ) ! R4 vector for IO in AppendDatain teger ( I8P ) , a l l o c a t a b l e : : v I 8 ( : ) ! I8 vector for IO in AppendDatain teger ( I4P ) , a l l o c a t a b l e : : v I 4 ( : ) ! I4 vector for IO in AppendDatain teger ( I2P ) , a l l o c a t a b l e : : v I 2 ( : ) ! I2 vector for IO in AppendDatain teger ( I1P ) , a l l o c a t a b l e : : v I 1 ( : ) ! I1 vector for IO in AppendDatain teger ( I4P ) : : N v ! vector dimensionin teger ( I4P ) : : n1 ! counter

The following is an example of VTK END XML calling:

VTK END XMLCalling...

E_IO = VTK_END_XML()...

43

Page 52: Lib Vtk Io Guide

Alib vtk io usage example

Contentsa.1 Legacy Rectilinear Grid 44a.2 XML Rectilinear Grid 45a.3 Legacy Unstructured Grid 46a.4 XML Unstructured Grid 49

The usage of lib vtk io is quite simple. In this chapter there are some example of lib vtk io

usage. Some of the following examples are present also in the file test lib vtk io .f90

distributed within the lib vtk io .

a .1 legacy rectilinear grid

Legacy RectilinearGrid...

integer(4), intent(IN):: Nxreal(8), intent(IN):: p(1:Nx)real(8), intent(IN):: rho(1:Nx)real(8), intent(IN):: u(1:Nx)real(8), intent(IN):: gamma(1:Nx)character(*), intent(IN):: filenamereal(8):: x(1:Nx)integer(4):: i...x=(/(i, i=1, Nx, 1)/)

44

Page 53: Lib Vtk Io Guide

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), intent(IN):: ninteger(4), intent(IN):: Nxreal(8), intent(IN):: p(1:Nx)real(8), intent(IN):: rho(1:Nx)real(8), intent(IN):: u(1:Nx)real(8), intent(IN):: gamma(1:Nx)character(*), intent(IN):: filenamereal(8):: x(1:Nx)integer(4):: i

45

Page 54: Lib Vtk Io Guide

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

Legacy UnstructuredGrid...

integer(4), parameter:: Nn = 27integer(4), parameter:: Ne = 11real(4), dimension(1:Nn):: x_unsreal(4), dimension(1:Nn):: y_unsreal(4), dimension(1:Nn):: z_unsinteger(4), dimension(1:Ne):: tipointeger(4), dimension(1:60):: connectreal(8), dimension(1:Nn):: var_uns_grid

46

Page 55: Lib Vtk Io Guide

A.3 legacy unstructured grid

integer(4), dimension(1:Nn):: var_uns_grid_Xinteger(4), dimension(1:Nn):: var_uns_grid_Yinteger(4), dimension(1:Nn):: var_uns_grid_Z...E_IO = VTK_INI(output_format = ’BINARY’, &

filename = ’UNST_GRID_BIN.vtk’, &title = ’Unstructured Grid Example’ &mesh_topology = ’UNSTRUCTURED_GRID’)

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/)

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

Page 56: Lib Vtk Io Guide

A.3 legacy unstructured grid

5, &3, &1/)

E_IO = VTK_CON(NCelle = Ne, &connect = connect, &tipo = tipo)

E_IO = VTK_DAT(NC_NN = Nn, &tipo = ’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

Page 57: Lib Vtk Io Guide

A.4 xml unstructured grid

a .4 xml unstructured grid

XML UnstructuredGrid...

integer(4), parameter:: Nn = 27integer(4), parameter:: Ne = 11real(4), dimension(1:Nn):: x_unsreal(4), dimension(1:Nn):: y_unsreal(4), dimension(1:Nn):: z_unsinteger(4), dimension(1:Ne):: tipointeger(4), dimension(1:49):: connect_xmlinteger(4), dimension(1:Ne):: offset_xmlreal(8), dimension(1:Nn):: var_uns_gridinteger(4), dimension(1:Nn):: var_uns_grid_Xinteger(4), dimension(1:Nn):: var_uns_grid_Yinteger(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/)

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

Page 58: Lib Vtk Io Guide

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 = Ne, &connect = connect_xml, &offset = offset_xml, &tipo = (/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 = ’node’, &azione = ’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

Page 59: Lib Vtk Io Guide

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 = Nn, &varname = ’vector’, &varX = var_uns_grid_X, &varY = var_uns_grid_Y, &varZ = var_uns_grid_Z)

E_IO = VTK_DAT_XML(tipo = ’node’, &azione = ’CLOSE’)

E_IO = VTK_GEO_XML()E_IO = VTK_END_XML()...

51

Page 60: Lib Vtk Io Guide

Bfortran & portable-kind-precision

selection

Fortran is the most popular programming language for scientific computing. With fortranit is quite simple obtain fast code and manage large multidimensional array. Because

fortran permits the achivment of high performance it is also used on great range of differentcomputer-architettures, and often on the fastest supercomputer in the world. Therefore fortranprograms must be portable: portability means that the code will give the same results onevery different computer-architettures. One of the most important goal of the numeric code isto control the the numeric error due to finite precision of numerical operations. Fortranuses the ieee rappresentations; integers and reals (floating point) are represented witha finite precision. So when the code computes an operation it has a trunction error dueto the truncation of the numerical finite rappresentaions. For numerical and more in generalscientific applications this source of errors must be controlled. The programmer must knowwhich is the precision associated to the code variables. Before the standard fortran 90/95 thereare not any way to select the precision of the numerical variables in a portable fashion. Withthe possibility to specify a kind parameter for variables, the standard fortran 90/95 makesavaible 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:: pinteger, intent(IN), optional:: rinteger:: 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 ofthe kind parameter of a real data type with decimalprecision, as returned by the function PRECISION, of at

52

Page 61: Lib Vtk Io Guide

least p digits and a decimal exponent range, as returnedby the function RANGE, of at least r.

function selected_int_kind(p) result(kind_id)integer, intent(IN), optional:: pinteger:: kind_id

The result, kind_id, is a scalar of type default integer.The result has a value equal to the value of the kindparameter of the integer data type that represents allvalues 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 ownvariables in a portable manner. Note that specifing the kind precision without using thesetwo 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 libraryare defined some parameters by which all variables kind-precisions are parametrized:

lib vtk io

Kind-PrecisionParameters

R E A L P R E C I S I O N D E F I N I T I O N S

R16P real with 33 digits, range [+ − 10−4931, + − 10+4931 − 1]

R8P real with 15 digits, range [+ − 10−307, + − 10+307 − 1]

R4P real with 6 digits, range [+ − 10−37, + − 10+37 − 1]

I N T E G E R P R E C I S I O N D E F I N I T I O N S

I8P range [−263, +263 − 1]

I4P range [−231, +231 − 1]

I2P range [−215, +215 − 1]

I1P range [−27, +27 − 1]

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

53

Page 62: Lib Vtk Io Guide

Cdynamic dispatching

Fortran is not an object oriented (OOp) programming language. It is a procedurallanguage with some of the the goals (ineritance, user-definited data type, polimorphism...)

of OOp. Fortran most important aim is to ensure the performance of the code not its “friend-liness”... Despite its nature, fortran 90/95 makes avaible some interesting features: it permitsthe dynamic dispatching of functions and subroutine ensuring the best performance. This goalis achived with use of interface construct. In the lib vtk io there are, at today, 4 interfaceblocks:

lib vtk io InterfaceBlocksinterface 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_VARmodule 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

54

Page 63: Lib Vtk Io Guide

endinterface

interface VTK_GEO_XMLmodule 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_XMLmodule 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 fewfunctions without non-sense-long-name... Dynamic dispatching is not the magic wand tosolve all problems but it is an useful tool to simplify the code API. It is not powerful asthe C++ template, but it is a quantum-leap for fortran programmers.

55

Page 64: Lib Vtk Io Guide

Dknown bugs

The lib vtk io is a very young project and it is a good example of wrong programmingstyle... It is unstable and not tested. It is used by only one user (... me of course!) and

there are a lot of bugs that are still hidden. At the moment several features are missing (theinput functions and the poly-data topology...), but it is useful to export fortran data to VTKstandard, and this goal was the most important for me.

At today only one main bug was found. Fortran allows the automatic reshape of arrays: asan example 2D array can be automatically (in the function calling) transformed to a 1D arraywith the same number of element of 2D array. The use of dynamic dispatching had disablethis 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 nextrelease I will fix this bug introducing the function to reshape arrays between 1D, 2D and 3Darrays.

A possible, not already found, bug is the non correct kind detection. It is possible that acode uses kind-precision parameter that does not match the lib vtk io parameters. I neverobserve 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,define new parameters in lib vtk io and redistribuite lib vtk io with your pacth!

Finally there is a strong inefficiency when saving XML binary file. To write XML binarylib vtk io uses a temporary scratch file to save binary data while saving all formatting datato the final XML file; only when all XML formatting data have been written the scratch file isrewinded and the binary data is saved in the final tag of XML file as raw data. This algorithmis obviously inefficient. Any tip is welcome!

56

Page 65: Lib Vtk Io Guide

Egnu general public license

V E R S I O N 3 , 2 9 J U N E 2 0 0 7

Copyright © 2007 Free Software Foundation, Inc. http://fsf.org/

Everyone is permitted to copy and distribute verbatim copies of thislicense document, but changing it is not allowed.

preamble

The GNU General Public License is a free, copyleft license for software and other kinds ofworks.

The licenses for most software and other practical works are designed to take away yourfreedom to share and change the works. By contrast, the GNU General Public License isintended to guarantee your freedom to share and change all versions of a program–to makesure it remains free software for all its users. We, the Free Software Foundation, use the GNUGeneral Public License for most of our software; it applies also to any other work released thisway 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 PublicLicenses are designed to make sure that you have the freedom to distribute copies of freesoftware (and charge for them if you wish), that you receive source code or can get it if youwant it, that you can change the software or use pieces of it in new free programs, and thatyou know you can do these things.

To protect your rights, we need to prevent others from denying you these rights or askingyou to surrender the rights. Therefore, you have certain responsibilities if you distribute copiesof 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, youmust pass on to the recipients the same freedoms that you received. You must make sure thatthey, too, receive or can get the source code. And you must show them these terms so theyknow their rights.

57

Page 66: Lib Vtk Io Guide

Developers that use the GNU GPL protect your rights with two steps: (1) assert copyrighton the software, and (2) offer you this License giving you legal permission to copy, distributeand/or modify it.

For the developers’ and authors’ protection, the GPL clearly explains that there is no war-ranty for this free software. For both users’ and authors’ sake, the GPL requires that modifiedversions be marked as changed, so that their problems will not be attributed erroneously toauthors of previous versions.

Some devices are designed to deny users access to install or run modified versions of thesoftware inside them, although the manufacturer can do so. This is fundamentally incompati-ble with the aim of protecting users’ freedom to change the software. The systematic patternof such abuse occurs in the area of products for individuals to use, which is precisely whereit is most unacceptable. Therefore, we have designed this version of the GPL to prohibit thepractice for those products. If such problems arise substantially in other domains, we standready to extend this provision to those domains in future versions of the GPL, as needed toprotect the freedom of users.

Finally, every program is threatened constantly by software patents. States should not allowpatents to restrict development and use of software on general-purpose computers, but inthose that do, we wish to avoid the special danger that patents applied to a free programcould make it effectively proprietary. To prevent this, the GPL assures that patents cannot beused to render the program non-free.

The precise terms and conditions for copying, distribution and modification follow.

Terms and Conditions

0. Definitions.

“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 assemiconductor masks.

“The Program” refers to any copyrightable work licensed under this License. Each li-censee is addressed as “you”. “Licensees” and “recipients” may be individuals or orga-nizations.

To “modify” a work means to copy from or adapt all or part of the work in a fashionrequiring copyright permission, other than the making of an exact copy. The resultingwork is called a “modified version” of the earlier work or a work “based on” the earlierwork.

A “covered work” means either the unmodified Program or a work based on the Pro-gram.

To “propagate” a work means to do anything with it that, without permission, wouldmake you directly or secondarily liable for infringement under applicable copyright law,except executing it on a computer or modifying a private copy. Propagation includescopying, distribution (with or without modification), making available to the public, andin some countries other activities as well.

To “convey” a work means any kind of propagation that enables other parties to makeor receive copies. Mere interaction with a user through a computer network, with notransfer of a copy, is not conveying.

58

Page 67: Lib Vtk Io Guide

An interactive user interface displays “Appropriate Legal Notices” to the extent that itincludes a convenient and prominently visible feature that (1) displays an appropriatecopyright notice, and (2) tells the user that there is no warranty for the work (except tothe extent that warranties are provided), that licensees may convey the work under thisLicense, and how to view a copy of this License. If the interface presents a list of usercommands 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 modifi-cations to it. “Object code” means any non-source form of a work.

A “Standard Interface” means an interface that either is an official standard defined by arecognized standards body, or, in the case of interfaces specified for a particular program-ming 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 asa whole, that (a) is included in the normal form of packaging a Major Component, butwhich is not part of that Major Component, and (b) serves only to enable use of thework with that Major Component, or to implement a Standard Interface for which animplementation is available to the public in source code form. A “Major Component”, inthis context, means a major essential component (kernel, window system, and so on) ofthe specific operating system (if any) on which the executable work runs, or a compilerused 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 codeneeded to generate, install, and (for an executable work) run the object code and to mod-ify the work, including scripts to control those activities. However, it does not include thework’s System Libraries, or general-purpose tools or generally available free programswhich are used unmodified in performing those activities but which are not part of thework. For example, Corresponding Source includes interface definition files associatedwith source files for the work, and the source code for shared libraries and dynamicallylinked subprograms that the work is specifically designed to require, such as by intimatedata communication or control flow between those subprograms and other parts of thework.

The Corresponding Source need not include anything that users can regenerate automat-ically 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 Pro-gram, and are irrevocable provided the stated conditions are met. This License explicitlyaffirms your unlimited permission to run the unmodified Program. The output fromrunning 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 otherequivalent, as provided by copyright law.

You may make, run and propagate covered works that you do not convey, without condi-tions so long as your license otherwise remains in force. You may convey covered worksto others for the sole purpose of having them make modifications exclusively for you, or

59

Page 68: Lib Vtk Io Guide

provide you with facilities for running those works, provided that you comply with theterms 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 yourbehalf, under your direction and control, on terms that prohibit them from making anycopies of your copyrighted material outside their relationship with you.

Conveying under any other circumstances is permitted solely under the conditions statedbelow. 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 underany applicable law fulfilling obligations under article 11 of the WIPO copyright treatyadopted on 20 December 1996, or similar laws prohibiting or restricting circumventionof such measures.

When you convey a covered work, you waive any legal power to forbid circumvention oftechnological measures to the extent such circumvention is effected by exercising rightsunder this License with respect to the covered work, and you disclaim any intention tolimit operation or modification of the work as a means of enforcing, against the work’susers, your or third parties’ legal rights to forbid circumvention of technological mea-sures.

4. Conveying Verbatim Copies.

You may convey verbatim copies of the Program’s source code as you receive it, in anymedium, provided that you conspicuously and appropriately publish on each copy anappropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all noticesof the absence of any warranty; and give all recipients a copy of this License along withthe Program.

You may charge any price or no price for each copy that you convey, and you may offersupport or warranty protection for a fee.

5. Conveying Modified Source Versions.

You may convey a work based on the Program, or the modifications to produce it fromthe Program, in the form of source code under the terms of section 4, provided that youalso meet all of these conditions:

a) The work must carry prominent notices stating that you modified it, and giving arelevant date.

b) The work must carry prominent notices stating that it is released under this Licenseand any conditions added under section 7. This requirement modifies the require-ment in section 4 to “keep intact all notices”.

c) You must license the entire work, as a whole, under this License to anyone whocomes into possession of a copy. This License will therefore apply, along with anyapplicable 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 licensethe work in any other way, but it does not invalidate such permission if you haveseparately received it.

60

Page 69: Lib Vtk Io Guide

d) If the work has interactive user interfaces, each must display Appropriate LegalNotices; however, if the Program has interactive interfaces that do not display Ap-propriate Legal Notices, your work need not make them do so.

A compilation of a covered work with other separate and independent works, which arenot by their nature extensions of the covered work, and which are not combined with itsuch 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 tolimit the access or legal rights of the compilation’s users beyond what the individualworks permit. Inclusion of a covered work in an aggregate does not cause this License toapply 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 and5, provided that you also convey the machine-readable Corresponding Source under theterms of this License, in one of these ways:

a) Convey the object code in, or embodied in, a physical product (including a phys-ical distribution medium), accompanied by the Corresponding Source fixed on adurable physical medium customarily used for software interchange.

b) Convey the object code in, or embodied in, a physical product (including a phys-ical distribution medium), accompanied by a written offer, valid for at least threeyears and valid for as long as you offer spare parts or customer support for thatproduct model, to give anyone who possesses the object code either (1) a copy ofthe Corresponding Source for all the software in the product that is covered by thisLicense, on a durable physical medium customarily used for software interchange,for a price no more than your reasonable cost of physically performing this convey-ing of source, or (2) access to copy the Corresponding Source from a network serverat no charge.

c) Convey individual copies of the object code with a copy of the written offer toprovide the Corresponding Source. This alternative is allowed only occasionallyand 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 acharge), and offer equivalent access to the Corresponding Source in the same waythrough the same place at no further charge. You need not require recipients to copythe Corresponding Source along with the object code. If the place to copy the objectcode 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, pro-vided you maintain clear directions next to the object code saying where to find theCorresponding Source. Regardless of what server hosts the Corresponding Source,you remain obligated to ensure that it is available for as long as needed to satisfythese requirements.

e) Convey the object code using peer-to-peer transmission, provided you inform otherpeers where the object code and Corresponding Source of the work are being offeredto the general public at no charge under subsection 6d.

A separable portion of the object code, whose source code is excluded from the Corre-sponding Source as a System Library, need not be included in conveying the object code

61

Page 70: Lib Vtk Io Guide

work.

A “User Product” is either (1) a “consumer product”, which means any tangible personalproperty which is normally used for personal, family, or household purposes, or (2)anything designed or sold for incorporation into a dwelling. In determining whether aproduct is a consumer product, doubtful cases shall be resolved in favor of coverage. Fora particular product received by a particular user, “normally used” refers to a typical orcommon use of that class of product, regardless of the status of the particular user orof 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 hassubstantial commercial, industrial or non-consumer uses, unless such uses represent theonly significant mode of use of the product.

“Installation Information” for a User Product means any methods, procedures, autho-rization keys, or other information required to install and execute modified versions of acovered work in that User Product from a modified version of its Corresponding Source.The information must suffice to ensure that the continued functioning of the modifiedobject code is in no case prevented or interfered with solely because modification hasbeen made.

If you convey an object code work under this section in, or with, or specifically for usein, a User Product, and the conveying occurs as part of a transaction in which the rightof possession and use of the User Product is transferred to the recipient in perpetuity orfor a fixed term (regardless of how the transaction is characterized), the CorrespondingSource 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 abilityto install modified object code on the User Product (for example, the work has beeninstalled in ROM).

The requirement to provide Installation Information does not include a requirement tocontinue to provide support service, warranty, or updates for a work that has been mod-ified or installed by the recipient, or for the User Product in which it has been modifiedor installed. Access to a network may be denied when the modification itself materiallyand adversely affects the operation of the network or violates the rules and protocols forcommunication across the network.

Corresponding Source conveyed, and Installation Information provided, in accord withthis section must be in a format that is publicly documented (and with an implementationavailable to the public in source code form), and must require no special password orkey for unpacking, reading or copying.

7. Additional Terms.

“Additional permissions” are terms that supplement the terms of this License by makingexceptions from one or more of its conditions. Additional permissions that are applicableto the entire Program shall be treated as though they were included in this License, tothe extent that they are valid under applicable law. If additional permissions apply onlyto part of the Program, that part may be used separately under those permissions, butthe entire Program remains governed by this License without regard to the additionalpermissions.

When you convey a copy of a covered work, you may at your option remove any addi-tional permissions from that copy, or from any part of it. (Additional permissions may

62

Page 71: Lib Vtk Io Guide

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, forwhich you have or can give appropriate copyright permission.

Notwithstanding any other provision of this License, for material you add to a coveredwork, you may (if authorized by the copyright holders of that material) supplement theterms of this License with terms:

a) Disclaiming warranty or limiting liability differently from the terms of sections 15

and 16 of this License; orb) Requiring preservation of specified reasonable legal notices or author attributions

in that material or in the Appropriate Legal Notices displayed by works containingit; or

c) Prohibiting misrepresentation of the origin of that material, or requiring that mod-ified versions of such material be marked in reasonable ways as different from theoriginal version; or

d) Limiting the use for publicity purposes of names of licensors or authors of thematerial; or

e) Declining to grant rights under trademark law for use of some trade names, trade-marks, or service marks; or

f) Requiring indemnification of licensors and authors of that material by anyone whoconveys the material (or modified versions of it) with contractual assumptions ofliability to the recipient, for any liability that these contractual assumptions directlyimpose on those licensors and authors.

All other non-permissive additional terms are considered “further restrictions” withinthe meaning of section 10. If the Program as you received it, or any part of it, containsa notice stating that it is governed by this License along with a term that is a furtherrestriction, you may remove that term. If a license document contains a further restric-tion but permits relicensing or conveying under this License, you may add to a coveredwork material governed by the terms of that license document, provided that the furtherrestriction does not survive such relicensing or conveying.

If you add terms to a covered work in accord with this section, you must place, in therelevant source files, a statement of the additional terms that apply to those files, or anotice indicating where to find the applicable terms.

Additional terms, permissive or non-permissive, may be stated in the form of a separatelywritten 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 thisLicense. Any attempt otherwise to propagate or modify it is void, and will automaticallyterminate your rights under this License (including any patent licenses granted underthe third paragraph of section 11).

However, if you cease all violation of this License, then your license from a particularcopyright holder is reinstated (a) provisionally, unless and until the copyright holderexplicitly and finally terminates your license, and (b) permanently, if the copyright holderfails to notify you of the violation by some reasonable means prior to 60 days after thecessation.

63

Page 72: Lib Vtk Io Guide

Moreover, your license from a particular copyright holder is reinstated permanently ifthe copyright holder notifies you of the violation by some reasonable means, this is thefirst time you have received notice of violation of this License (for any work) from thatcopyright holder, and you cure the violation prior to 30 days after your receipt of thenotice.

Termination of your rights under this section does not terminate the licenses of partieswho have received copies or rights from you under this License. If your rights have beenterminated and not permanently reinstated, you do not qualify to receive new licensesfor 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 theProgram. Ancillary propagation of a covered work occurring solely as a consequence ofusing 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 modifyany 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 ofthis License to do so.

10. Automatic Licensing of Downstream Recipients.

Each time you convey a covered work, the recipient automatically receives a license fromthe 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 sub-stantially 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 thattransaction who receives a copy of the work also receives whatever licenses to the workthe party’s predecessor in interest had or could give under the previous paragraph, plusa right to possession of the Corresponding Source of the work from the predecessor ininterest, 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 oraffirmed under this License. For example, you may not impose a license fee, royalty, orother charge for exercise of rights granted under this License, and you may not initiatelitigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patentclaim is infringed by making, using, selling, offering for sale, or importing the Programor any portion of it.

11. Patents.

A “contributor” is a copyright holder who authorizes use under this License of the Pro-gram or a work on which the Program is based. The work thus licensed is called thecontributor’s “contributor version”.

A contributor’s “essential patent claims” are all patent claims owned or controlled by thecontributor, whether already acquired or hereafter acquired, that would be infringed bysome manner, permitted by this License, of making, using, or selling its contributor ver-sion, but do not include claims that would be infringed only as a consequence of further

64

Page 73: Lib Vtk Io Guide

modification of the contributor version. For purposes of this definition, “control” in-cludes the right to grant patent sublicenses in a manner consistent with the requirementsof this License.

Each contributor grants you a non-exclusive, worldwide, royalty-free patent license un-der the contributor’s essential patent claims, to make, use, sell, offer for sale, import andotherwise run, modify and propagate the contents of its contributor version.

In the following three paragraphs, a “patent license” is any express agreement or com-mitment, however denominated, not to enforce a patent (such as an express permissionto practice a patent or covenant not to sue for patent infringement). To “grant” such apatent license to a party means to make such an agreement or commitment not to enforcea patent against the party.

If you convey a covered work, knowingly relying on a patent license, and the Correspond-ing Source of the work is not available for anyone to copy, free of charge and under theterms of this License, through a publicly available network server or other readily acces-sible means, then you must either (1) cause the Corresponding Source to be so available,or (2) arrange to deprive yourself of the benefit of the patent license for this particularwork, or (3) arrange, in a manner consistent with the requirements of this License, to ex-tend the patent license to downstream recipients. “Knowingly relying” means you haveactual knowledge that, but for the patent license, your conveying the covered work in acountry, or your recipient’s use of the covered work in a country, would infringe one ormore identifiable 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 licenseto some of the parties receiving the covered work authorizing them to use, propagate,modify or convey a specific copy of the covered work, then the patent license you grantis 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 therights that are specifically granted under this License. You may not convey a coveredwork if you are a party to an arrangement with a third party that is in the business ofdistributing software, under which you make payment to the third party based on theextent 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 discriminatorypatent license (a) in connection with copies of the covered work conveyed by you (orcopies made from those copies), or (b) primarily for and in connection with specificproducts or compilations that contain the covered work, unless you entered into thatarrangement, 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 orother defenses to infringement that may otherwise be available to you under applicablepatent law.

12. No Surrender of Others’ Freedom.

If conditions are imposed on you (whether by court order, agreement or otherwise) thatcontradict the conditions of this License, they do not excuse you from the conditions ofthis License. If you cannot convey a covered work so as to satisfy simultaneously your

65

Page 74: Lib Vtk Io Guide

obligations under this License and any other pertinent obligations, then as a consequenceyou may not convey it at all. For example, if you agree to terms that obligate you to collecta royalty for further conveying from those to whom you convey the Program, the onlyway you could satisfy both those terms and this License would be to refrain entirely fromconveying the Program.

13. Use with the GNU Affero General Public License.

Notwithstanding any other provision of this License, you have permission to link or com-bine any covered work with a work licensed under version 3 of the GNU Affero GeneralPublic License into a single combined work, and to convey the resulting work. The termsof this License will continue to apply to the part which is the covered work, but thespecial requirements of the GNU Affero General Public License, section 13, concerninginteraction 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 GNUGeneral Public License from time to time. Such new versions will be similar in spirit tothe present version, but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the Program specifies thata 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 thatnumbered version or of any later version published by the Free Software Foundation. Ifthe Program does not specify a version number of the GNU General Public License, youmay choose any version ever published by the Free Software Foundation.

If the Program specifies that a proxy can decide which future versions of the GNU Gen-eral Public License can be used, that proxy’s public statement of acceptance of a versionpermanently authorizes you to choose that version for the Program.

Later license versions may give you additional or different permissions. However, noadditional obligations are imposed on any author or copyright holder as a result of yourchoosing to follow a later version.

15. Disclaimer of Warranty.

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BYAPPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPY-RIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS”WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUD-ING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITYAND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUAL-ITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PRO-GRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVIC-ING, REPAIR OR CORRECTION.

16. Limitation of Liability.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRIT-ING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIESAND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU

66

Page 75: Lib Vtk Io Guide

FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSE-QUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PRO-GRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING REN-DERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR AFAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVENIF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OFSUCH DAMAGES.

17. Interpretation of Sections 15 and 16.

If the disclaimer of warranty and limitation of liability provided above cannot be givenlocal legal effect according to their terms, reviewing courts shall apply local law thatmost closely approximates an absolute waiver of all civil liability in connection with theProgram, unless a warranty or assumption of liability accompanies a copy of the Programin 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 tothe public, the best way to achieve this is to make it free software which everyone canredistribute and change under these terms.

To do so, attach the following notices to the program. It is safest to attach them to thestart of each source file to most effectively state the exclusion of warranty; and each fileshould have at least the “copyright” line and a pointer to where the full notice is found.

<one line to give the program’s 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 itstarts 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

Page 76: Lib Vtk Io Guide

The hypothetical commands show w and show c should show the appropriate parts ofthe General Public License. Of course, your program’s commands might be different; fora GUI interface, you would use an “about box”.

You should also get your employer (if you work as a programmer) or school, if any, tosign a “copyright disclaimer” for the program, if necessary. For more information onthis, 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 pro-prietary programs. If your program is a subroutine library, you may consider it moreuseful to permit linking proprietary applications with the library. If this is what youwant to do, use the GNU Lesser General Public License instead of this License. But first,please readhttp://www.gnu.org/philosophy/why-not-lgpl.html.

68