manual aux buffer

This commit is contained in:
Gregor Weiss 2024-10-17 19:18:44 +02:00
parent e0bc0d8839
commit 31ed09982e
Signed by: Gregor Weiss
GPG key ID: 61E170A8BBFE5756
2 changed files with 45 additions and 41 deletions

View file

@ -369,6 +369,10 @@
} field;
span *aux;
uchar *uchar_aux;
uint32 aux_pos;
uint32 aux_len;
} 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: !
! ------------ !
! This function is used to write an additional chunck of size length to a bwc bitstream. !
! !
! !
! 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 !
! This macro is used to write an additional chunck of size length to the auxilliary !
! information. !
! !
\*----------------------------------------------------------------------------------------------------------*/
#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
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 !
! enough to prevent excessive reallocation. !
\*--------------------------------------------------------*/
aux = eas3_init_stream(NULL, AUX_SIZE, 'c');
if(!aux)
data->uchar_aux = calloc(AUX_SIZE, sizeof(uchar));
data->aux_pos = 0;
data->aux_len = AUX_SIZE;
if(!data->uchar_aux)
{
// memory allocation error
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- !
! 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 !
@ -896,7 +887,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! Emit the time step array to the auxiliary information !
! 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 !
@ -929,7 +921,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! Emit the timestep attribute array to the auxiliary infor-!
! 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)
{
@ -1000,7 +993,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! Emit the remaining header information the the auxiliary !
! 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. !
@ -1012,12 +1006,18 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! ful, the address to the aux memory block stored is !
! 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
fprintf(stderr, MEMERROR);
data->aux_len = 0;
return 1;
}
}
return 0;
}