[LON-CAPA-cvs] cvs: loncom /cgi plot.gif

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 28 Feb 2002 21:02:32 -0000


matthew		Thu Feb 28 16:02:32 2002 EDT

  Modified files:              
    /loncom/cgi	plot.gif 
  Log:
  Now supports eps files.  A change in the input line breaks this version 
  with respect to lonplot.pm of version 1.52 or earlier.
  
  
Index: loncom/cgi/plot.gif
diff -u loncom/cgi/plot.gif:1.7 loncom/cgi/plot.gif:1.8
--- loncom/cgi/plot.gif:1.7	Fri Dec 21 11:10:58 2001
+++ loncom/cgi/plot.gif	Thu Feb 28 16:02:32 2002
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 #
-# $Id: plot.gif,v 1.7 2001/12/21 16:10:58 matthew Exp $
+# $Id: plot.gif,v 1.8 2002/02/28 21:02:32 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -29,14 +29,18 @@
 $|=1;
 
 my $tmpdir = '/home/httpd/perl/tmp/';
-my $filename = $ENV{'QUERY_STRING'};
-
-if ($filename =~ /\// |
-    $filename !~ /_plot.data$/) {
-    die;
+my %data;
+foreach (split/&/,$ENV{'QUERY_STRING'}) {
+    my ($name,$value)=split/=/;
+    $data{$name}=$value;
 }
+my $filename = $data{'file'};
+die if ($filename =~ /\// || $filename !~ /_plot.data$/);
 $filename = $tmpdir . $filename;
-if (-e $filename) {
+die "$data{'file'} does not exist\n" if (! -e $filename);
+
+my $output = $data{'output'};
+if ($output eq 'gif') {
     open PLOT, "gnuplot $filename |";
     print <<"END";
 Content-type: image/gif
@@ -45,5 +49,11 @@
     while ($_=<PLOT>) {
 	print;
     }
+} elsif ($output eq 'eps') {
+    system ("gnuplot $filename");
+} else {
+    die "output $output is not a recognized value or has no value\n";
 }
+
+