SCM Repository
Annotation of /benchmarks/analysis/ploticus.sml
Parent Directory
|
Revision Log
Revision 3059 - (view) (download)
1 : | jhr | 3059 | (* ploticus.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2015 The Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | * | ||
6 : | * Utility code to generate a plot using the ploticus program (http://ploticus.sourceforge.net/) | ||
7 : | *) | ||
8 : | |||
9 : | structure Ploticus : sig | ||
10 : | |||
11 : | type args = string list | ||
12 : | |||
13 : | (* common runtime arguments *) | ||
14 : | val output : string -> args (* specify output file *) | ||
15 : | val toEPS : args (* EPS output target *) | ||
16 : | val timesRoman : int -> args (* use Times-Roman font at given point size *) | ||
17 : | |||
18 : | (* given command-line arguments and a function for generating plotting commands, generate | ||
19 : | * a plot. | ||
20 : | *) | ||
21 : | val run : args -> (TextIO.outstream -> unit) -> OS.Process.status | ||
22 : | |||
23 : | (* run the epstopdf command to convert the output of ploticus to a PDF file *) | ||
24 : | val epstopdf : string -> OS.Process.status | ||
25 : | |||
26 : | (* support for generating ploticus plots *) | ||
27 : | |||
28 : | datatype color | ||
29 : | = RGB of real * real * real | ||
30 : | | GRAY of real | ||
31 : | | Tan1 | ||
32 : | | Tan2 | ||
33 : | | Red | ||
34 : | | Magenta | ||
35 : | | Claret | ||
36 : | | Coral | ||
37 : | | Pink | ||
38 : | | Orange | ||
39 : | | RedOrange | ||
40 : | | LightOrange | ||
41 : | | Yellow | ||
42 : | | Yellow2 | ||
43 : | | DullYellow | ||
44 : | | YellowOrange | ||
45 : | | BrightGreen | ||
46 : | | Green | ||
47 : | | KelleyGreen | ||
48 : | | Teal | ||
49 : | | DrabGreen | ||
50 : | | YellowGreen | ||
51 : | | LimeGreen | ||
52 : | | BrightBlue | ||
53 : | | DarkBlue | ||
54 : | | Blue | ||
55 : | | OceanBlue | ||
56 : | | SkyBlue | ||
57 : | | Purple | ||
58 : | | Lavender | ||
59 : | | LightPurple | ||
60 : | | PowderBlue | ||
61 : | | PowderBlue2 | ||
62 : | |||
63 : | end = struct | ||
64 : | |||
65 : | structure FS = OS.FileSys | ||
66 : | structure F = Format | ||
67 : | |||
68 : | (* these are common paths where ploticus might be installed *) | ||
69 : | val paths = [ | ||
70 : | ("/opt/local/bin/pl", "/opt/local/share/ploticus") (* MacPorts *) | ||
71 : | ] | ||
72 : | |||
73 : | fun getExePath () = let | ||
74 : | fun chk (cmdPath, prefabsPath) = | ||
75 : | FS.access(cmdPath, [FS.A_EXEC]) andalso | ||
76 : | FS.isDir prefabsPath | ||
77 : | in | ||
78 : | case List.find chk paths | ||
79 : | of NONE => raise Fail "Ploticus: unable to find ploticus command and prefabs" | ||
80 : | | SOME arg => arg | ||
81 : | (* end case *) | ||
82 : | end | ||
83 : | |||
84 : | type args = string list | ||
85 : | |||
86 : | (* common runtime arguments *) | ||
87 : | fun output file = ["-o", file] | ||
88 : | val toEPS = ["-eps"] | ||
89 : | fun timesRoman sz = ["-font", "/Times-Roman", "-textsize", Int.toString sz] | ||
90 : | |||
91 : | fun run args outFn = let | ||
92 : | val (plPath, prefabs) = getExePath () | ||
93 : | val env = [ | ||
94 : | "PLOTICUS_PREFABS=" ^ prefabs | ||
95 : | ] | ||
96 : | val proc = Unix.executeInEnv (plPath, args, env) | ||
97 : | val outS = Unix.textOutstreamOf proc | ||
98 : | in | ||
99 : | outFn outS; | ||
100 : | TextIO.closeOut outS; | ||
101 : | Unix.reap proc | ||
102 : | end | ||
103 : | |||
104 : | fun epstopdf file = let | ||
105 : | val dst = (case OS.Path.splitBaseExt file | ||
106 : | of {base, ext=SOME"eps"} => OS.Path.joinBaseExt {base=base, ext=SOME "pdf"} | ||
107 : | | _ => OS.Path.joinBaseExt {base=file, ext=SOME "pdf"} | ||
108 : | (* end case *)) | ||
109 : | in | ||
110 : | OS.Process.system (String.concatWith " " [ | ||
111 : | "epstopdf", "-o", dst, file | ||
112 : | ]) | ||
113 : | end | ||
114 : | |||
115 : | datatype color | ||
116 : | = RGB of real * real * real | ||
117 : | | GRAY of real | ||
118 : | | Tan1 | ||
119 : | | Tan2 | ||
120 : | | Red | ||
121 : | | Magenta | ||
122 : | | Claret | ||
123 : | | Coral | ||
124 : | | Pink | ||
125 : | | Orange | ||
126 : | | RedOrange | ||
127 : | | LightOrange | ||
128 : | | Yellow | ||
129 : | | Yellow2 | ||
130 : | | DullYellow | ||
131 : | | YellowOrange | ||
132 : | | BrightGreen | ||
133 : | | Green | ||
134 : | | KelleyGreen | ||
135 : | | Teal | ||
136 : | | DrabGreen | ||
137 : | | YellowGreen | ||
138 : | | LimeGreen | ||
139 : | | BrightBlue | ||
140 : | | DarkBlue | ||
141 : | | Blue | ||
142 : | | OceanBlue | ||
143 : | | SkyBlue | ||
144 : | | Purple | ||
145 : | | Lavender | ||
146 : | | LightPurple | ||
147 : | | PowderBlue | ||
148 : | | PowderBlue2 | ||
149 : | |||
150 : | fun colorToString (RGB(r, g, b)) = F.format "rgb(%f,%f,%f)" [F.REAL r, F.REAL g, F.REAL b] | ||
151 : | | colorToString (GRAY g) = F.format "gray(%f)" [F.REAL g] | ||
152 : | | colorToString Tan1 = "tan1" | ||
153 : | | colorToString Tan2 = "tan2" | ||
154 : | | colorToString Red = "ted" | ||
155 : | | colorToString Magenta = "magenta" | ||
156 : | | colorToString Claret = "claret" | ||
157 : | | colorToString Coral = "coral" | ||
158 : | | colorToString Pink = "pink" | ||
159 : | | colorToString Orange = "orange" | ||
160 : | | colorToString RedOrange = "redorange" | ||
161 : | | colorToString LightOrange = "lightorange" | ||
162 : | | colorToString Yellow = "yellow" | ||
163 : | | colorToString Yellow2 = "yellow2" | ||
164 : | | colorToString DullYellow = "dullyellow" | ||
165 : | | colorToString YellowOrange = "yelloworange" | ||
166 : | | colorToString BrightGreen = "brightgreen" | ||
167 : | | colorToString Green = "green" | ||
168 : | | colorToString KelleyGreen = "kelleygreen" | ||
169 : | | colorToString Teal = "teal" | ||
170 : | | colorToString DrabGreen = "drabgreen" | ||
171 : | | colorToString YellowGreen = "yellowgreen" | ||
172 : | | colorToString LimeGreen = "limegreen" | ||
173 : | | colorToString BrightBlue = "brightblue" | ||
174 : | | colorToString DarkBlue = "darkblue" | ||
175 : | | colorToString Blue = "blue" | ||
176 : | | colorToString OceanBlue = "oceanblue" | ||
177 : | | colorToString SkyBlue = "skyslue" | ||
178 : | | colorToString Purple = "purple" | ||
179 : | | colorToString Lavender = "lavender" | ||
180 : | | colorToString LightPurple = "lightpurple" | ||
181 : | | colorToString PowderBlue = "powderblue" | ||
182 : | | colorToString PowderBlue2 = "powderblue2" | ||
183 : | |||
184 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |