From b48525b8e4f5940c00f5f20d805b9422ac6269a2 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 16 Oct 2024 10:19:30 +0200 Subject: [PATCH] add eas3_param_names linked list and functionality to extend eas3_add_param_name also add eas3_free_data --- include/interfaces/reader/eas3.h | 18 +++++++ src/interfaces/reader/eas3.c | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index e75dfa2..650d20f 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -332,6 +332,23 @@ uint64_t udef_real_size; } eas3_std_params; + /*----------------------------------------------------------------------------------------------*\ + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! ! + ! This structure is used to store field names eas3 file. ! + ! ! + \*----------------------------------------------------------------------------------------------*/ + typedef struct name + { + char name[24]; // Parameter name. + uint8 id; // Parameter index. + + struct name *next; // Next element in linked-list. + struct name *root; // Linked-list root. + } eas3_param_names; + /*----------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! @@ -342,6 +359,7 @@ \*----------------------------------------------------------------------------------------------*/ typedef struct { + eas3_param_names *param_names; eas3_std_params params; struct field diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 973b778..7752580 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -586,6 +586,88 @@ endian_conversion(void *value, } } +/*----------------------------------------------------------------------------------------------------------*\ +! ! +! DESCRIPTION: ! +! ------------ ! +! This function deallocates the data structure used to store an numerical dataset ! +! and can be called if an error occurs or once the data is no longer needed is to be closed. ! +! The deallocation will be carried out down to the structure levels that have been allocated. ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +void +eas3_free_data(eas3_data* data) +{ + if(data) + { + if(data->aux) + { + free(data->aux->memory); + data->aux->access = NULL; + data->aux->position = 0; + data->aux->size = 0; + // TODO: remove + data->aux->L = 0; + } + free(data->aux); + free(data); + } +} + +void +eas3_add_param_name(eas3_data *const data, char *name) +{ + eas3_param_names *param_names; + assert(data); + param_names = &data->param_names; + /*--------------------------------------------------------*\ + ! Check if the specified parameter name has the proper ! + ! length. ! + \*--------------------------------------------------------*/ + if((strlen(name) > 24) && name) + { + fprintf(stderr, "o==========================================================o\n"\ + "| WARNING: Invalid parameter name: %-24s|\n"\ + "| |\n"\ + "| Parameter names cannot exceed 24 characters. |\n"\ + "| |\n"\ + "o==========================================================o\n",name); + } + + /*--------------------------------------------------------*\ + ! Check if the parameter structure has already been allo- ! + ! cated. ! + \*--------------------------------------------------------*/ + if(data->param_names == NULL) + { + /*--------------------------------------------------------*\ + ! If eas3_add_param_name function is called for the first ! + ! time, allocate the parameter structure and save the root ! + ! node address. ! + \*--------------------------------------------------------*/ + data->param_names = calloc(1, sizeof(eas3_param_names)); + data->param_names->root = data->param_names; + } + else + { + /*--------------------------------------------------------*\ + ! If a new parameter is added, allocate the nex linked ! + ! list node, save the root node address in its structure ! + ! and set the linked list access pointer to the new node. ! + \*--------------------------------------------------------*/ + data->param_names->next = calloc(1, sizeof(eas3_param_names)); + data->param_names->next->root = data->param_names->root; + data->param_names->next->id = data->param_names->id + 1; + data->param_names = data->param_names->next; + } + + /*--------------------------------------------------------*\ + ! Save the name of the new parameter its precision in the ! + ! structure of the new node. ! + \*--------------------------------------------------------*/ + strcpy(data->param_names->name, name ? name : "undefined"); +} + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: uchar read_eas3_header(bwc_data *const data) ! ! -------------- !