[compressed, info] = zmat(eye(10));
original = zmat(compressed, info);
original = zmat(compressed, 0);
isequal(original, eye(10))
[compressed, info] = zmat(data, -9, 'zlib');
data = rand(100, 100);
[zlib_out, info] = zmat(data, 1, 'zlib');
[gzip_out, info] = zmat(data, 1, 'gzip');
[lz4_out, info] = zmat(data, 1, 'lz4');
[lzma_out, info] = zmat(data, 1, 'lzma');
[zstd_out, info] = zmat(data, 1, 'zstd');
data = uint8(rand(100, 100, 50) * 255);
[b_lz4, info] = zmat(data, 1, 'blosc2lz4');
[b_zlib, info] = zmat(data, 1, 'blosc2zlib');
[b_zstd, info] = zmat(data, 1, 'blosc2zstd');
[compressed, info] = zmat(data, -6, 'blosc2lz4', ...
'nthread', 4, 'shuffle', 1, 'typesize', 1);
original = zmat(compressed, info);
#include "zmatlib.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
unsigned char input[] = "ZMat compression test data";
size_t inputsize = strlen((char*)input);
unsigned char *output = NULL;
size_t outputsize = 0;
int status = 0;
zmat_run(inputsize, input, &outputsize, &output,
0, &status, -6);
printf("Compressed: %zu -> %zu bytes\n", inputsize, outputsize);
unsigned char *decoded = NULL;
size_t decodedsize = 0;
zmat_run(outputsize, output, &decodedsize, &decoded,
0, &status, 0);
printf("Decompressed: %s\n", decoded);
free(output);
free(decoded);
return 0;
}
📝 Compile Command:
gcc -o test_zmat test_zmat.c -I../include -L../lib -lzmat -lz -llzma -llz4
📋 Makefile:
CC = gcc
CFLAGS = -I../include -O3 -Wall
LDFLAGS = -L../lib -lzmat -lz -llzma -llz4 -lzstd
test_zmat: test_zmat.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
clean:
rm -f test_zmat
🏗️ CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(zmat_example C)
find_library(ZMAT_LIB zmat PATHS ../lib)
find_library(Z_LIB z)
find_library(LZMA_LIB lzma)
find_library(LZ4_LIB lz4)
add_executable(test_zmat test_zmat.c)
target_include_directories(test_zmat PRIVATE ../include)
target_link_libraries(test_zmat ${ZMAT_LIB} ${Z_LIB} ${LZMA_LIB} ${LZ4_LIB})
program zmat_demo
use iso_c_binding
use zmat_module
implicit none
character(len=100) :: input_str = "ZMat Fortran compression test"
integer(c_size_t) :: input_len, output_len, decoded_len
integer(c_int) :: zipid, status, clevel
type(c_ptr) :: output_ptr, decoded_ptr
character(kind=c_char), pointer :: output(:), decoded(:)
integer :: i
input_len = len_trim(input_str)
zipid = 0
clevel = -6
call zmat_run(input_len, input_str, output_len, &
output_ptr, zipid, status, clevel)
call c_f_pointer(output_ptr, output, [output_len])
print *, "Compressed:", input_len, "->", output_len, "bytes"
call zmat_run(output_len, output, decoded_len, &
decoded_ptr, zipid, status, 0)
call c_f_pointer(decoded_ptr, decoded, [decoded_len])
print *, "Decompressed:", (decoded(i), i=1,decoded_len)
end program zmat_demo
📝 Compile Command:
gfortran -o test_zmat test_zmat.f90 zmat_fortran.f90 \
-I../include -L../lib -lzmat -lz -llzma -llz4
📋 Makefile:
FC = gfortran
FFLAGS = -I../include -O3 -Wall
LDFLAGS = -L../lib -lzmat -lz -llzma -llz4 -lzstd
SOURCES = test_zmat.f90 zmat_fortran.f90
test_zmat: $(SOURCES)
$(FC) $(FFLAGS) -o $@ $^ $(LDFLAGS)
clean:
rm -f test_zmat *.mod *.o
🏗️ CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(zmat_fortran Fortran)
enable_language(Fortran)
find_library(ZMAT_LIB zmat PATHS ../lib)
find_library(Z_LIB z)
find_library(LZMA_LIB lzma)
add_executable(test_zmat test_zmat.f90 zmat_fortran.f90)
target_include_directories(test_zmat PRIVATE ../include)
target_link_libraries(test_zmat ${ZMAT_LIB} ${Z_LIB} ${LZMA_LIB})
str = 'ZMat compression test';
encoded = char(zmat(str, 2, 'base64'));
decoded = char(zmat(encoded, 0, 'base64'));
encoded_full = char(zmat(str, 3, 'base64'));
data = rand(50, 50);
[compressed, info] = zmat(data, 1, 'zlib');
base64_compressed = char(zmat(compressed, 2, 'base64'));