updates for some convenient debug events and a covnert to txt mode
[IRC.git] / Robust / CoreProf / Plot.java
1 import java.io.*;
2 import java.util.*;
3
4 public class Plot {
5   PrintWriter out;
6   PrintWriter command;
7   String filename;
8   int count=0;
9   String cmdstr="plot ";
10   Hashtable series;
11   boolean first=true;
12   boolean percent;
13   public Plot(String filename, boolean percent) {
14     this(filename);
15     this.percent=percent;
16   }
17
18   public Plot(String filename) {
19     try {
20       command=new PrintWriter(new FileOutputStream(filename+".cmd"), true);
21     } catch (IOException e) {
22       e.printStackTrace();
23       System.exit(-1);
24     }
25     this.filename=filename;
26     series=new Hashtable();
27   }
28
29   public Series getSeries(String name) {
30     if (series.containsKey(name))
31       return (Series)series.get(name);
32     Series s=createSeries(name);
33     series.put(name, s);
34     return s;
35   }
36
37   private Series createSeries(String name) {
38     Series s=null;
39     try {
40       s=new Series(new PrintWriter(new FileOutputStream(filename+"."+count),true));
41     } catch (IOException e) {
42       e.printStackTrace();
43       System.exit(-1);
44     }
45     if (!first) cmdstr+=",";
46     first=false;
47     cmdstr+="\""+filename+"."+count+"\" title \""+name+"\"";
48     count++;
49     return s;
50   }
51   
52   public void close() {
53     for(Iterator it=series.values().iterator();it.hasNext();) {
54       Series s=(Series)it.next();
55       s.close();
56     }
57     command.println("set style data linespoints");
58     command.println("set terminal postscript enhanced eps \"Times-Roman\" 18");
59     command.println("set key left");
60     command.println("set output \""+filename+"linear.eps\"");
61     command.println(cmdstr);
62     if (!percent) {
63       command.println("set log y");
64       command.println("set output \""+filename+"log.eps\"");
65       command.println(cmdstr);
66     }
67     command.close();
68   }
69 }