diff --git a/src/aevol_create.cpp b/src/aevol_create.cpp index d12c908b966e804d259edea52c85161973f5cfba..744de72bf672233cc9a5a115b2cea773b6b0c7c3 100644 --- a/src/aevol_create.cpp +++ b/src/aevol_create.cpp @@ -40,7 +40,9 @@ const char* DEFAULT_PARAM_FILE_NAME = "param.in"; #include <getopt.h> +#include <fstream> #include <sstream> +#include <string> #include "legacy/ExpManager.h" #include "aevol_version.h" @@ -70,35 +72,28 @@ int main(int argc, char* argv[]) { // Initialize the experiment manager exp_manager = new ExpManager(); - // Initialize the simulation from the parameter file - int32_t lchromosome = -1; - char* chromosome = nullptr; + std::string chromosome; if (chromosome_file_name != nullptr) { - const int max_input_chrom_size = 1000000; - char raw_chromosome[max_input_chrom_size]; - FILE* chromosome_file = fopen(chromosome_file_name, "r"); - if (chromosome_file == nullptr) { + std::ifstream chromosome_file(chromosome_file_name); + if (not chromosome_file) { Utils::ExitWithUsrMsg(std::string("failed to open source chromosome file ") + chromosome_file_name); } - if (fgets(raw_chromosome, max_input_chrom_size, chromosome_file) == nullptr) - { + + std::getline(chromosome_file, chromosome); + if (not chromosome_file or chromosome.length() == 0) { Utils::ExitWithUsrMsg(std::string("failed to read from chromosome file ") + chromosome_file_name); } - lchromosome = strlen(raw_chromosome) - 1; - chromosome = new char[lchromosome + 1]; - strncpy(chromosome, raw_chromosome, lchromosome + 1); - printf("Loading chromosome from text file %s (%" PRId32 " base pairs) \n", - chromosome_file_name, lchromosome); + + std::cout << "Loading chromosome from text file " << chromosome_file_name << " (" << chromosome.length() + << " base pairs)" << std::endl; delete [] chromosome_file_name; - fclose(chromosome_file); } if(param_file_name != nullptr) { - if (lchromosome > -1) { - ParamLoader::load(param_values, exp_manager, true, chromosome, lchromosome); - delete chromosome; + if (chromosome.length() != 0) { + ParamLoader::load(param_values, exp_manager, true, chromosome.c_str(), chromosome.length()); } else { ParamLoader::load(param_values, exp_manager, true); }