Gnuastro’s generic data container (
gal_data_t) is a very versatile structure that can be used in many higher-level contexts.
One such higher-level construct is an array of
gal_data_t structures to simplify the allocation (and later cleaning) of several
gal_data_ts that are related.
For example, each column in a table is usually represented by one
gal_data_t (so it has its own name, data type, units, etc.).
A table (with many columns) can be seen as an array of
gal_data_ts (when the number of columns is known a-priori).
The functions below are defined to create a cleared array of data structures and to free them when none are necessary any more.
These functions are declared in gnuastro/data.h which is also visible from the function names (see Gnuastro library).
Allocate an array of
This function will also initialize all the values (
NULL for pointers and 0 for other types).
You can use
gal_data_initialize to fill each element of the array afterwards.
The following code snippet is one example of doing this.
size_t i; gal_data_t *dataarr; dataarr=gal_data_array_calloc(10); for(i=0;i<10;++i) gal_data_initialize(&dataarr[i], ...); ... gal_data_array_free(dataarr, 10, 1);
Free all the
num elements within
dataarr and the actual allocated array.
free_array is not zero, then the
array element of all the datasets will also be freed, see Generic data container (
Allocate an array of pointers to Gnuastro’s generic data structure and initialize all pointers to
This is useful when you want to allocate individual datasets later (for example, with
Free all the individual datasets within the elements of
dataptr, then free
dataptr itself (the array of pointers that was probably allocated with
Read in other formats.
GNU Astronomy Utilities 0.20 manual, April 2023.