Presenting Mathematical Concepts on the World Wide Web
Forms & Scripts
Using Scripts: Image Demo Source Code
#!/usr/local/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>";
Back: Strategies for Using Scripts
Up:
Forms & Scripts
Presenting Mathematical Concepts on the World Wide Web.
Copyright © 1997 by
Carol Scheftic.
All rights reserved.
(This section was originally copyrighted in 1996 by
The Geometry Center
and is re-used here with permission.)
Please send comments on this page,
or requests for permission to re-use material from this page, to:
scheftic@geom.umn.edu
Page established 1-Jun-97;
last updated Thursday, 24-Jul-1997 01:55:34 CDT.