Up: Strategies for using scripts

Graph Demo Source CODE

#! /usr/bin/perl

# Set up environment and get form data

require "/u/www/root/admin/bin/cgi.pl";

$ENV{"PATH"} .= ":/usr/local/bin";

print &mime_header();
%data = &get_data();
$x = $data{"x"};
$y = $data{"y"};
$red = $data{"red"};
$green = $data{"green"};
$blue = $data{"blue"};
$history = $data{"history"};
$nodes = $data{"nodes"};

$pid = $$;

# memory utility subroutines

sub pack_history {

    if ($hl > 10) {$hl = 10;}        # limit to 10 pairs
    $history = "";
    foreach $i (0..$hl) {
       $history .= $x[$i]."z".$y[$i]."z".$r[$i]."z".$g[$i]."z".$b[$i]."q";
    }
}

sub expand_history {

   @colors = split('q',$history);
   $hl = $#colors;
   foreach $i (0..$#colors) {
      ($x[$i], $y[$i], $r[$i], $g[$i], $b[$i]) = split('z',$colors[$i]);
   }
}

# do memory

&expand_history();

$hl++;
$x[$hl] = $x; $y[$hl] = $y; $r[$hl] = $red; $g[$hl] = $green; $b[$hl] = $blue;

&pack_history();


#draw postscript

$tmp = "graph$pid";
system("cat graph.head > tmp/$tmp.eps");
open (TMP, ">> tmp/$tmp.eps");

for ($i=1; $i <= $hl; $i++) {
   $j = $i - 1;
   print TMP "
$r[$i] $g[$i] $b[$i] $r[$j] $g[$j] $b[$j] colors
$x[$i] $y[$i] 0.4 3 $nodes  doSwirl \n";
}

print TMP "showpage \n";

close(TMP);

system("convert tmp/$tmp.eps tmp/$tmp.gif");

# write out new page

print
"<HTML>
<HEAD>
<TITLE>Graph demo</TITLE>
</HEAD>

<BODY>
<H1>Graph demo</H1>

<FORM ACTION=\"graphdemo.cgi\">

<INPUT TYPE=HIDDEN name=history value=\"$history\">

<INPUT TYPE=IMAGE SRC=\"tmp/$tmp.gif\"><P>

R: <INPUT name=red size=3 value=1><BR>
G: <INPUT name=green size=3 value=0><BR>
B: <INPUT name=blue size=3 value=0><P>

nodes: <INPUT name=nodes size=3 value = 3><P>

</FORM>

<HR>
<!-- hhmts start -->
Last modified: Thu May  9 19:36:23 1996
<!-- hhmts end -->
</BODY>
</HTML>
";


# Scan for old files and erase them.

opendir(WORKDIR, tmp);
$old = time() - 600;		# "Old" files unchanged for 600 sec=10min
foreach $_ (readdir(WORKDIR)) {
    if(/^.+gif$/  || /^.+eps$/  ) { # any file with suffixes
	$thisfile=$WORKDIR . "/" . $_;
	@stat = stat($thisfile);      # stat[8]=mtime; stat[9]=ctime
	unlink($thisfile) if($stat[8] < $old && $stat[9] < $old);
    }
}
close(WORKDIR);


Up: Strategies for using scripts

[HOME] The Geometry Center Home Page

Comments to: webmaster@www.geom.uiuc.edu
Created: May 10 1996 --- Last modified: Tue Jun 4 22:11:47 1996