diff --git a/src/fit.cc b/src/fit.cc index e2a5afa9..f12f21fe 100644 --- a/src/fit.cc +++ b/src/fit.cc @@ -49,34 +49,38 @@ read_number_sequence(istream &in, numseq_t &numseq) { const std::string VERSION_STRING = (std::string)PACKAGE_STRING; -bool help; -bool version; -bool verbose; +struct fit_clp { + bool help; + bool version; + bool verbose; -string filename; // file that contains the sequence of numbers + string filename; // file that contains the sequence of numbers -double delta_ab; // penalty for a change a->b -double delta_ba; // penalty for a change b->a + double delta_ab; // penalty for a change a->b + double delta_ba; // penalty for a change b->a -double beta = 12; // inverse temperature + double beta = 12; // inverse temperature -bool opt_once_on; + bool opt_once_on; -bool opt_all_values; + bool opt_all_values; +}; + +fit_clp clp; option_def my_options[] = - {{"help", 'h', &help, O_NO_ARG, 0, O_NODEFAULT, "", "This help"}, - {"version", 'V', &version, O_NO_ARG, 0, O_NODEFAULT, "", "Version info"}, - {"verbose", 'v', &verbose, O_NO_ARG, 0, O_NODEFAULT, "", "Verbose"}, + {{"help", 'h', &clp.help, O_NO_ARG, 0, O_NODEFAULT, "", "This help"}, + {"version", 'V', &clp.version, O_NO_ARG, 0, O_NODEFAULT, "", "Version info"}, + {"verbose", 'v', &clp.verbose, O_NO_ARG, 0, O_NODEFAULT, "", "Verbose"}, - {"delta", 'd', 0, O_ARG_DOUBLE, &delta_ab, "0.5", "float", + {"delta", 'd', 0, O_ARG_DOUBLE, &clp.delta_ab, "0.5", "float", "Penalty for state change"}, - {"beta", 'b', 0, O_ARG_DOUBLE, &beta, "6", "float", "Inverse temperature"}, - {"once-on", 0, &opt_once_on, O_NO_ARG, 0, O_NODEFAULT, "", + {"beta", 'b', 0, O_ARG_DOUBLE, &clp.beta, "6", "float", "Inverse temperature"}, + {"once-on", 0, &clp.opt_once_on, O_NO_ARG, 0, O_NODEFAULT, "", "Fit a signal that is on only once"}, - {"all-values", 0, &opt_all_values, O_NO_ARG, 0, O_NODEFAULT, "", + {"all-values", 0, &clp.opt_all_values, O_NO_ARG, 0, O_NODEFAULT, "", "Show all function values of signal (instead of only ranges)"}, - {"", 0, 0, O_ARG_STRING, &filename, "profile.dat", "file", + {"", 0, 0, O_ARG_STRING, &clp.filename, "profile.dat", "file", "Input file with sequence of numbers"}, {"", 0, 0, 0, 0, O_NODEFAULT, "", ""}}; @@ -85,7 +89,7 @@ option_def my_options[] = int main(int argc, char **argv) { - delta_ba = delta_ab; // always use same penalties for a->b and b->a + clp.delta_ba = clp.delta_ab; // always use same penalties for a->b and b->a double c0 = 0.2; double c1 = 0.6; // initial on off values @@ -95,7 +99,7 @@ main(int argc, char **argv) { // bool process_success = process_options(argc, argv, my_options); - if (help) { + if (clp.help) { cout << "locarnap_fit - Fit a two step function to a data series." << endl << endl; @@ -107,9 +111,9 @@ main(int argc, char **argv) { return 0; } - if (version || verbose) { + if (clp.version || clp.verbose) { cout << "locarnap_fit (" << VERSION_STRING << ")" << endl; - if (version) + if (clp.version) return 0; else cout << endl; @@ -121,7 +125,7 @@ main(int argc, char **argv) { return -1; } - if (verbose) { + if (clp.verbose) { print_options(my_options); } // @@ -133,16 +137,16 @@ main(int argc, char **argv) { // numseq_t numseq; - if (filename == "-") { + if (clp.filename == "-") { read_number_sequence(std::cin, numseq); } else { - read_number_sequence(filename, numseq); + read_number_sequence(clp.filename, numseq); } // ---------------------------------------- // optimize on/off-values and compute fit // - FitOnOff fns(numseq, delta_ab, delta_ba, beta); + FitOnOff fns(numseq, clp.delta_ab, clp.delta_ba, clp.beta); // double viterbi_score; @@ -151,7 +155,7 @@ main(int argc, char **argv) { c0 = opt.first; c1 = opt.second; - if (opt_once_on) { + if (clp.opt_once_on) { // run once on optimization double on = std::max(c0, c1); double off = std::min(c0, c1); @@ -169,8 +173,8 @@ main(int argc, char **argv) { // write best fit // - if (!opt_all_values) { - if (opt_once_on) + if (!clp.opt_all_values) { + if (clp.opt_once_on) cout << "ONOFF " << min(c0, c1) << " " << max(c0, c1) << endl; else cout << "ONOFF " << c0 << " " << c1 << endl;