feat/api #46

Open
Gregor Weiss wants to merge 56 commits from feat/api into main
2 changed files with 45 additions and 41 deletions
Showing only changes of commit 31ed09982e - Show all commits

View file

@ -369,6 +369,10 @@
} field; } field;
span *aux; span *aux;
uchar *uchar_aux;
uint32 aux_pos;
uint32 aux_len;
} eas3_data; } eas3_data;
/************************************************************************************************************\ /************************************************************************************************************\

View file

@ -231,40 +231,28 @@ eas3_init_stream(uchar* memory, uint32 size, char instr)
} }
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void eas3_emit_chunck(bitstream *const stream, const uchar* string, const uint64 length) !
! -------------- !
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
! ------------ ! ! ------------ !
! This function is used to write an additional chunck of size length to a bwc bitstream. ! ! This macro is used to write an additional chunck of size length to the auxilliary !
! ! ! information. !
! !
! PARAMETERS: !
! ----------- !
! Variable Type Description !
! -------- ---- ----------- !
! stream bitstream* - Structure used to assemble a bwc bit- !
! bitstream. !
! !
! chunck unsigned char* - Memory handle for a data block that is !
! to be written to the bwc bitstream. !
! !
! size unsigned int(64 bit) - Size of the data block. !
! !
! RETURN VALUE: !
! ------------- !
! Type Description !
! ---- ----------- !
! - - !
! !
! DEVELOPMENT HISTORY: !
! -------------------- !
! !
! Date Author Change Id Release Description Of Change !
! ---- ------ --------- ------- --------------------- !
! 22.06.2019 Patrick Vogler B87D120 V 0.1.0 function created !
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
#define aux_push_back(aux, aux_pos, aux_len, chunck, chunck_len) \
{ \
if (aux_pos + chunck_len > aux_len) \
{ \
while(aux_pos + chunck_len > aux_len) \
{ \
aux_len += aux_len / 2; \
} \
aux = realloc(aux, aux_len); \
} \
memcpy(aux + aux_pos, chunck, chunck_len); \
aux_pos += chunck_len; \
}
void void
eas3_emit_chunck(span *const stream, const uchar* chunck, const uint64 size) eas3_emit_chunck(span *const stream, const uchar* chunck, const uint64 size)
{ {
@ -793,8 +781,10 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! block has been chosen arbitrarily and should be large ! ! block has been chosen arbitrarily and should be large !
! enough to prevent excessive reallocation. ! ! enough to prevent excessive reallocation. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
aux = eas3_init_stream(NULL, AUX_SIZE, 'c'); data->uchar_aux = calloc(AUX_SIZE, sizeof(uchar));
if(!aux) data->aux_pos = 0;
data->aux_len = AUX_SIZE;
if(!data->uchar_aux)
{ {
// memory allocation error // memory allocation error
fprintf(stderr, MEMERROR); fprintf(stderr, MEMERROR);
@ -832,7 +822,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! Emit the standard parameters to the auxiliary informa- ! ! Emit the standard parameters to the auxiliary informa- !
! tion information memory block. ! ! tion information memory block. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
eas3_emit_chunck(aux, (uchar*)params, 176); aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len,
(uchar*)params, 176);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Convert the parameters required for the bwc compression ! ! Convert the parameters required for the bwc compression !
@ -896,7 +887,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! Emit the time step array to the auxiliary information ! ! Emit the time step array to the auxiliary information !
! memory block. ! ! memory block. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
eas3_emit_chunck(aux, buffer_char, params->nts * sizeof(uint64)); aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char,
params->nts * sizeof(uint64));
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Check if any attributes have been specified in the eas3 ! ! Check if any attributes have been specified in the eas3 !
@ -929,7 +921,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! Emit the timestep attribute array to the auxiliary infor-! ! Emit the timestep attribute array to the auxiliary infor-!
! mation memory block. ! ! mation memory block. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
eas3_emit_chunck(aux, buffer_char, params->nts * ATTRLEN * sizeof(char)); aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char,
params->nts * ATTRLEN * sizeof(char));
for(i = 0; i < params->npar; ++i) for(i = 0; i < params->npar; ++i)
{ {
@ -1000,7 +993,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! Emit the remaining header information the the auxiliary ! ! Emit the remaining header information the the auxiliary !
! information stream. ! ! information stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
eas3_emit_chunck(aux, buffer_char, Lread); aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len,
buffer_char, Lread);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Free the buffer character array. ! ! Free the buffer character array. !
@ -1012,12 +1006,18 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! ful, the address to the aux memory block stored is ! ! ful, the address to the aux memory block stored is !
! stored in the file structure alongside its size. ! ! stored in the file structure alongside its size. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
if(eas3_terminate_stream(aux, data->aux)) if(data->aux_pos != data->aux_len)
{
data->aux_len = data->aux_pos;
data->uchar_aux = realloc(data->uchar_aux, data->aux_len);
if(!data->uchar_aux)
{ {
// memory allocation error // memory allocation error
fprintf(stderr, MEMERROR); fprintf(stderr, MEMERROR);
data->aux_len = 0;
return 1; return 1;
} }
}
return 0; return 0;
} }