add eas3_param_names linked list and functionality to extend
eas3_add_param_name also add eas3_free_data
This commit is contained in:
parent
ae7d48c458
commit
b48525b8e4
2 changed files with 100 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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) !
|
||||
! -------------- !
|
||||
|
|
Loading…
Reference in a new issue