Skip to content

vtk_fortran_zlib ​

Minimal zlib bindings used for VTK XML internal compression (vtkZLibDataCompressor), compression and decompression.

The module is always compiled: without VTKFORTRAN_USE_ZLIB the procedures are stubs returning an error, and is_zlib_enabled is .false.. With it, the library must be linked with zlib (-lz).

Source: src/lib/vtk_fortran_zlib.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
Z_DEFAULT_COMPRESSIONinteger(kind=c_int)parameterzlib default compression level (currently 6).
Z_BEST_SPEEDinteger(kind=c_int)parameterzlib fastest compression level.
Z_BEST_COMPRESSIONinteger(kind=c_int)parameterzlib best compression level.
is_zlib_enabledlogicalparameterThe library is built with zlib (VTKFORTRAN_USE_ZLIB).

Subroutines ​

zlib_compress_blocks ​

Compress a bytes stream into VTK compressed blocks (vtkZLibDataCompressor layout).

The stream is split into blocks of block_size bytes (the last one can be shorter), each compressed independently. The VTK header of the compressed data is returned as I8P words, its width in the file (UInt32 or UInt64) is chosen by the caller:

 header = [number of blocks, block size, last block size, compressed size of each block]

As VTK writes it, the last block size is the size of a partial last block, 0 when all blocks are full; an empty stream has no blocks. blocks holds the compressed blocks, concatenated.

fortran
subroutine zlib_compress_blocks(bytes, block_size, level, header, blocks, error)

Arguments

NameTypeIntentAttributesDescription
bytesinteger(kind=c_signed_char)inUncompressed bytes.
block_sizeinteger(kind=I8P)inUncompressed block size in bytes.
levelinteger(kind=c_int)inzlib compression level.
headerinteger(kind=I8P)outallocatableVTK header of the compressed data.
blocksinteger(kind=c_signed_char)outallocatableCompressed blocks.
errorintegeroutError status: 0 on success.

Call graph

zlib_uncompress_blocks ​

Decompress VTK compressed blocks (vtkZLibDataCompressor layout) into a bytes stream: the inverse of zlib_compress_blocks.

The header, read from the file as UInt32 or UInt64 words and passed as I8P, is

 header = [number of blocks, block size, last block size, compressed size of each block]

where a last block size of 0 means that the last block is full. blocks holds the compressed blocks, concatenated (it can be longer than their total). The header is checked before decompressing: an inconsistent header, a block that does not decompress to its declared size, or a library built without zlib return a non-zero error.

fortran
subroutine zlib_uncompress_blocks(header, blocks, bytes, error)

Arguments

NameTypeIntentAttributesDescription
headerinteger(kind=I8P)inVTK header of the compressed data.
blocksinteger(kind=c_signed_char)inCompressed blocks.
bytesinteger(kind=c_signed_char)outallocatableUncompressed bytes.
errorintegeroutError status: 0 on success.

Call graph

Functions ​

zlib_compress_bound ​

Upper bound of the compressed size of n bytes (0 without zlib).

Returns: integer(kind=c_long)

fortran
function zlib_compress_bound(n) result(bound)

Arguments

NameTypeIntentAttributesDescription
ninteger(kind=c_long)valueUncompressed size in bytes.

Call graph

zlib_compress2 ​

Compress a byte buffer with zlib compress2 (an error without zlib).

Returns: integer(kind=c_int)

fortran
function zlib_compress2(dst, dst_len, src, src_len, level) result(ret)

Arguments

NameTypeIntentAttributesDescription
dstinteger(kind=c_signed_char)inouttargetCompressed buffer.
dst_leninteger(kind=c_long)inouttargetSize of dst on input, compressed size on output.
srcinteger(kind=c_signed_char)intargetUncompressed buffer.
src_leninteger(kind=c_long)inUncompressed size in bytes.
levelinteger(kind=c_int)inCompression level.

Call graph

zlib_uncompress ​

Decompress a byte buffer with zlib uncompress (an error without zlib).

Returns: integer(kind=c_int)

fortran
function zlib_uncompress(dst, dst_len, src, src_len) result(ret)

Arguments

NameTypeIntentAttributesDescription
dstinteger(kind=c_signed_char)inouttargetUncompressed buffer.
dst_leninteger(kind=c_long)inouttargetSize of dst on input, uncompressed size on output.
srcinteger(kind=c_signed_char)intargetCompressed buffer.
src_leninteger(kind=c_long)inCompressed size in bytes.

Call graph