(* ploticus.sml * * COPYRIGHT (c) 2015 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. * * Utility code to generate a plot using the ploticus program (http://ploticus.sourceforge.net/) *) structure Ploticus : sig type args = string list (* common runtime arguments *) val output : string -> args (* specify output file *) val toEPS : args (* EPS output target *) val timesRoman : int -> args (* use Times-Roman font at given point size *) (* given command-line arguments and a function for generating plotting commands, generate * a plot. *) val run : args -> (TextIO.outstream -> unit) -> OS.Process.status (* run the epstopdf command to convert the output of ploticus to a PDF file *) val epstopdf : string -> OS.Process.status (* support for generating ploticus plots *) datatype color = RGB of real * real * real | GRAY of real | Tan1 | Tan2 | Red | Magenta | Claret | Coral | Pink | Orange | RedOrange | LightOrange | Yellow | Yellow2 | DullYellow | YellowOrange | BrightGreen | Green | KelleyGreen | Teal | DrabGreen | YellowGreen | LimeGreen | BrightBlue | DarkBlue | Blue | OceanBlue | SkyBlue | Purple | Lavender | LightPurple | PowderBlue | PowderBlue2 end = struct structure FS = OS.FileSys structure F = Format (* these are common paths where ploticus might be installed *) val paths = [ ("/opt/local/bin/pl", "/opt/local/share/ploticus") (* MacPorts *) ] fun getExePath () = let fun chk (cmdPath, prefabsPath) = FS.access(cmdPath, [FS.A_EXEC]) andalso FS.isDir prefabsPath in case List.find chk paths of NONE => raise Fail "Ploticus: unable to find ploticus command and prefabs" | SOME arg => arg (* end case *) end type args = string list (* common runtime arguments *) fun output file = ["-o", file] val toEPS = ["-eps"] fun timesRoman sz = ["-font", "/Times-Roman", "-textsize", Int.toString sz] fun run args outFn = let val (plPath, prefabs) = getExePath () val env = [ "PLOTICUS_PREFABS=" ^ prefabs ] val proc = Unix.executeInEnv (plPath, args, env) val outS = Unix.textOutstreamOf proc in outFn outS; TextIO.closeOut outS; Unix.reap proc end fun epstopdf file = let val dst = (case OS.Path.splitBaseExt file of {base, ext=SOME"eps"} => OS.Path.joinBaseExt {base=base, ext=SOME "pdf"} | _ => OS.Path.joinBaseExt {base=file, ext=SOME "pdf"} (* end case *)) in OS.Process.system (String.concatWith " " [ "epstopdf", "-o", dst, file ]) end datatype color = RGB of real * real * real | GRAY of real | Tan1 | Tan2 | Red | Magenta | Claret | Coral | Pink | Orange | RedOrange | LightOrange | Yellow | Yellow2 | DullYellow | YellowOrange | BrightGreen | Green | KelleyGreen | Teal | DrabGreen | YellowGreen | LimeGreen | BrightBlue | DarkBlue | Blue | OceanBlue | SkyBlue | Purple | Lavender | LightPurple | PowderBlue | PowderBlue2 fun colorToString (RGB(r, g, b)) = F.format "rgb(%f,%f,%f)" [F.REAL r, F.REAL g, F.REAL b] | colorToString (GRAY g) = F.format "gray(%f)" [F.REAL g] | colorToString Tan1 = "tan1" | colorToString Tan2 = "tan2" | colorToString Red = "ted" | colorToString Magenta = "magenta" | colorToString Claret = "claret" | colorToString Coral = "coral" | colorToString Pink = "pink" | colorToString Orange = "orange" | colorToString RedOrange = "redorange" | colorToString LightOrange = "lightorange" | colorToString Yellow = "yellow" | colorToString Yellow2 = "yellow2" | colorToString DullYellow = "dullyellow" | colorToString YellowOrange = "yelloworange" | colorToString BrightGreen = "brightgreen" | colorToString Green = "green" | colorToString KelleyGreen = "kelleygreen" | colorToString Teal = "teal" | colorToString DrabGreen = "drabgreen" | colorToString YellowGreen = "yellowgreen" | colorToString LimeGreen = "limegreen" | colorToString BrightBlue = "brightblue" | colorToString DarkBlue = "darkblue" | colorToString Blue = "blue" | colorToString OceanBlue = "oceanblue" | colorToString SkyBlue = "skyslue" | colorToString Purple = "purple" | colorToString Lavender = "lavender" | colorToString LightPurple = "lightpurple" | colorToString PowderBlue = "powderblue" | colorToString PowderBlue2 = "powderblue2" end
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: | colorToString PowderBlue = "powderblue" | colorToString PowderBlue2 = "powderblue2" end