-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plotting.cpp
58 lines (48 loc) · 1.55 KB
/
Plotting.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include "cblock.h"
#include "Plotting.h"
using namespace std;
extern control_block cb;
Plotter::Plotter() {
gnu_pipe = popen("gnuplot","w");
}
void Plotter::updatePlot(double *U, int niter, int m, int n){
double mx= -1.0e10, mn = 1.0e10;
for (int i=0; i<(m+2)*(n+2); i++){
if (U[i] > mx)
mx = U[i];
if (U[i] < mn)
mn = U[i];
}
// fprintf(gnu_pipe, "\n\nunset key\n");
fprintf(gnu_pipe, "set title \"niter = %d\n",niter);
fprintf(gnu_pipe, "set xrange [0:%f]\n", m);
fprintf(gnu_pipe, "set yrange [0:%f]\n", n);
fprintf(gnu_pipe, "set size square\n");
fprintf(gnu_pipe, "set key off\n");
fprintf(gnu_pipe, "set pm3d map\n");
fprintf(gnu_pipe, "set palette defined (-3 \"blue\", 0 \"white\", 1 \"red\")\n");
// fprintf(gnu_pipe, "plot \"-\" with points lt 1 pt 10 ps 1\n");
// Various color schemes
// fprintf(gnu,"set palette rgbformulae 22, 13, 31\n");
// fprintf(gnu,"set palette rgbformulae 30, 31, 32\n");
// Write out the coordinates of the particles
fprintf(gnu_pipe,"splot [0:%d] [0:%d][%f:%f] \"-\"\n",m-2,n-2,mn,mx);
for (int i=0; i<(m+2)*(n+2); i++) {
int I = i / (n+2);
int J = i % (n+2);
fprintf(gnu_pipe,"%d %d %f\n", I, J, U[i]);
if (J == n+1)
fprintf(gnu_pipe,"\n");
}
fprintf(gnu_pipe, "e\n");
fflush(gnu_pipe);
if (cb.wait){
cout << "Type any key to continue...\n";
int dummy;
cin >> dummy;
}
}
Plotter::~Plotter() {
pclose(gnu_pipe);
}