3 # Convert a single gnuplot demo script to a web page
7 # Reads xxx.dem and creates xxx.html along with associated
8 # png images output to xxx.<n>.png
10 # If gpsavediff is present also create a set of scripts
11 # xxx.<n>.gnu corresponding to the minimal set of commands
12 # needed to generate that png image.
14 # If gnuplot_demo.css is present, link to it as a stylesheet.
16 # Ethan A Merritt <merritt@u.washington.edu>
20 # use gpsavediff if available
21 # link to gnuplot_demo.css if available
24 # If DEMOTERM is present as an environmental variable, then use
26 # rather than the default terminal settings
27 # E.g. (for image demo)
28 # setenv DEMOTERM "png truecolor enhanced font arial 8 transparent size 420,320"
31 use Env qw(DEMOTERM GNUPLOT_LIB);
37 # Use the in-tree copy of gnuplot if there is one
38 my $gnuplot = ( -x "../../src/gnuplot" ) ? "../../src/gnuplot" : "gnuplot" ;
40 my $date = &ctime(time);
43 # input and output files
44 open(IN, "<$GNUPLOT_LIB/$ARGV[0].dem") or die "can't open $GNUPLOT_LIB/$ARGV[0].dem";
45 open(OUT, ">$ARGV[0].html") or die "can't open $ARGV[0].html";
47 # open pipe to gnuplot and set terminal type
48 open(GNUPLOT, "|$gnuplot") or die "can't find gnuplot";
49 if ((defined $ENV{DEMOTERM}) && $DEMOTERM ne "") {
50 print GNUPLOT "set term $DEMOTERM\n";
52 print GNUPLOT "set term png enhanced font arial 8 transparent size 420,320\n";
54 print GNUPLOT "set output \"$ARGV[0].$plot.png\"\n";
56 # find out if gpsavediff is available in current path
58 {local $^W=0; $savescripts = open(FOO, "|gpsavediff") }
59 close FOO if ($savescripts);
62 print OUT "<html>\n<head>\n<title>gnuplot demo script: $ARGV[0].dem </title>\n";
63 print OUT "<link rel=\"stylesheet\" href=\"gnuplot_demo.css\" type=\"text/css\">\n"
64 if (-e "gnuplot_demo.css");
65 print OUT "</head>\n";
66 print OUT "<body>\n<h2>gnuplot demo script: <font color=blue>$ARGV[0].dem</font> </h2>\n";
67 print OUT "<i>autogenerated by webify.pl on $date</i>";
69 # try to find gnuplot version
70 $version = `$gnuplot --version`;
71 print OUT "\n<br><i>gnuplot version $version</i>";
75 print OUT "<img src=\"$ARGV[0].$plot.png\" alt=\"\" align=right>\n";
81 print OUT "<br><p>Click <a href=$ARGV[0].$plot.gnu>here</a> ",
82 "for minimal script to generate this plot</p>\n";
83 print GNUPLOT "save \"| gpsavediff > $ARGV[0].$plot.gnu\"\n";
85 print OUT "</pre>\n<br clear=all>\n<hr>\n";
87 print OUT "<img src=\"$ARGV[0].$plot.png\" alt=\"\" align=right>\n";
89 print GNUPLOT "set output \"$ARGV[0].$plot.png\"\n";
91 print GNUPLOT "set output \"$ARGV[0].$plot.png\"\n";
93 print OUT HTML::Entities::encode($_);
98 # Amazingly enough, that's it.
99 # Unlink leftover empty plot before leaving.
101 unlink("$ARGV[0].$plot.png");
102 print OUT "</pre>\n";
103 print OUT "</body>\n</html>\n";