Skip to content

Commit

Permalink
Better spea2 error message (#1207)
Browse files Browse the repository at this point in the history
* added output file header and working example
* more informative msg when param file missing
  • Loading branch information
MichaelEhrlichman authored Sep 26, 2024
1 parent bf940fa commit 22ddafa
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions bsim/apisa/spea2/spea2_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <cstring>
#include <cassert>
#include <cmath>

#include <iostream>
#include "spea2.hpp"

/* common parameters */
Expand Down Expand Up @@ -67,7 +67,12 @@ int* old_index;
double** dist; /* distance between individuals in combined population */
int** NN;


void custom_assert(bool condition, const char* message) {
if (!condition) {
std::cerr << "Assertion failed: " << message << std::endl;
abort(); // Terminate the program
}
}

/*-----------------------| initialization |------------------------------*/

Expand All @@ -77,11 +82,16 @@ void initialize(char* paramfile, char* filenamebase)
FILE *fp;
int result;
char str[CFG_ENTRY_LENGTH];
char buffer[100];

/* reading parameter file with parameters for selection */
fp = fopen(paramfile, "r");
assert(fp != NULL);

/* assert(fp != NULL);
*/

/*custom_assert(fp != NULL, "Check a_spea2_param.txt") ; */
sprintf(buffer, "Problem with paramfile: %s", paramfile);
custom_assert(fp != NULL, buffer) ;
fscanf(fp, "%s", str);
assert(strcmp(str, "seed") == 0);
fscanf(fp, "%d", &seed);
Expand Down

0 comments on commit 22ddafa

Please sign in to comment.