From a843582d8f7e391ac280280b909c142822ef050e Mon Sep 17 00:00:00 2001 From: antonio leblanc Date: Sat, 31 Oct 2026 11:24:25 -0300 Subject: [PATCH 1/2] plot: warn when the ASCII cells are not square (#161) - writeASCII took the cellsize from the x extent alone: NEY was dropped - an ASCII grid carries one cellsize, so a non-square grid cannot be written correctly, we warn instead of staying quiet - test in tests/unit/test_commands.cpp: 2000 x 1000 m domain, size=20,20 -> dx 100, dy 50 - ctest 12/12, NetCDF OFF build --- src/Command.cpp | 18 ++++++++++++++---- tests/unit/test_commands.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Command.cpp b/src/Command.cpp index 7774e538..eef8a9cc 100644 --- a/src/Command.cpp +++ b/src/Command.cpp @@ -3785,7 +3785,7 @@ namespace libforefire } #endif /* FF_NO_NETCDF */ } - void Command::writeASCII(const char *filename, const std::vector> &matrix, double SWX, double SWY, double NEX, double /*NEY*/) + void Command::writeASCII(const char *filename, const std::vector> &matrix, double SWX, double SWY, double NEX, double NEY) { std::ofstream out(filename); if (!out) @@ -3799,9 +3799,19 @@ namespace libforefire size_t ncols = matrix.size(); size_t nrows = (ncols > 0) ? matrix[0].size() : 0; - // Compute the cell size. - // Here we assume that (NEX - SWX) corresponds to the total width of the matrix. - double cellsize = (ncols > 0) ? (NEX - SWX) / static_cast(ncols) : 0.0; + // An ASCII grid carries a single cellsize, but the matrix can hold + // cells that are not square (plot[...;size=...]). Writing the x value + // alone would place every row at the wrong spacing without a word. + double dx = (ncols > 0) ? (NEX - SWX) / static_cast(ncols) : 0.0; + double dy = (nrows > 0) ? (NEY - SWY) / static_cast(nrows) : 0.0; + if ((ncols > 0) && (nrows > 0) && + (std::abs(dx - dy) > 1e-6 * std::max(std::abs(dx), std::abs(dy)))) + { + std::cout << "writeASCII warning : the cells are not square, the file takes cellsize " + << dx << " from the x extent, while the y extent gives " << dy + << " for " << nrows << " rows" << std::endl; + } + double cellsize = dx; // Write the ASCII header. out << "ncols " << ncols << "\n"; diff --git a/tests/unit/test_commands.cpp b/tests/unit/test_commands.cpp index 86c11b7f..54c744bc 100644 --- a/tests/unit/test_commands.cpp +++ b/tests/unit/test_commands.cpp @@ -28,7 +28,9 @@ #include #include #include +#include #include +#include #include #include @@ -179,6 +181,29 @@ TEST_CASE("plot writes arrival times as an ASCII grid, north row first") { CHECK(inexact == 0); } +TEST_CASE("plot warns when the ASCII cells are not square") { + // An ASCII grid carries one cellsize, but plot[...;size=] can ask for cells + // that are not square. writeASCII used to compute it from the x extent + // alone, so the y spacing the file declares was wrong with no sign of it. + Command executor; + burnOffCentre(executor); + const std::string path = "ff_test_anisotropic.asc"; + + std::ostringstream captured; + std::streambuf* previous = std::cout.rdbuf(captured.rdbuf()); + run(executor, "plot[parameter=arrival_time;filename=" + path + ";size=20,20]"); + std::cout.rdbuf(previous); + + AsciiGrid grid = readAsciiGrid(path); + std::remove(path.c_str()); + + /* 2000 x 1000 m in 20 x 20 cells: 100 m in x, 50 m in y. */ + CHECK(grid.ncols == 20); + CHECK(grid.nrows == 20); + CHECK(grid.cellsize == doctest::Approx(100.)); + CHECK(captured.str().find("not square") != std::string::npos); +} + TEST_CASE("a domain built without a propagation layer spreads with the propagationModel parameter") { // loadData picks the model from the propagationModel parameter, but a // bare FireDomain[...] had no propagation layer and goTo segfaulted. From ac36d5178225ba82ebb4f74baf5d1afa6cb65a64 Mon Sep 17 00:00:00 2001 From: Antonio Leblanc Date: Mon, 2 Nov 2026 23:27:24 -0300 Subject: [PATCH 2/2] plot: use the WARNING: prefix for the non-square ASCII cells warning (#161) - matches the other warnings in src/, so a later move of WARNING lines to stderr (#165) picks it up - ctest 12/12 --- src/Command.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command.cpp b/src/Command.cpp index eef8a9cc..f6783ed8 100644 --- a/src/Command.cpp +++ b/src/Command.cpp @@ -3807,7 +3807,7 @@ namespace libforefire if ((ncols > 0) && (nrows > 0) && (std::abs(dx - dy) > 1e-6 * std::max(std::abs(dx), std::abs(dy)))) { - std::cout << "writeASCII warning : the cells are not square, the file takes cellsize " + std::cout << "WARNING: writeASCII: the cells are not square, the file takes cellsize " << dx << " from the x extent, while the y extent gives " << dy << " for " << nrows << " rows" << std::endl; }