Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)::
Expand Down Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions ROOT/ROOT/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -194,12 +194,14 @@ int main(int argc, char** argv) {
append_or_overwrite == 'o');
writer.write();
} else if (!write_to_dat.empty()) {
Writer<Eigen::MatrixX2d> writer(results, WritingMethod::DAT, write_to_dat, ' ', append_or_overwrite == 'o');
writer.write();
} else if (!write_with_gnuplot.empty()) {
Writer<Eigen::MatrixX2d> writer(results, WritingMethod::GNUPLOT, write_with_gnuplot, ',',
append_or_overwrite == 'o');
writer.write();
if (write_with_gnuplot) {
Writer<Eigen::MatrixX2d> writer(results, WritingMethod::GNUPLOT, write_to_dat, ' ',
append_or_overwrite == 'o');
writer.write();
} else {
Writer<Eigen::MatrixX2d> writer(results, WritingMethod::DAT, write_to_dat, ' ', append_or_overwrite == 'o');
writer.write();
}
}

return 0;
Expand Down
8 changes: 5 additions & 3 deletions ROOT/ROOT/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void Writer<Eigen::MatrixX2d>::write() {
// LLM
if (auto gp = dynamic_cast<PrinterGNUPlot<Eigen::Vector2d>*>(printer.get())) {
gp->generate_gnuplot_script();
std::cout << "Gnuplot script generated: plot.plt\n";
std::cout << "Gnuplot script generated: " << this->filename << ".plt\n";
}
}

Expand All @@ -59,7 +59,8 @@ void Writer<T>::build_printer(std::unique_ptr<PrinterBase<V>>& printer) {
printer = std::make_unique<PrinterGNUPlot<V>>(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);
}
}

Expand All @@ -85,7 +86,8 @@ PrinterFile<V>::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);
}
}

Expand Down
6 changes: 4 additions & 2 deletions ROOT/tests/integration/test_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down