adjust read_eas3

This commit is contained in:
Gregor Weiss 2024-10-16 11:11:34 +02:00
parent 379e10d5a2
commit 858808a46c
Signed by: Gregor Weiss
GPG key ID: 61E170A8BBFE5756
2 changed files with 28 additions and 33 deletions

View file

@ -388,7 +388,7 @@
! structure. !
! !
\*----------------------------------------------------------------------------------------------------------*/
bwc_data*
eas3_data*
read_eas3(char *const filename);
/*----------------------------------------------------------------------------------------------------------*\

View file

@ -1290,7 +1290,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created !
! !
\*----------------------------------------------------------------------------------------------------------*/
bwc_data*
eas3_data*
read_eas3(char *const filename)
{
/*-----------------------*\
@ -1299,16 +1299,17 @@ read_eas3(char *const filename)
uint64 Lfield;
uint64 i;
uint32 root;
FILE *fp;
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bwc_data *data;
eas3_data *data;
/*--------------------------------------------------------*\
! Allocate the data structure. !
\*--------------------------------------------------------*/
data = calloc(1, sizeof(bwc_data));
data = calloc(1, sizeof(eas3_data));
if(!data)
{
// memory allocation error
@ -1316,23 +1317,17 @@ read_eas3(char *const filename)
return NULL;
}
/*--------------------------------------------------------*\
! Set the file identifier used to select the appropriate !
! write operation during decompression. !
\*--------------------------------------------------------*/
strncpy(data->info.f_ext, "eas", 4);
/*--------------------------------------------------------*\
! Open the specified file for reading. If the file doesn't !
! exist, exit the bwc command-line tool. !
\*--------------------------------------------------------*/
if((data->fp = fopen(filename, "rb")) == NULL)
if((fp = fopen(filename, "rb")) == NULL)
{
// error opening file
fprintf(stderr, "o##########################################################o\n"\
"| ERROR: Could not open or read %-25s|\n"\
"o##########################################################o\n", filename);
bwc_free_data(data);
fclose(fp);
return NULL;
}
@ -1340,10 +1335,10 @@ read_eas3(char *const filename)
! Parse the eas3 header and store the information in the !
! data structure. !
\*--------------------------------------------------------*/
if(read_eas3_header(data))
if(read_eas3_header(fp, data))
{
//error reading eas3 header
bwc_free_data(data);
eas3_free_data(data);
}
/*--------------------------------------------------------*\
@ -1351,19 +1346,19 @@ read_eas3(char *const filename)
! file and store the information in the bwc_gl_data struc- !
! ture. !
\*--------------------------------------------------------*/
root = ftell(data->fp);
fseek(data->fp, 0L, SEEK_END);
Lfield = (ftell(data->fp) - root) / sizeof(double);
fseek(data->fp, root, SEEK_SET);
root = ftell(fp);
fseek(fp, 0L, SEEK_END);
Lfield = (ftell(fp) - root) / sizeof(double);
fseek(fp, root, SEEK_SET);
/*--------------------------------------------------------*\
! Check if the file_size coincide with the specified dimen-!
! sions, timesteps number of parameters or bitdepth speci- !
! fied in the eas3 file header. !
\*--------------------------------------------------------*/
if(Lfield != data->info.nX * data->info.nY *
data->info.nZ * data->info.nTS *
data->info.nPar)
if(Lfield != data->params.ndim1 * data->params.ndim2 *
data->params.ndim3 * data->params.nts *
data->params.npar)
{
// error in file size
fprintf(stderr, "o##########################################################o\n"\
@ -1372,11 +1367,11 @@ read_eas3(char *const filename)
"| and number of parameters specified in the file |\n"\
"| header. |\n"\
"o##########################################################o\n");
bwc_free_data(data);
eas3_free_data(data);
return NULL;
}
if(data->info.parameter->precision == 4)
if(data->params.accuracy == 1)
{
/*--------------------------------------------------------*\
! Allocate the real field that will hold the numerical !
@ -1384,22 +1379,22 @@ read_eas3(char *const filename)
\*--------------------------------------------------------*/
data->field.d = NULL;
data->field.f = calloc(Lfield, sizeof(float));
if(!data->field.d)
if(!data->field.f)
{
// memory allocation error
fprintf(stderr, MEMERROR);
bwc_free_data(data);
eas3_free_data(data);
return NULL;
}
/*--------------------------------------------------------*\
! Read the flow field data from the specified eas3 file. !
\*--------------------------------------------------------*/
if(fread(data->field.f, sizeof(float), Lfield, data->fp) != Lfield)
if(fread(data->field.f, sizeof(float), Lfield, fp) != Lfield)
{
// invalid read
fprintf(stderr, RDERROR);
bwc_free_data(data);
eas3_free_data(data);
return NULL;
}
@ -1412,7 +1407,7 @@ read_eas3(char *const filename)
endian_conversion(&data->field.f[i], 4);
}
}
else if(data->info.parameter->precision == 8)
else if(data->params.accuracy == 2)
{
/*--------------------------------------------------------*\
! Allocate the real field that will hold the numerical !
@ -1424,18 +1419,18 @@ read_eas3(char *const filename)
{
// memory allocation error
fprintf(stderr, MEMERROR);
bwc_free_data(data);
eas3_free_data(data);
return NULL;
}
/*--------------------------------------------------------*\
! Read the flow field data from the specified eas3 file. !
\*--------------------------------------------------------*/
if(fread(data->field.d, sizeof(double), Lfield, data->fp) != Lfield)
if(fread(data->field.d, sizeof(double), Lfield, fp) != Lfield)
{
// invalid read
fprintf(stderr, RDERROR);
bwc_free_data(data);
eas3_free_data(data);
return NULL;
}
@ -1453,8 +1448,8 @@ read_eas3(char *const filename)
! Close the file pointer and return the bwc_data structure !
! to the function caller. !
\*--------------------------------------------------------*/
fclose(data->fp);
data->fp = NULL;
fclose(fp);
fp = NULL;
return data;
}