Plotting functions and data with Perl CGI controlling Gnuplot

Plotting functions and data with Perl CGI controlling Gnuplot

Post by Michael Skippe » Wed, 07 Jun 2000 04:00:00



Hello,

I am writing a Perl CGI that will accept a function and some x-y data from
an HTML web page form, pass the info to Gnuplot which will generate a .gif
file (containing both the data points and a plot of the function) and serve
it back to the browser.  I understand Perl-CGI-html well and have been
moderately successful in controlling Gnuplot with Perl as well.  However,
some "tutorial" information and examples could be very helpful.  I already
have the Gnuplot 3.7 manual.  Do you have any resources or recommended
sources of information on this topic - specifically including plotting
functions with Gnuplot through cgi?

Server: Unix/Apache
Gnuplot: Version 3.7

Michael Skipper
www.slowgt.com

 
 
 

Plotting functions and data with Perl CGI controlling Gnuplot

Post by Lauren Clark » Wed, 07 Jun 2000 04:00:00


Michael,

This is not too difficult (at least on the NT/IIS side, which is what I do.
gnuplot, having its roots in unix can only help here).

Tips:
Use gnuplot in batchmode
Use set terminal to GIF (or PGN) to cause gnuplot (note the small g) output
to go to a file.

A brief look at "batchmode" and "set terminal" in the gnuplot help should
get you started.

-lc

----- Original Message -----


Sent: Tuesday, June 06, 2000 9:25 PM
Subject: Plotting functions and data with Perl CGI controlling Gnuplot

> Hello,

> I am writing a Perl CGI that will accept a function and some x-y data from
> an HTML web page form, pass the info to Gnuplot which will generate a .gif
> file (containing both the data points and a plot of the function) and
serve
> it back to the browser.  I understand Perl-CGI-html well and have been
> moderately successful in controlling Gnuplot with Perl as well.  However,
> some "tutorial" information and examples could be very helpful.  I already
> have the Gnuplot 3.7 manual.  Do you have any resources or recommended
> sources of information on this topic - specifically including plotting
> functions with Gnuplot through cgi?

> Server: Unix/Apache
> Gnuplot: Version 3.7

> Michael Skipper
> www.slowgt.com

>  - -
> [[[[ to unsubscribe from info-gnuplot, send an email with body
> unsubscribe info-gnuplot

> ]]]]


 
 
 

Plotting functions and data with Perl CGI controlling Gnuplot

Post by Peter Bos » Thu, 08 Jun 2000 04:00:00


Hello,

im sorry to say that i dont have any informations. But im very
interested in this CGI. Will You publish it somewhere? (URL?)


Quote:> I am writing a Perl CGI that will accept a function and some x-y data from
> an HTML web page form, pass the info to Gnuplot which will generate a .gif
> file (containing both the data points and a plot of the function) and serve
> it back to the browser.  I understand Perl-CGI-html well and have been
> moderately successful in controlling Gnuplot with Perl as well.  However,
> some "tutorial" information and examples could be very helpful.  I already
> have the Gnuplot 3.7 manual.  Do you have any resources or recommended
> sources of information on this topic - specifically including plotting
> functions with Gnuplot through cgi?

Greetings

Peter

 
 
 

1. gnuplot CGI in Perl on Win2K

I'm having more of a Perl problem that a gnuplot problem I think but I'd
like to see if anyone could shed some light on this.  I wrote a Perl CGI
script to run gnuplot and spit back the GIF image it generates.  It works
fine on my Linux/Apache machine but I need to port it to Windows for a
customer and am having troubles.  I've tried a few of the binary
distributions available for gnuplot 3.7.1 (gp371w32.zip, gp371dj2.zip, and
gp371cyg.zip).

The latest incarnation of my script is below.  It runs on the command line
fine spitting out the header followed by the GIF data.  from a web browser,
I get nothing or a broken graphic.  I'm guessing something is getting into
the return data and screwing it up but I don't see it.  Thanks in advance
for any suggestions,

-- Paul

Oh, my setup is as follows: Win2000-Pro SP-1, IIS, ActivePerl build 623 all
on my trusty laptop.

#!/bin/perl -w
# --------------------------------------------------------------------------
--
# FILENAME    : chart.pl
# DESCRIPTION : CGI script to generate plots using GNUPlot
# AUTHOR      : Paul Dugas
# --------------------------------------------------------------------------
--

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use IPC::Open2;

$| = 1;    # autoflush stdout

#
# constants
#
#my $gnuplot = 'c:/inetpub/scripts/wgnupl32.exe';  # from gp371w32.zip
my $gnuplot = 'c:/inetpub/scripts/gnuplot.exe';   # from gp371dj2.zip
#my $gnuplot = 'c:/inetpub/scripts/wgnuplot.exe';  # from gp371cyg.zip

#
# start GNUPlot
#
my ($rdrfh, $wtrfh);
my $pid = open2($rdrfh, $wtrfh, $gnuplot);
die "$gnuplot failed." unless defined $pid;

#
# send the plot script
#
print $wtrfh <<END_PLOT;
  set autoscale
  set terminal gif
  plot cos(x)
  exit
END_PLOT
close($wtrfh) or die "failed to close($wtrfh): $!";

#
# read the image
#
binmode $rdrfh or die "binmode $rdrfh failed: $!";
my ($gif, $gif_len, $buf, $buf_len);
while ($buf_len = read($rdrfh, $buf, 16384))
{
  $gif .= $buf;
  $gif_len += $buf_len;
die "No response from gnuplot." unless defined $gif;

#
# cleanup GNUPlot
#
close($rdrfh) or die "failed to close($rdrfh): $!";
waitpid($pid, 0);

#
# send the response
#
binmode STDOUT or die "binmode STDOUT failed: $!";
print STDOUT header(-type=>'image/gif',
                    -expires=>'now',
                    -Cache_Control=>'no-cache; must-revalidate',
                    -Pragma=>'no-cache'),
             $gif;

#
# done
#
0;

2. Sprite Question

3. Calling gnuplot from Perl-Script produces no x11-plot

4. Collision points with SOLID

5. How can I plot PERIODIC functions in GNUplot?

6. Mpegs and mpeg editor wanted !!!

7. plotting straight lines for erfc function data points

8. jobs offers/requiries

9. plot function of a data file?

10. Plotting data with errorbars and functions

11. plotting discrete data from a function ?

12. function & data plot

13. to plot a binary-format data via gnuplot