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

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 21 Jun 2004 20:04:29 -0000


matthew		Mon Jun 21 16:04:29 2004 EDT

  Modified files:              
    /loncom/cgi	plot.gif 
    /loncom/xml	lonplot.pm 
  Log:
  Changes for moving to gnuplot 4.0
  lonplot.pm: detect gnuplot version on start and pass it to plot.gif
  plot.gif: Send out correct content type (gif|png) if passed in.
  
  
Index: loncom/cgi/plot.gif
diff -u loncom/cgi/plot.gif:1.10 loncom/cgi/plot.gif:1.11
--- loncom/cgi/plot.gif:1.10	Wed Sep 24 17:15:55 2003
+++ loncom/cgi/plot.gif	Mon Jun 21 16:04:29 2004
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 #
-# $Id: plot.gif,v 1.10 2003/09/24 21:15:55 matthew Exp $
+# $Id: plot.gif,v 1.11 2004/06/21 20:04:29 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -43,10 +43,10 @@
 die "$data{'file'} does not exist\n" if (! -e $filename);
 
 my $output = $data{'output'};
-if ($output eq 'gif') {
+if ($output eq 'gif' || $output eq 'png') {
     open PLOT, "gnuplot $filename |";
     print <<"END";
-Content-type: image/gif
+Content-type: image/$output
 
 END
     while ($_=<PLOT>) {
@@ -72,6 +72,3 @@
 } else {
     die "output $output is not a recognized value or has no value\n";
 }
-
-
-
Index: loncom/xml/lonplot.pm
diff -u loncom/xml/lonplot.pm:1.96 loncom/xml/lonplot.pm:1.97
--- loncom/xml/lonplot.pm:1.96	Wed May 26 15:44:20 2004
+++ loncom/xml/lonplot.pm	Mon Jun 21 16:04:29 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Dynamic plot
 #
-# $Id: lonplot.pm,v 1.96 2004/05/26 19:44:20 matthew Exp $
+# $Id: lonplot.pm,v 1.97 2004/06/21 20:04:29 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,8 +36,17 @@
 use Apache::lonxml;
 use Apache::edit;
 
+use vars qw/$weboutputformat $versionstring/;
+
 BEGIN {
-  &Apache::lonxml::register('Apache::lonplot',('gnuplot'));
+    &Apache::lonxml::register('Apache::lonplot',('gnuplot'));
+    #
+    # Determine the version of GNUPLOT
+    $weboutputformat = 'gif';
+    $versionstring = `gnuplot --version`;
+    if ($versionstring =~ /^gnuplot 4/) {
+        $weboutputformat = 'png';
+    }
 }
 
 ## 
@@ -460,7 +469,7 @@
 	## return image tag for the plot
 	if ($target eq 'web') {
 	    $result .= <<"ENDIMAGE";
-<img src    = "/cgi-bin/plot.gif?file=$filename.data&output=gif" 
+<img src    = "/cgi-bin/plot.gif?file=$filename.data&output=$weboutputformat" 
      width  = "$plot{'width'}"
      height = "$plot{'height'}"
      align  = "$plot{'align'}"