#!/usr/bin/perl -w # # Convert a single gnuplot demo script to a web page # Usage: # webify xxx # # Reads xxx.dem and creates xxx.html along with associated # png images output to xxx..png # # If gpsavediff is present also create a set of scripts # xxx..gnu corresponding to the minimal set of commands # needed to generate that png image. # # If gnuplot.css is present, link to it as a stylesheet. # # Ethan A Merritt # December 2003 # # EAM Jan 2004 # use gpsavediff if available # link to gnuplot.css if available # use HTML::Entities; require "ctime.pl"; my $date = &ctime(time); my $plot = 1; # input and output files open(IN, "<$ARGV[0].dem") or die "can't open $ARGV[0].dem"; open(OUT, ">$ARGV[0].html") or die "can't open $ARGV[0].html"; # open pipe to gnuplot and set terminal type open(GNUPLOT, "|gnuplot") or die "can't find gnuplot"; print GNUPLOT "set term png enhanced font arial 8 transparent size 420,320\n"; print GNUPLOT "set output \"$ARGV[0].$plot.png\"\n"; # find out if gpsavediff is available in current path my $savescripts = T; {local $^W=0; $savescripts = open(FOO, "|gpsavediff") } close FOO if ($savescripts); # Boiler plate header print OUT "\n\ngnuplot demo script: $ARGV[0].dem \n"; print OUT "\n" if (-e "gnuplot.css"); print OUT "\n"; print OUT "\n

gnuplot demo script: $ARGV[0].dem

\n"; print OUT "autogenerated by webify.pl on $date"; # try to find gnuplot version $version = `gnuplot --version`; print OUT "\n
gnuplot version $version"; print OUT "
\n"; # Start processing print OUT "\"\"\n"; print OUT "
\n";

	while () {
		if (/^pause /) {
			if ($savescripts) {
			    print OUT "

Click here ", "for minimal script to generate this plot

\n"; print GNUPLOT "save \"| gpsavediff > $ARGV[0].$plot.gnu\"\n"; } print OUT "
\n
\n
\n"; $plot++; print OUT "\"\"\n"; print OUT "
\n";
			print GNUPLOT "set output \"$ARGV[0].$plot.png\"\n";
		} else {
			print OUT HTML::Entities::encode($_);
			print GNUPLOT;
		}
	}

# Amazingly enough, that's it.
# Unlink leftover empty plot before leaving.
	close GNUPLOT;
	unlink("$ARGV[0].$plot.png");
	print OUT "
\n"; print OUT "\n\n";