From b65bd931c97768308f1aab7077cabacd0e4cd247 Mon Sep 17 00:00:00 2001 From: andreasaporito Date: Thu, 11 Dec 2025 15:31:24 +0100 Subject: [PATCH 1/6] Fixed one bug in main.cpp and in README examples --- README.md | 12 ++++++------ ROOT/ROOT/main.cpp | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a67a289..3ec2c4a 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ Here's a list of examples of possible execution syntax: - DAT input file called input.dat with first row not being header and " " separating different values, .dat file output called output.dat, Bisection method to find the root of x^3-1, with initial interval [-2,2], verbose output (given tolerance and maximum iterations): ``` - root_cli --verbose --wdat output dat input + root_cli --verbose --wdat output dat --file input.dat ``` where input.dat is: @@ -165,10 +165,10 @@ Here's a list of examples of possible execution syntax: ``` function = x^3-1 method = bisection - initial = -1 + interval_a = -1 + 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 file ouput @@ -176,21 +176,21 @@ called output.csv, Fixed Point Method to find the root of cos(x), with initial guess 0.5, fixed point function cos(x): ``` - root_cli --wcsv output --ocsvsep , csv input --sep , --header + root_cli --wcsv output --ocsvsep , csv --file input.csv --sep , --header 1 ``` where input.csv is: ``` function,method,initial,tolerance,max_iterations,g-function - 'cos(x)',fixed_point,0.5,1e-5,100,'cos(x)' + cos(x),fixed_point,0.5,1e-5,100,cos(x) ``` - CLI input, .dat output file called output.dat and moreover a GNU Plot is created from it as output.png. Chords method to solve the equation x^3-8 starting from the two initial points 1 and 3: ``` - root_cli --wdat output --wgnuplot output cli --function x^3-8 chords --x0 --x1 3 + root_cli --wdat output --wgnuplot output cli --function x^3-8 chords --x0 1 --x1 3 ``` The installed CLI application can simply be used by: diff --git a/ROOT/ROOT/main.cpp b/ROOT/ROOT/main.cpp index f0defc4..6694f47 100644 --- a/ROOT/ROOT/main.cpp +++ b/ROOT/ROOT/main.cpp @@ -196,13 +196,15 @@ 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()) { + if (!write_with_gnuplot.empty()) { Writer writer(results, WritingMethod::GNUPLOT, write_with_gnuplot, ',', append_or_overwrite == 'o'); writer.write(); } + else { + Writer writer(results, WritingMethod::DAT, write_to_dat, ' ', append_or_overwrite == 'o'); + writer.write();} + } return 0; } From c90dafe5e704f391096c2f0dea0041e501ec740e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:33:20 +0000 Subject: [PATCH 2/6] style: pre-commit fixes --- ROOT/ROOT/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ROOT/ROOT/main.cpp b/ROOT/ROOT/main.cpp index 6694f47..c0b6376 100644 --- a/ROOT/ROOT/main.cpp +++ b/ROOT/ROOT/main.cpp @@ -197,13 +197,13 @@ int main(int argc, char** argv) { writer.write(); } else if (!write_to_dat.empty()) { if (!write_with_gnuplot.empty()) { - Writer writer(results, WritingMethod::GNUPLOT, write_with_gnuplot, ',', - append_or_overwrite == 'o'); - writer.write(); - } - else { + Writer writer(results, WritingMethod::GNUPLOT, write_with_gnuplot, ',', + append_or_overwrite == 'o'); + writer.write(); + } else { Writer writer(results, WritingMethod::DAT, write_to_dat, ' ', append_or_overwrite == 'o'); - writer.write();} + writer.write(); + } } return 0; From 19470b556449900b2795e61f97d5b55419ef9ca8 Mon Sep 17 00:00:00 2001 From: andreasaporito Date: Thu, 11 Dec 2025 15:47:52 +0100 Subject: [PATCH 3/6] Fixed integration tests --- ROOT/tests/integration/test_cli.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ROOT/tests/integration/test_cli.cpp b/ROOT/tests/integration/test_cli.cpp index 6588634..fa97ba2 100644 --- a/ROOT/tests/integration/test_cli.cpp +++ b/ROOT/tests/integration/test_cli.cpp @@ -71,6 +71,7 @@ TEST(NewtonMethodWithReaderCSVWriterGNUPlot, QuadraticConvergesToMinus2) { std::string exe = "../../ROOT/root_cli"; std::string cmd = exe + + " --wdat result" " --wgnuplot result" " csv --file " + filename; @@ -131,6 +132,7 @@ TEST(NewtonMethodWithReaderDATWriterGNUPlot, QuadraticConvergesToMinus2) { std::string exe = "../../ROOT/root_cli"; std::string cmd = exe + + " --wdat result" " --wgnuplot result" " dat --file " + filename; From 3de83d74f5e19f3bfa6f30613e1e53659e92598c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:49:24 +0000 Subject: [PATCH 4/6] style: pre-commit fixes --- ROOT/tests/integration/test_cli.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ROOT/tests/integration/test_cli.cpp b/ROOT/tests/integration/test_cli.cpp index fa97ba2..d89e0ed 100644 --- a/ROOT/tests/integration/test_cli.cpp +++ b/ROOT/tests/integration/test_cli.cpp @@ -71,7 +71,7 @@ TEST(NewtonMethodWithReaderCSVWriterGNUPlot, QuadraticConvergesToMinus2) { std::string exe = "../../ROOT/root_cli"; std::string cmd = exe + - " --wdat result" + " --wdat result" " --wgnuplot result" " csv --file " + filename; @@ -132,7 +132,7 @@ TEST(NewtonMethodWithReaderDATWriterGNUPlot, QuadraticConvergesToMinus2) { std::string exe = "../../ROOT/root_cli"; std::string cmd = exe + - " --wdat result" + " --wdat result" " --wgnuplot result" " dat --file " + filename; From 693ef1019c977cda5fe80598094a199989fe8813 Mon Sep 17 00:00:00 2001 From: Saransh Chopra Date: Thu, 11 Dec 2025 17:46:52 +0100 Subject: [PATCH 5/6] make gnuplot a flag --- ROOT/ROOT/main.cpp | 10 +++++----- ROOT/ROOT/writer.hpp | 8 +++++--- ROOT/tests/integration/test_cli.cpp | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ROOT/ROOT/main.cpp b/ROOT/ROOT/main.cpp index 0402c33..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,8 +194,8 @@ int main(int argc, char** argv) { append_or_overwrite == 'o'); writer.write(); } else if (!write_to_dat.empty()) { - if (!write_with_gnuplot.empty()) { - Writer writer(results, WritingMethod::GNUPLOT, write_with_gnuplot, ',', + if (write_with_gnuplot) { + Writer writer(results, WritingMethod::GNUPLOT, write_to_dat, ' ', append_or_overwrite == 'o'); writer.write(); } else { 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 d89e0ed..09e7a22 100644 --- a/ROOT/tests/integration/test_cli.cpp +++ b/ROOT/tests/integration/test_cli.cpp @@ -72,7 +72,7 @@ TEST(NewtonMethodWithReaderCSVWriterGNUPlot, QuadraticConvergesToMinus2) { std::string cmd = exe + " --wdat result" - " --wgnuplot result" + " --wgnuplot" " csv --file " + filename; @@ -133,7 +133,7 @@ TEST(NewtonMethodWithReaderDATWriterGNUPlot, QuadraticConvergesToMinus2) { std::string cmd = exe + " --wdat result" - " --wgnuplot result" + " --wgnuplot" " dat --file " + filename; From 06edb49237e4e6039796725d4896d0a993b6e817 Mon Sep 17 00:00:00 2001 From: Saransh Chopra Date: Thu, 11 Dec 2025 17:47:46 +0100 Subject: [PATCH 6/6] update readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 81b7df8..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 @@ -229,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 --wdat output --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