bwc_to_eas3 and writing decompressed data, tested output can be parsed to compress again
This commit is contained in:
parent
d13354078b
commit
d4acd85c37
3 changed files with 126 additions and 24 deletions
|
@ -359,6 +359,9 @@
|
||||||
void
|
void
|
||||||
eas3_free_data(eas3_data* data);
|
eas3_free_data(eas3_data* data);
|
||||||
|
|
||||||
|
uchar
|
||||||
|
bwc_to_eas3(bwc_stream *const stream, eas3_data *const data);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------------------------------------*\
|
/*----------------------------------------------------------------------------------------------------------*\
|
||||||
! FUNCTION NAME: bwc_data* read_eas3(const char* const filename) !
|
! FUNCTION NAME: bwc_data* read_eas3(const char* const filename) !
|
||||||
! -------------- !
|
! -------------- !
|
||||||
|
|
|
@ -317,6 +317,118 @@ eas3_add_param_name(eas3_data *const data, char *name)
|
||||||
strcpy(data->param_names->name, name ? name : "undefined");
|
strcpy(data->param_names->name, name ? name : "undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*================================================================================================*/
|
||||||
|
/**
|
||||||
|
* @details Parses the uncompressed output from bwc_stream into the eas3_data.
|
||||||
|
*
|
||||||
|
* @param[in] stream Pointer to uncompressed data set.
|
||||||
|
* @param[inout] data Pointer to eas3_data structure to be filled.
|
||||||
|
*
|
||||||
|
* @retval uchar
|
||||||
|
*/
|
||||||
|
/*================================================================================================*/
|
||||||
|
uchar
|
||||||
|
bwc_to_eas3(bwc_stream *const stream, eas3_data *const data)
|
||||||
|
{
|
||||||
|
/*-----------------------*\
|
||||||
|
! DEFINE INT VARIABLES: !
|
||||||
|
\*-----------------------*/
|
||||||
|
uint64 Lread;
|
||||||
|
uint64 size;
|
||||||
|
uint64 i;
|
||||||
|
|
||||||
|
/*-----------------------*\
|
||||||
|
! DEFINE CHAR VARIABLES: !
|
||||||
|
\*-----------------------*/
|
||||||
|
uchar *buffer_char;
|
||||||
|
char param_name[ATTRLEN + 1] = {};
|
||||||
|
|
||||||
|
/*-----------------------*\
|
||||||
|
! DEFINE STRUCTS: !
|
||||||
|
\*-----------------------*/
|
||||||
|
eas3_std_params *params;
|
||||||
|
|
||||||
|
params = &data->params;
|
||||||
|
|
||||||
|
data->aux.ptr = calloc(stream->codestream.aux->size, sizeof(uchar));
|
||||||
|
data->aux.pos = 0;
|
||||||
|
data->aux.len = stream->codestream.aux->size;
|
||||||
|
if(!data->aux.ptr)
|
||||||
|
{
|
||||||
|
// memory allocation error
|
||||||
|
fprintf(stderr, MEMERROR);
|
||||||
|
free(data->aux.ptr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
memcpy(data->aux.ptr, stream->codestream.aux->memory,
|
||||||
|
stream->codestream.aux->size);
|
||||||
|
|
||||||
|
aux_dequeue(data->aux, (uchar*)params, 176);
|
||||||
|
|
||||||
|
endian_conversion(¶ms->nts, 8);
|
||||||
|
endian_conversion(¶ms->npar, 8);
|
||||||
|
endian_conversion(¶ms->ndim1, 8);
|
||||||
|
endian_conversion(¶ms->ndim2, 8);
|
||||||
|
endian_conversion(¶ms->ndim3, 8);
|
||||||
|
endian_conversion(¶ms->accuracy, 8);
|
||||||
|
if(params->accuracy != 1 && params->accuracy != 2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "o##########################################################o\n"\
|
||||||
|
"| ERROR: The accuracy of the specified dataset is not sup- |\n"\
|
||||||
|
"| ported by the compression algorithm. |\n"\
|
||||||
|
"o##########################################################o\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_char = calloc(params->nts, sizeof(uint64));
|
||||||
|
if(!buffer_char)
|
||||||
|
{
|
||||||
|
// memory allocation error
|
||||||
|
fprintf(stderr, MEMERROR);
|
||||||
|
free(buffer_char);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
aux_dequeue(data->aux, buffer_char, params->nts * sizeof(uint64));
|
||||||
|
|
||||||
|
if(params->attribute_mode == EAS3_ALL_ATTR)
|
||||||
|
{
|
||||||
|
buffer_char = realloc(buffer_char, params->nts * ATTRLEN * sizeof(char));
|
||||||
|
if(!buffer_char)
|
||||||
|
{
|
||||||
|
// memory allocation error
|
||||||
|
fprintf(stderr, MEMERROR);
|
||||||
|
free(buffer_char);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
aux_dequeue(data->aux, buffer_char, params->nts * ATTRLEN * sizeof(char));
|
||||||
|
|
||||||
|
for(i = 0; i < params->npar; ++i)
|
||||||
|
{
|
||||||
|
aux_dequeue(data->aux, param_name, ATTRLEN * sizeof(char));
|
||||||
|
eas3_add_param_name(data, param_name);
|
||||||
|
memset(param_name, 0, ATTRLEN + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size = params->ndim1 * params->ndim2 * params->ndim3 *
|
||||||
|
params->nts * params->npar;
|
||||||
|
|
||||||
|
if(params->accuracy == 1)
|
||||||
|
{
|
||||||
|
data->field.d = NULL;
|
||||||
|
data->field.f = calloc(size, sizeof(float));
|
||||||
|
memcpy(data->field.f, stream->out, size);
|
||||||
|
}
|
||||||
|
else if(params->accuracy == 2)
|
||||||
|
{
|
||||||
|
data->field.f = NULL;
|
||||||
|
data->field.d = calloc(size, sizeof(double));
|
||||||
|
memcpy(data->field.d, stream->out, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------------------------------------*\
|
/*----------------------------------------------------------------------------------------------------------*\
|
||||||
! FUNCTION NAME: uchar read_eas3_header(bwc_data *const data) !
|
! FUNCTION NAME: uchar read_eas3_header(bwc_data *const data) !
|
||||||
! -------------- !
|
! -------------- !
|
||||||
|
@ -756,7 +868,13 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
||||||
! Convert the size parameters, used to write the rest of !
|
! Convert the size parameters, used to write the rest of !
|
||||||
! the header, to little endian. !
|
! the header, to little endian. !
|
||||||
\*--------------------------------------------------------*/
|
\*--------------------------------------------------------*/
|
||||||
|
endian_conversion(¶ms->file_type, 8);
|
||||||
endian_conversion(¶ms->accuracy, 8);
|
endian_conversion(¶ms->accuracy, 8);
|
||||||
|
endian_conversion(¶ms->nts, 8);
|
||||||
|
endian_conversion(¶ms->npar, 8);
|
||||||
|
endian_conversion(¶ms->ndim1, 8);
|
||||||
|
endian_conversion(¶ms->ndim2, 8);
|
||||||
|
endian_conversion(¶ms->ndim3, 8);
|
||||||
endian_conversion(¶ms->size_time, 8);
|
endian_conversion(¶ms->size_time, 8);
|
||||||
endian_conversion(¶ms->size_parameter, 8);
|
endian_conversion(¶ms->size_parameter, 8);
|
||||||
endian_conversion(¶ms->size_dim1, 8);
|
endian_conversion(¶ms->size_dim1, 8);
|
||||||
|
@ -766,6 +884,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
||||||
endian_conversion(¶ms->udef_int_size, 8);
|
endian_conversion(¶ms->udef_int_size, 8);
|
||||||
endian_conversion(¶ms->udef_real_size, 8);
|
endian_conversion(¶ms->udef_real_size, 8);
|
||||||
|
|
||||||
|
data->params = *params;
|
||||||
|
|
||||||
/*--------------------------------------------------------*\
|
/*--------------------------------------------------------*\
|
||||||
! Allocate the buffer character array. If successful, get !
|
! Allocate the buffer character array. If successful, get !
|
||||||
! the timestep array from the auxiliary information block !
|
! the timestep array from the auxiliary information block !
|
||||||
|
|
|
@ -1554,30 +1554,9 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
bwc_decompress(coder, stream);
|
bwc_decompress(coder, stream);
|
||||||
|
|
||||||
size = coder->info.nX * coder->info.nY * coder->info.nZ *
|
data = calloc(1, sizeof(eas3_data));
|
||||||
coder->info.nTS * coder->info.nPar;
|
bwc_to_eas3(stream, data);
|
||||||
|
write_eas3(data, cli_output);
|
||||||
data->params.ndim1 = coder->info.nX;
|
|
||||||
data->params.ndim2 = coder->info.nY;
|
|
||||||
data->params.ndim3 = coder->info.nZ;
|
|
||||||
data->params.nts = coder->info.nTS;
|
|
||||||
data->params.npar = coder->info.nPar;
|
|
||||||
if (coder->info.data_prec == bwc_precision_single)
|
|
||||||
{
|
|
||||||
data->params.accuracy = 1;
|
|
||||||
data->field.d = NULL;
|
|
||||||
data->field.f = calloc(size, sizeof(float));
|
|
||||||
memcpy(data->field.f, stream->out, size);
|
|
||||||
}
|
|
||||||
else if (coder->info.data_prec == bwc_precision_double)
|
|
||||||
{
|
|
||||||
data->params.accuracy = 2;
|
|
||||||
data->field.f = NULL;
|
|
||||||
data->field.d = calloc(size, sizeof(double));
|
|
||||||
memcpy(data->field.d, stream->out, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
//write_eas3(data, cli_output);
|
|
||||||
|
|
||||||
goto OUT;
|
goto OUT;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue