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:
- easel - a C library for biological sequence analysis developed by the Eddy/Rivas laboratory.
- klib
- 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. This wrapper is optional and is not built by default (see Optional HDF5 support below). 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);mkdir build
cd build
cmake ..
make
make testHDF5 support is off by default. To enable it, first install the hdf5 library.
Ubuntu/Debian:
sudo apt-get install -y libhdf5-devOn a mac via brew:
brew install hdf5Then configure with TLD_USE_HDF5 switched on:
cmake -DTLD_USE_HDF5=ON ..When HDF5 is off, TLD_NO_HDF5 is defined for tld and for any target linking against it, and the tld_hdf5_* functions and HDF_* macros are not available.