The code in plotHeatmap() traverses an input array "efficiently", but incorrectly - that was THE point of the OP.
It works for a 'square' NxN matrix, but not in the general case, when Rows!=Cols (and the reason for that is traversing an array in a column-major way, so to speak, by blocks Rows-wide, rather than Cols-wide).
Run this code:
#include <profile.c>
#define Rows 3
#define Cols 8
int main() {
var Rets[Rows][Cols]; // address of a element is Rets [ i*Cols+j]
int DoW=0;
int Hr=0;
var i=0.01;
for (DoW=0; DoW<Rows; DoW++) {
for (Hr=0;Hr<Cols;Hr++) {
Rets[DoW][Hr] =i; // writing to an array happens at Rets[Dow*Cols +Hr] - i.e. by blocks of 8 (hourly) values per DoW
i+=0.01;
}
}
plotHeatmap("DoWbyHr",Rets,Rows,Cols); // produces wrong weird map - because retrieval/plotting happens from Rets[Hr*Rows+Dow] - i.e. by blocks of 3 (hourly) values
//plotHeatmap("DoWbyHr",Rets,Cols,Rows); // exchange Rows and Cols params to get a visually correct heatmap - though looking transposed
return 1;
}