Skip to content

Commit

Permalink
Improve error message on EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
fgvieira committed Aug 11, 2023
1 parent 7001165 commit afb35a3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions shared/read_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ double*** read_geno(char *in_geno, bool in_bin, bool in_probs, bool *in_logscale
for(uint64_t s = 0; s < n_sites; s++){
if(in_bin){
for(uint64_t i = 0; i < n_ind; i++){
if( gzread(in_geno_fh, geno[i][s], N_GENO * sizeof(double)) != N_GENO * sizeof(double) )
error(__FUNCTION__, "cannot read binary GENO file. Check GENO file and number of sites!");
if( gzread(in_geno_fh, geno[i][s], N_GENO * sizeof(double)) != N_GENO * sizeof(double) ){
if (gzeof(in_geno_fh))
error(__FUNCTION__, "GENO file at premature EOF. Check GENO file and number of sites!");
else
error(__FUNCTION__, "cannot read binary GENO file. Check GENO file and number of sites!");
}
if(!*in_logscale)
conv_space(geno[i][s], N_GENO, log);
// Normalize GL
Expand All @@ -42,8 +46,12 @@ double*** read_geno(char *in_geno, bool in_bin, bool in_probs, bool *in_logscale
}
}
else{
if( gzgets(in_geno_fh, buf, BUFF_LEN) == NULL)
error(__FUNCTION__, "cannot read GZip GENO file. Check GENO file and number of sites!");
if( gzgets(in_geno_fh, buf, BUFF_LEN) == NULL){
if (gzeof(in_geno_fh))
error(__FUNCTION__, "GENO file at premature EOF. Check GENO file and number of sites!");
else
error(__FUNCTION__, "cannot read GZip GENO file. Check GENO file and number of sites!");
}
// Remove trailing newline
chomp(buf);
// Check if empty
Expand Down

0 comments on commit afb35a3

Please sign in to comment.