adjust write_eas3_header

This commit is contained in:
Gregor Weiss 2024-10-16 10:34:25 +02:00
parent 00f9e720e9
commit 379e10d5a2
Signed by: Gregor Weiss
GPG key ID: 61E170A8BBFE5756

View file

@ -1057,7 +1057,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
static uchar static uchar
write_eas3_header(bwc_data *const data) write_eas3_header(FILE *const fp, eas3_data *const data)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE INT VARIABLES: ! ! DEFINE INT VARIABLES: !
@ -1075,25 +1075,13 @@ write_eas3_header(bwc_data *const data)
bwc_gl_inf *info; bwc_gl_inf *info;
bitstream *aux; bitstream *aux;
eas3_std_params *params; eas3_std_params *params;
bwc_cmd_opts_ll *param; eas3_param_names *param_names;
/*-----------------------*\
! DEFINE FILE POINTER: !
\*-----------------------*/
FILE *fp;
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !
\*-----------------------*/ \*-----------------------*/
assert(data); assert(data);
/*--------------------------------------------------------*\
! Save the file pointer and data info structure in tempo- !
! rary variables to make the code more readable. !
\*--------------------------------------------------------*/
fp = data->fp;
info = &data->info;
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Write the valid EAS3 identifier to the specified file. ! ! Write the valid EAS3 identifier to the specified file. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
@ -1107,8 +1095,7 @@ write_eas3_header(bwc_data *const data)
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Initialize the auxiliary information stream. ! ! Initialize the auxiliary information stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
aux = init_stream(data->codestream.aux->memory, aux = init_stream(data->aux->memory, data->aux->size, 'd');
data->codestream.aux->size, 'd');
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Get the standard parameters from the auxiliary informa- ! ! Get the standard parameters from the auxiliary informa- !
@ -1142,7 +1129,7 @@ write_eas3_header(bwc_data *const data)
! the timestep array from the auxiliary information block ! ! the timestep array from the auxiliary information block !
! and write it to the file stream. ! ! and write it to the file stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
buffer_char = get_chunck(aux, info->nTS * sizeof(uint64)); buffer_char = get_chunck(aux, data->params.nts * sizeof(uint64));
if(!buffer_char) if(!buffer_char)
{ {
// memory allocation error // memory allocation error
@ -1151,7 +1138,7 @@ write_eas3_header(bwc_data *const data)
return 1; return 1;
} }
if(fwrite(buffer_char, sizeof(uint64), info->nTS, fp) != info->nTS) if(fwrite(buffer_char, sizeof(uint64), data->params.nts, fp) != data->params.nts)
{ {
// invalid read // invalid read
fprintf(stderr, WRTERROR); fprintf(stderr, WRTERROR);
@ -1171,7 +1158,7 @@ write_eas3_header(bwc_data *const data)
! the timestep attribute array from the auxiliary informa- ! ! the timestep attribute array from the auxiliary informa- !
! tion block and write it to the file stream. ! ! tion block and write it to the file stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
buffer_char = get_chunck(aux, info->nTS * ATTRLEN); buffer_char = get_chunck(aux, data->params.nts * ATTRLEN);
if(!buffer_char) if(!buffer_char)
{ {
// memory allocation error // memory allocation error
@ -1180,7 +1167,7 @@ write_eas3_header(bwc_data *const data)
return 1; return 1;
} }
if(fwrite(buffer_char, sizeof(uchar), info->nTS * ATTRLEN, fp) != (info->nTS * ATTRLEN)) if(fwrite(buffer_char, sizeof(uchar), data->params.nts * ATTRLEN, fp) != (data->params.nts * ATTRLEN))
{ {
// invalid read // invalid read
fprintf(stderr, WRTERROR); fprintf(stderr, WRTERROR);
@ -1192,17 +1179,17 @@ write_eas3_header(bwc_data *const data)
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Loop through the parameter array and... ! ! Loop through the parameter array and... !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
if(data->info.parameter) if(data->param_names)
{ {
param = data->info.parameter->root; param_names = data->param_names->root;
while(param != NULL) while(param_names != NULL)
{ {
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! ... write the parameter name from the info structure to ! ! ... write the parameter name from the info structure to !
! the file stream. ! ! the file stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
if(fwrite(param->name, sizeof(char), ATTRLEN, fp) != ATTRLEN) if(fwrite(param_names->name, sizeof(char), ATTRLEN, fp) != ATTRLEN)
{ {
// invalid read // invalid read
fprintf(stderr, WRTERROR); fprintf(stderr, WRTERROR);
@ -1210,7 +1197,7 @@ write_eas3_header(bwc_data *const data)
return 1; return 1;
} }
param = param -> next; param_names = param_names->next;
} }
} }
} }