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