GMT_Create_Data with multiple tables

Hello,

I sometimes need to create a GMT_DATASET with multiple tables, each one with a different number of segments of a different number of rows. Let’s say I want nbTables of nbSeg[] segments of nbRows[][] rows, I do it this way right now:


int j, n;
void *API;
struct GMT_DATASET *D = NULL;
uint64_t par[] = {nbTables, 0, 0, 3};

API = GMT_Create_Session("GMT_dataset", 2, 0, NULL);
D = GMT_Create_Data(API, GMT_IS_DATASET, GMT_IS_POINT, GMT_CONTAINER_AND_DATA, par, NULL, NULL, 0, -1, NULL);
for (n = 0; n < nbTables; n++) {
    D->table[n]->n_segments = nbSeg[n];
    D->table[n]->segment = (struct GMT_DATASEGMENT**) calloc(D->table[n]->n_segments, sizeof(struct GMT_DATASEGMENT*));
    for (j = 0; j < D->table[n]->n_segments; j++) 
        D->table[n]->segment[j] = GMT_Alloc_Segment(API, GMT_NO_STRINGS, nbRows[n][j], 3, "test", NULL);
}
// Do some stuff with D
GMT_Destroy_Data(API, &D);
GMT_Destroy_Session(API);

That seems to work, but I’m not sure this is the right way to do it. Especially, I don’t think it is a good idea to alloc the segments in my program (and not in the library) because GMT may then have some problems to free that memory. Shouldn’t we need a GMT_Alloc_Table function ?

Thank you for your help.

Olivier

Some of those tasks are not implemented in the API, but they happen in lower-level functions, such as gmtio_alloc_table and gmt_alloc_dataset and in places in the modules. Of course, the modules include gmt_dev.h and not gmt.h.
Because data sets are much more complicated that, say one grid, perhaps we should add a GMT_Create_Dataset function that lets you specify how many tables, segments per table, and rows per segment for such work.