Skip to content

TimoLassmann/tld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

https://github.com/TimoLassmann/tld/actions/workflows/cmake.yml/badge.svg

tld - a small convenience C library

tld is a small C library containing a bunch of convenient function and macros used by Timo Lassmann. It is under active development and therefore not recommended to be used directly in any serious projects. Nevertheless, it may be useful in demonstrating some interesting C techniques. Inspiration for the library comes from many places including:

  1. easel - a C library for biological sequence analysis developed by the Eddy/Rivas laboratory.
  2. klib
  3. rayfork by Sas Luca

An interesting feature is the galloc macro, a generic malloc wrapper. It takes a pointer and one or two numbers and allocated either an array or a matrix. For example:

double* arr = NULL;
galloc(&arr, 100)

is equivalent to:

double* arr = NULL;
size_t size = sizeof(double) * 100;
if ((arr = malloc(size) == NULL) {                   
        fprintf(stderr,"malloc of size %d failed", size);
        exit(1);
}
memset(p, 0, size);

For a matrix:

uint32_t** mat = NULL;
galloc(&mat,100,100);

All memory allocates with galloc has to be freed by gfree :

gfree(arr); 

galloc support all standard data types (int, float, double) any types found in stdint.h (uint8_t etc…).

tld also contains a simple wrapper for writing and reading hdf5 files. For example this code writes an array to file test.h5

struct hdf5_data* hdf5_data = NULL;
tld_hdf5_open_file(&hdf5_data,"test.h5");
HDF_WRITE_DATA(hdf5_data, "/","MyArrayName",arr);
tld_hdf5_close_file(&hdf5_data);

To read the array back:

double* arr = NULL;
struct hdf5_data* hdf5_data = NULL;
tld_hdf5_open_file(&hdf5_data,"test.h5");
RUN(HDF_READ_DATA(hdf5_data, "/","MyArrayName",&arr));
tld_hdf5_close_file(&hdf5_data);

How to build

tld depends on the hdf5 library. To install on linux:

Ubuntu/Debian:

sudo apt-get install -y libhdf5-dev

On a mac via brew:

brew install hdf5

Then:

mkdir build
cd build
cmake ..
make
make test

About

tld - a small convenience C library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published