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