From 80922ee1863b4bb6f68a156568eacc634c72969d Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sat, 9 Sep 2023 22:05:11 -0400 Subject: [PATCH] plot_cubefile conforms to the original cube format in which up to 6 elements are allowed per line ... this allows Wolfram to read the data --- src/madness/mra/funcplot.h | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/madness/mra/funcplot.h b/src/madness/mra/funcplot.h index bbbf9d0d528..4b7e20def14 100644 --- a/src/madness/mra/funcplot.h +++ b/src/madness/mra/funcplot.h @@ -961,21 +961,29 @@ void plot_plane(World& world, const std::vector >& vfuncti for (const std::string& s : molecular_info) fprintf(file,"%s",s.c_str()); - Tensorgrid(npt[0],npt[1],npt[2]); - for (int i=0;i grid(npt[0], npt[1], npt[2]); + long count_per_line = 0; + for (int i = 0; i < npt[0]; ++i) { + for (int j = 0; j < npt[1]; ++j) { + for (int k = 0; k < npt[2]; ++k) { + double x = cell(0, 0) + origin[0] + xlen / npt[0] * i; + double y = cell(1, 0) + origin[1] + ylen / npt[1] * j; + double z = cell(2, 0) + origin[2] + zlen / npt[2] * k; + // the original format has up to 6 entries per line: https://paulbourke.net/dataformats/cube/ + // stick with this, even though many codes can read an arbitrary number of entries per line + if (count_per_line < 6) { + fprintf(file, "%12.5e ", f(x, y, z)); + count_per_line++; + } else { + fprintf(file, "%12.5e\n", f(x, y, z)); + count_per_line = 0; + } + } + } + } + fprintf(file, "\n"); + fclose(file); + } /// convenience to get plot_plane and plot_cubefile template