adjust read_eas3_header
This commit is contained in:
parent
b48525b8e4
commit
00f9e720e9
1 changed files with 44 additions and 71 deletions
|
@ -703,7 +703,7 @@ eas3_add_param_name(eas3_data *const data, char *name)
|
|||
! !
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
static uchar
|
||||
read_eas3_header(bwc_data *const data)
|
||||
read_eas3_header(FILE *const fp, eas3_data *const data)
|
||||
{
|
||||
/*-----------------------*\
|
||||
! DEFINE INT VARIABLES: !
|
||||
|
@ -723,12 +723,7 @@ read_eas3_header(bwc_data *const data)
|
|||
\*-----------------------*/
|
||||
bwc_gl_inf *info;
|
||||
bitstream *aux;
|
||||
eas3_std_params params;
|
||||
|
||||
/*-----------------------*\
|
||||
! DEFINE FILE POINTER: !
|
||||
\*-----------------------*/
|
||||
FILE *fp;
|
||||
eas3_std_params *params;
|
||||
|
||||
/*-----------------------*\
|
||||
! DEFINE ASSERTIONS: !
|
||||
|
@ -736,11 +731,10 @@ read_eas3_header(bwc_data *const data)
|
|||
assert(data);
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Save the file pointer and data info structure in tempo- !
|
||||
! rary variables to make the code more readable. !
|
||||
! Save the eas3_std_params structure in temporary !
|
||||
! variables to make the code more readable. !
|
||||
\*--------------------------------------------------------*/
|
||||
fp = data->fp;
|
||||
info = &data->info;
|
||||
params = &data->params;
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Allocate the character buffer used to store chunks of !
|
||||
|
@ -784,8 +778,8 @@ read_eas3_header(bwc_data *const data)
|
|||
/*--------------------------------------------------------*\
|
||||
! Allocate the auxiliary information packed stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
data->codestream.aux = calloc(1, sizeof(bwc_stream));
|
||||
if(!data->codestream.aux)
|
||||
data->aux = calloc(1, sizeof(bitstream));
|
||||
if(!data->aux)
|
||||
{
|
||||
// memory allocation error
|
||||
fprintf(stderr, MEMERROR);
|
||||
|
@ -813,7 +807,7 @@ read_eas3_header(bwc_data *const data)
|
|||
! present the eas3 standard parameters. The information !
|
||||
! is stored in the eas3_std_params structure. !
|
||||
\*--------------------------------------------------------*/
|
||||
if(fread(¶ms, sizeof(uint64), 22, fp) != 22)
|
||||
if(fread(params, sizeof(uint64), 22, fp) != 22)
|
||||
{
|
||||
// invalid read
|
||||
fprintf(stderr, RDERROR);
|
||||
|
@ -824,7 +818,7 @@ read_eas3_header(bwc_data *const data)
|
|||
/*--------------------------------------------------------*\
|
||||
! Check if the specified file is of the EAS3 type. !
|
||||
\*--------------------------------------------------------*/
|
||||
if(params.file_type == EAS2_TYPE)
|
||||
if(params->file_type == EAS2_TYPE)
|
||||
{
|
||||
// invalid file format
|
||||
fprintf(stderr, "o##########################################################o\n"\
|
||||
|
@ -834,50 +828,29 @@ read_eas3_header(bwc_data *const data)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Emit a file format hash to the aux stream to identify it !
|
||||
! as a eas3 auxiliary information block. This hash can be !
|
||||
! used to properly handle decompression into an eas3 file !
|
||||
! or conversion to other file formats. !
|
||||
\*--------------------------------------------------------*/
|
||||
// emit_symbol(aux, hash("eas3"), 8);
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Emit the standard parameters to the auxiliary informa- !
|
||||
! tion information memory block. !
|
||||
\*--------------------------------------------------------*/
|
||||
emit_chunck(aux, (uchar*)¶ms, 176);
|
||||
emit_chunck(aux, (uchar*)params, 176);
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Convert the parameters required for the bwc compression !
|
||||
! stage to little endian and store them in the file info !
|
||||
! structure. !
|
||||
\*--------------------------------------------------------*/
|
||||
endian_conversion(¶ms.nzs, 8);
|
||||
info->nTS = (uint16)params.nzs;
|
||||
endian_conversion(params->nts, 8);
|
||||
|
||||
endian_conversion(¶ms.npar, 8);
|
||||
info->nPar = (uint8)params.npar;
|
||||
endian_conversion(params->npar, 8);
|
||||
|
||||
endian_conversion(¶ms.ndim1, 8);
|
||||
info->nX = (uint64)params.ndim1;
|
||||
endian_conversion(params->ndim1, 8);
|
||||
|
||||
endian_conversion(¶ms.ndim2, 8);
|
||||
info->nY = (uint64)params.ndim2;
|
||||
endian_conversion(params->ndim2, 8);
|
||||
|
||||
endian_conversion(¶ms.ndim3, 8);
|
||||
info->nZ = (uint64)params.ndim3;
|
||||
endian_conversion(params->ndim3, 8);
|
||||
|
||||
endian_conversion(¶ms.accuracy, 8);
|
||||
if(params.accuracy == 1)
|
||||
{
|
||||
precision = 4;
|
||||
}
|
||||
else if(params.accuracy == 2)
|
||||
{
|
||||
precision = 8;
|
||||
}
|
||||
else
|
||||
endian_conversion(params->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"\
|
||||
|
@ -890,20 +863,20 @@ read_eas3_header(bwc_data *const data)
|
|||
! Convert the size parameters, used to load the rest of the!
|
||||
! header, to little endian. !
|
||||
\*--------------------------------------------------------*/
|
||||
endian_conversion(¶ms.size_time, 8);
|
||||
endian_conversion(¶ms.size_parameter, 8);
|
||||
endian_conversion(¶ms.size_dim1, 8);
|
||||
endian_conversion(¶ms.size_dim2, 8);
|
||||
endian_conversion(¶ms.size_dim3, 8);
|
||||
endian_conversion(¶ms.udef_char_size, 8);
|
||||
endian_conversion(¶ms.udef_int_size, 8);
|
||||
endian_conversion(¶ms.udef_real_size, 8);
|
||||
endian_conversion(params->size_time, 8);
|
||||
endian_conversion(params->size_parameter, 8);
|
||||
endian_conversion(params->size_dim1, 8);
|
||||
endian_conversion(params->size_dim2, 8);
|
||||
endian_conversion(params->size_dim3, 8);
|
||||
endian_conversion(params->udef_char_size, 8);
|
||||
endian_conversion(params->udef_int_size, 8);
|
||||
endian_conversion(params->udef_real_size, 8);
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Allocate the time step array. If successful, read the !
|
||||
! timesteps from the file stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
buffer_char = realloc(buffer_char, info->nTS * sizeof(uint64));
|
||||
buffer_char = realloc(buffer_char, params->nts * sizeof(uint64));
|
||||
if(!buffer_char)
|
||||
{
|
||||
// memory allocation error
|
||||
|
@ -911,7 +884,7 @@ read_eas3_header(bwc_data *const data)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if(fread(buffer_char, sizeof(uint64), info->nTS, fp) != info->nTS)
|
||||
if(fread(buffer_char, sizeof(uint64), params->nts, fp) != params->nts)
|
||||
{
|
||||
// invalid read
|
||||
fprintf(stderr, RDERROR);
|
||||
|
@ -923,19 +896,19 @@ read_eas3_header(bwc_data *const data)
|
|||
! Emit the time step array to the auxiliary information !
|
||||
! memory block. !
|
||||
\*--------------------------------------------------------*/
|
||||
emit_chunck(aux, buffer_char, info->nTS * sizeof(uint64));
|
||||
emit_chunck(aux, buffer_char, params->nts * sizeof(uint64));
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Check if any attributes have been specified in the eas3 !
|
||||
! file. !
|
||||
\*--------------------------------------------------------*/
|
||||
if(params.attribute_mode == EAS3_ALL_ATTR)
|
||||
if(params->attribute_mode == EAS3_ALL_ATTR)
|
||||
{
|
||||
/*--------------------------------------------------------*\
|
||||
! Allocate the buffer character array. If successful, read !
|
||||
! the timestep attributes from the file stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
buffer_char = realloc(buffer_char, info->nTS * ATTRLEN * sizeof(char));
|
||||
buffer_char = realloc(buffer_char, params->nts * ATTRLEN * sizeof(char));
|
||||
if(!buffer_char)
|
||||
{
|
||||
// memory allocation error
|
||||
|
@ -944,7 +917,7 @@ read_eas3_header(bwc_data *const data)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if(fread(buffer_char, sizeof(char), info->nTS * ATTRLEN, fp) != (info->nTS * ATTRLEN))
|
||||
if(fread(buffer_char, sizeof(char), params->nts * ATTRLEN, fp) != (params->nts * ATTRLEN))
|
||||
{
|
||||
// invalid read
|
||||
fprintf(stderr, RDERROR);
|
||||
|
@ -956,9 +929,9 @@ read_eas3_header(bwc_data *const data)
|
|||
! Emit the timestep attribute array to the auxiliary infor-!
|
||||
! mation memory block. !
|
||||
\*--------------------------------------------------------*/
|
||||
emit_chunck(aux, buffer_char, info->nTS * ATTRLEN * sizeof(char));
|
||||
emit_chunck(aux, buffer_char, params->nts * ATTRLEN * sizeof(char));
|
||||
|
||||
for(i = 0; i < info->nPar; ++i)
|
||||
for(i = 0; i < params->npar; ++i)
|
||||
{
|
||||
/*--------------------------------------------------------*\
|
||||
! Read the parameter name from the file stream and add all !
|
||||
|
@ -973,7 +946,7 @@ read_eas3_header(bwc_data *const data)
|
|||
return 1;
|
||||
}
|
||||
|
||||
bwc_add_param(data, param_name, precision);
|
||||
eas3_add_param_name(data, param_name);
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Read the parameter name from the file stream and add all !
|
||||
|
@ -989,15 +962,15 @@ read_eas3_header(bwc_data *const data)
|
|||
! the eas3 file header. !
|
||||
\*--------------------------------------------------------*/
|
||||
Lread = 0;
|
||||
Lread += (params.attribute_mode == EAS3_ALL_ATTR) ? 3 * ATTRLEN : 0;
|
||||
Lread += (params.gmode_time > EAS3_NO_G) ? params.size_time * sizeof(uint64) : 0;
|
||||
Lread += (params.gmode_param > EAS3_NO_G) ? params.size_parameter * sizeof(uint64) : 0;
|
||||
Lread += (params.gmode_dim1 > EAS3_NO_G) ? params.size_dim1 * sizeof(uint64) : 0;
|
||||
Lread += (params.gmode_dim2 > EAS3_NO_G) ? params.size_dim2 * sizeof(uint64) : 0;
|
||||
Lread += (params.gmode_dim3 > EAS3_NO_G) ? params.size_dim3 * sizeof(uint64) : 0;
|
||||
Lread += (params.udef_param == EAS3_ALL_UDEF) ? params.udef_char_size * sizeof(char) * UDEFLEN +
|
||||
params.udef_int_size * sizeof(uint64) +
|
||||
params.udef_real_size * sizeof(double) : 0;
|
||||
Lread += (params->attribute_mode == EAS3_ALL_ATTR) ? 3 * ATTRLEN : 0;
|
||||
Lread += (params->gmode_time > EAS3_NO_G) ? params->size_time * sizeof(uint64) : 0;
|
||||
Lread += (params->gmode_param > EAS3_NO_G) ? params->size_parameter * sizeof(uint64) : 0;
|
||||
Lread += (params->gmode_dim1 > EAS3_NO_G) ? params->size_dim1 * sizeof(uint64) : 0;
|
||||
Lread += (params->gmode_dim2 > EAS3_NO_G) ? params->size_dim2 * sizeof(uint64) : 0;
|
||||
Lread += (params->gmode_dim3 > EAS3_NO_G) ? params->size_dim3 * sizeof(uint64) : 0;
|
||||
Lread += (params->udef_param == EAS3_ALL_UDEF) ? params->udef_char_size * sizeof(char) * UDEFLEN +
|
||||
params->udef_int_size * sizeof(uint64) +
|
||||
params->udef_real_size * sizeof(double) : 0;
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Reallocate the buffer character array to allow for the !
|
||||
|
@ -1039,7 +1012,7 @@ read_eas3_header(bwc_data *const data)
|
|||
! ful, the address to the aux memory block stored is !
|
||||
! stored in the file structure alongside its size. !
|
||||
\*--------------------------------------------------------*/
|
||||
if(terminate_stream(aux, data->codestream.aux))
|
||||
if(terminate_stream(aux, data->aux))
|
||||
{
|
||||
// memory allocation error
|
||||
fprintf(stderr, MEMERROR);
|
||||
|
|
Loading…
Reference in a new issue