-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMatPlot.java
executable file
·117 lines (109 loc) · 3.78 KB
/
MatPlot.java
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package javaPlot;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import utility.GridMap;
import utility.Location;
public class MatPlot {
/**
* Call Matlab function that plot data on google map
* @param dataDir data dir
* @param plotDir plot dir
* @param cellSize grid size
* @param noc number of channels
* @param nlat north lat
* @param slat south lat
* @param wlng west lng
* @param elng east lng
* @param randomQuery plot result of random query
* @param smartQuery plot result of smart query
* @param noCM plot google map for no countermeasure
* @param ad plot additive noise
* @param tf plot transfiguration
* @param ka plot k anonymity
* @param kc plot k clustering
* @return
*/
public static boolean plot(String dataDir, String plotDir, double cellSize, int noc, double nlat,
double slat, double wlng, double elng,
boolean randomQuery, boolean smartQuery,
boolean noCM, boolean ad, boolean tf, boolean ka, boolean kc) {
if (!randomQuery && !smartQuery) {
System.out.println("Must specify method of queries");
return true;
}
if (!noCM && !ad && !tf && !ka && !kc) {
System.out.println("No google map need to be plotted");
return true;
}
System.out.println("Start plotting Google Maps...");
/**
* Construct a map instance to get number of rows and cols
*/
Location nwLoc = new Location(nlat, wlng);
Location seLoc = new Location(slat, elng);
GridMap map = new GridMap(nwLoc, seLoc, cellSize);
try {
// using the Runtime exec method:
String cmd = "java -cp \"C:\\Users\\Pradeep\\Desktop\\plotMap\";\"C:\\Program Files\\MATLAB\\MATLAB Compiler Runtime\\v83\\toolbox\\javabuilder\\jar\\javabuilder.jar\";\"C:\\Users\\Pradeep\\Desktop\\plotMap\\MatPlot.jar\" getmagic "
+ dataDir + " " + plotDir + " "
+ Integer.toString(noc) + " " + Integer.toString(map.getNumOfRows()) + " " + Integer.toString(map.getNumOfCols()) + " "
+ Double.toString(map.getNorthLat()) + " " + Double.toString(map.getSouthLat()) + " " + Double.toString(map.getWestLng()) + " " + Double.toString(map.getEastLng());
if (randomQuery) {
if (noCM) {
cmd += " No_Countermeasure";
}
if (ad) {
cmd += " Additive_Noise";
}
if (tf) {
cmd += " Transfiguration";
}
if (ka) {
cmd += " K_Anonymity";
}
if (kc) {
cmd += " K_Clustering";
}
}
if (smartQuery) {
if (noCM) {
cmd += " smart_No_Countermeasure";
}
if (ad) {
cmd += " smart_Additive_Noise";
}
if (tf) {
cmd += " smart_Transfiguration";
}
if (ka) {
cmd += " smart_K_Anonymity";
}
if (kc) {
cmd += " smart_K_Clustering";
}
}
// print command
System.out.println(cmd);
Process p = Runtime.getRuntime().exec(cmd);
/* uncomment these code to see matlab output */
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
String s;
// read the output from the command
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
int r = p.waitFor(); // if you don't read information from the input stream, it will overflow and hang
return r == 0;
} catch(Exception e) {
e.printStackTrace();
return false;
}
}
}