Up: Strategies for using scripts

Image Demo Source Code

#! /usr/bin/perl

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

#get form data

print &mime_header();
%data = &get_data();

$A = $data{"A"};
$B = $data{"B"};
$C = $data{"C"};

#get the current process number

$pid = $$;

#open a connection to Maple

$maple = "| maple -q";
$maplegif = "tmp/maple$pid.gif";
open(MAPLE, $maple) || print STDERR "Maple can't be opened!\n";

#Send commands via print

print MAPLE "interface(plotdevice=gif,plotoutput=`$maplegif`,plotoptions=`width=500,height=300`);\n";
print MAPLE "plot($A * x^2 + $B * x + $C, x=-5..5);\n";
print MAPLE "quit;\n";
close(MAPLE);

#Set up some unique file names

$math_in = "tmp/math$pid.in";
$math_out = "tmp/math$pid.out";

#Construct a batch input file

open(MATH, "> $math_in") || print STDERR "Math can't be opened!\n";
print MATH "Solve[$A x^2 + $B x + $C == 0] \n";
print MATH "Quit \n";
close(MATH);

#process the Mathematica output

open(TMP, "math -batchinput -batchoutput
<$math_in |");  while () {
    $roots .= $_ unless /(^License|^\n)/;
}

close(TMP);

#Return new form

print "
<HTML><HEAD><TITLE>Image Demo</TITLE></HEAD>
<BODY>
<FORM ACTION=\"imagedemo.cgi\">
<IMG SRC=$maplegif><P>

Solutions of $A <I>x</I><SUP>2</SUP> + $B <I>x</I> + $C = 0 are:<P>

<BLOCKQUOTE><PRE>$roots</PRE></BLOCKQUOTE>

A: <INPUT SIZE=3 NAME=A><BR>
B: <INPUT SIZE=3 NAME=B><BR>
C: <INPUT SIZE=3 NAME=C><BR>

<INPUT TYPE=SUBMIT>
</FORM>

<HR>
</BODY>
</HTML>";


Up: Strategies for using scripts

[HOME] The Geometry Center Home Page

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