diff --git a/README.md b/README.md index 7227c7f..83882ff 100644 --- a/README.md +++ b/README.md @@ -148,8 +148,8 @@ OPTIONS: Separator character for CSV output --wdat, --write-to-dat TEXT Path for writing results to DAT file - --wgnuplot, --write-to-gnuplot TEXT - Path for writing results to Gnuplot file + --wgnuplot, --write-to-gnuplot Needs: --wdat + Write results to Gnuplot file --ofmode, --output-file-mode CHAR:{a,o} [o] Append or overwrite output file: 'a' for append, 'o' for overwrite @@ -198,7 +198,6 @@ Here's a list of examples of possible execution syntax: interval_b = 2 tolerance = 1e-5 max-iterations = 100 - derivative = 2*x ``` - CSV input file called input.csv with first row which is a header and "," separating different values, CSV output file called output.csv, Fixed Point Method to find the root of x^2-x, with initial guess 0.5, fixed point function x^2, and verbose output (given tolerance and maximum iterations):: @@ -230,7 +229,7 @@ Here's a list of examples of possible execution syntax: - CLI input, DAT output file called output.dat, gnuplot writing method (a GNU Plot named output.png is created), Chords method to solve the equation x^3-8 starting from the two initial points 1 and 3: ``` - root_cli --wgnuplot output cli --function x^3-8 chords --x0 1 --x1 3 + root_cli --wdat output --wgnuplot cli --function x^3-8 chords --x0 1 --x1 3 ``` ## Typical program execution diff --git a/ROOT/ROOT/main.cpp b/ROOT/ROOT/main.cpp index 0584083..7a6c6b3 100644 --- a/ROOT/ROOT/main.cpp +++ b/ROOT/ROOT/main.cpp @@ -39,9 +39,9 @@ int main(int argc, char** argv) { ->capture_default_str(); std::string write_to_dat; - app.add_option("--wdat,--write-to-dat", write_to_dat, "Path for writing results to DAT file"); - std::string write_with_gnuplot; - app.add_option("--wgnuplot,--write-to-gnuplot", write_with_gnuplot, "Path for writing results to Gnuplot file"); + auto* wdat = app.add_option("--wdat,--write-to-dat", write_to_dat, "Path for writing results to DAT file"); + bool write_with_gnuplot = false; + app.add_flag("--wgnuplot,--write-to-gnuplot", write_with_gnuplot, "Write results to Gnuplot file")->needs(wdat); char append_or_overwrite = 'o'; app.add_option("--ofmode,--output-file-mode", append_or_overwrite, @@ -194,12 +194,14 @@ int main(int argc, char** argv) { append_or_overwrite == 'o'); writer.write(); } else if (!write_to_dat.empty()) { - Writer writer(results, WritingMethod::DAT, write_to_dat, ' ', append_or_overwrite == 'o'); - writer.write(); - } else if (!write_with_gnuplot.empty()) { - Writer writer(results, WritingMethod::GNUPLOT, write_with_gnuplot, ',', - append_or_overwrite == 'o'); - writer.write(); + if (write_with_gnuplot) { + Writer writer(results, WritingMethod::GNUPLOT, write_to_dat, ' ', + append_or_overwrite == 'o'); + writer.write(); + } else { + Writer writer(results, WritingMethod::DAT, write_to_dat, ' ', append_or_overwrite == 'o'); + writer.write(); + } } return 0; diff --git a/ROOT/ROOT/writer.hpp b/ROOT/ROOT/writer.hpp index 2052199..588f9e4 100644 --- a/ROOT/ROOT/writer.hpp +++ b/ROOT/ROOT/writer.hpp @@ -38,7 +38,7 @@ void Writer::write() { // LLM if (auto gp = dynamic_cast*>(printer.get())) { gp->generate_gnuplot_script(); - std::cout << "Gnuplot script generated: plot.plt\n"; + std::cout << "Gnuplot script generated: " << this->filename << ".plt\n"; } } @@ -59,7 +59,8 @@ void Writer::build_printer(std::unique_ptr>& printer) { printer = std::make_unique>(this->filename, this->overwrite); break; default: - throw std::runtime_error("Unknown writing method"); + std::cerr << "\033[31mError: Unknown writing method.\033[0m\n"; + std::exit(EXIT_FAILURE); } } @@ -85,7 +86,8 @@ PrinterFile::PrinterFile(const std::string& fname, bool ow_mode) { } if (!file.is_open()) { - throw std::runtime_error("File could not be opened"); + std::cerr << "\033[31mError: could not open file " << this->filename << " for writing.\033[0m\n"; + std::exit(EXIT_FAILURE); } } diff --git a/ROOT/tests/integration/test_cli.cpp b/ROOT/tests/integration/test_cli.cpp index 6588634..09e7a22 100644 --- a/ROOT/tests/integration/test_cli.cpp +++ b/ROOT/tests/integration/test_cli.cpp @@ -71,7 +71,8 @@ TEST(NewtonMethodWithReaderCSVWriterGNUPlot, QuadraticConvergesToMinus2) { std::string exe = "../../ROOT/root_cli"; std::string cmd = exe + - " --wgnuplot result" + " --wdat result" + " --wgnuplot" " csv --file " + filename; @@ -131,7 +132,8 @@ TEST(NewtonMethodWithReaderDATWriterGNUPlot, QuadraticConvergesToMinus2) { std::string exe = "../../ROOT/root_cli"; std::string cmd = exe + - " --wgnuplot result" + " --wdat result" + " --wgnuplot" " dat --file " + filename;