-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGnuplot.java
More file actions
91 lines (68 loc) · 1.67 KB
/
Copy pathGnuplot.java
File metadata and controls
91 lines (68 loc) · 1.67 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
import java.lang.StringBuilder;
public class Gnuplot
{
private int MAX = 8;
private double[] a = new double[MAX];
private double[] b = new double[MAX];
private Random fRandom = new Random();
public double getGaussian(double aMean, double aVariance)
{
return aMean + fRandom.nextGaussian() * aVariance;
}
double MEAN1 = 200.0f;
double VARIANCE1 = 20.0f;
double MEAN2 = 300.0f;
double VARIANCE2 = 30.0f;
public void generate()
{
for (int i = 0; i < MAX; i++)
{
a[i] = getGaussian(MEAN1, VARIANCE1);
b[i] = 5.0 - 2.0*a[i] + getGaussian(MEAN2, VARIANCE2);
}
}
String command;
public void buildCommand()
{
StringBuilder s = new StringBuilder("echo ");
for (int i = 0; i < MAX; i++)
{
s.append(a[i]).append(" ").append(b[i]);
if(i < MAX - 1) s.append("\n");
}
s.append(" | feedgnuplot\n");
command = s.toString();
}
public static void main(String[] args)
{
Gnuplot gobj = new Gnuplot();
gobj.generate();
gobj.buildCommand();
System.out.println(gobj.command);
String output = gobj.plot();
//System.out.println(output);
}
public String plot()
{
StringBuffer output = new StringBuffer();
Process p;
try
{
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null)
output.append(line + "\n");
}
catch (Exception e)
{
e.printStackTrace();
}
return output.toString();
}
}