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. 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);
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