#!/usr/local/bin/perl # # Demo CGI perl script for handling requests from the sample form # idl-form.html with the WWW Client Browser as the user I/F front-end # and IDL as a background process. # # mathews@nssdc.gsfc.nasa.gov # # $Header: /usr/local/etc/httpd/cgi-bin/idl-form.cgi,v 1.2 1995/05/17 23:10:13 mathews Exp $ # # Copyright 1994 Jason Mathews # Unpublished work. # Permission granted to use and modify this program so long as the # copyright above is maintained, modifications are documented, and # credit is given for any use of the program.. # # This program assumes there is a /idl directory in the HTML document # root with a sub-directory tmp that is a symbolic link to /tmp # and the HTML form "mfi-wplt.html" is also located in /idl. # # See http://lepmfi.gsfc.nasa.gov/idl/mfikp/mfi-wplt.html # # Written by: Laura Smith, July 1999. # Using Perl version 5.00503 ## # debug mode: change to DEBUG=1 for debugging $debug = 0; # physical location of your cgi-lib.pl #$cgi_lib = '/www/cgi-bin/cgi-lib.pl'; #require $cgi_lib; #&ReadParse; # Read in all the variables set by the form require "./CGI.pm"; $interface = new CGI; #print $interface->header; print $interface->header('text/html'); # print $interface->start_html('-title' => "Plot Results", '-TEXT' => "#FFFFFF", '-LINK' => "#C0C0C0", '-VLINK' => "#008000", '-BGCOLOR' => "#000000", '-background' => "../mfi/laura/blue.JPG", '-alink' => "#00FFFF"); # temporary work files $idl_prog = "/tmp/idl.pro"; $gif_file = "/tmp/idl_$$.gif"; $ps_file = "/tmp/idl_$$.ps"; $dat_file = "/tmp/idl_$$.dat"; $psplot = "pspt.cgi"; $ps_data = "/tmp/idlps_$$.dat"; # If we use the same image file name then the cache will keep a # copy of it and changes will not be seen and simultaneous users # of this script might overwrite the same file while the browser # is displaying it, therefore we append the process id ($$) to # the filename to make it unique. The only drawback is that we # need to do a cleanup after the script is run, such as using a # cron job that deletes all files older than one day as below: # 0 2 * * * find /tmp -name idl\*.gif -mtime +1 -exec rm -f {} \; if ($debug) { print "DEBUG http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}"; print "Form Input"; EOH } # create the plot_arr and initialize it $str = "instr"; @in_arr; for($i=0; $i<23; $i++) { $in_arr[$i] = 0; } #print "\n
"; $in_arr[0] = 1 if $interface->param('instr0'); $in_arr[1] = 1 if $interface->param('instr1'); $in_arr[2] = 1 if $interface->param('instr2'); $in_arr[3] = 1 if $interface->param('instr3'); $in_arr[4] = 1 if $interface->param('instr4'); $in_arr[5] = 1 if $interface->param('instr5'); $in_arr[6] = 1 if $interface->param('instr6'); $in_arr[7] = 1 if $interface->param('instr7'); $in_arr[8] = 1 if $interface->param('instr8'); $in_arr[9] = 1 if $interface->param('instr9'); $in_arr[10] = 1 if $interface->param('instr10'); $in_arr[11] = 1 if $interface->param('instr11'); $in_arr[12] = 1 if $interface->param('instr12'); $in_arr[13] = 1 if $interface->param('instr13'); $in_arr[14] = 1 if $interface->param('instr14'); $in_arr[15] = 1 if $interface->param('instr15'); $in_arr[16] = 1 if $interface->param('instr16'); $in_arr[17] = 1 if $interface->param('instr17'); $in_arr[18] = 1 if $interface->param('instr18'); $in_arr[19] = 1 if $interface->param('instr19'); $in_arr[20] = 1 if $interface->param('instr20'); $in_arr[21] = 1 if $interface->param('instr21'); $in_arr[22] = 1 if $interface->param('instr22'); #for ($p=0;$p<23;$p++) { # print $in_arr[$p],","; #} #print "\n
"; # determine the format of the user imputted time interval, and determine the plot interval $startime = $interface->param('start'); $stoptime = $interface->param('stop'); $tformat = 0; $tformat = 1 if $interface->param('time') eq 'YYYYMMDD'; ($s,$min,$hr,$mday,$m,$y,$wday,$yday,$isdst) = localtime(time); if ($y > 100) { $y = $y - 100 + 2000; } else { $y = $y + 1900; } #print "$y
\n"; if ($tformat) { $y1 = substr($startime,0,4); $y2 = substr($stoptime,0,4); $m1 = substr($startime,4,2); $m2 = substr($stoptime,4,2); $d1 = substr($startime,6,2); $d2 = substr($stoptime,6,2); #print "start time: $y1 $m1 $d1
\n"; #print "end time: $y2 $m2 $d2
\n"; $t = 1; #check to make sure that dates are valid if (($y1>$y2) || ($y1<1994) || ($y2>$y)) { print "
You entered in an invalid date range. Click the back button to try again.
\n"; } elsif ((($y1==1994) && ($m1<10)) || (($y1==1994) && ($m1==10) && ($d1<=16))) { print "
You entered in an invalid date range. Click the back button to try again.
\n"; } elsif ((($y2==$y) && ($m2>$m)) || (($y2==$y) && ($m2==$m) && ($d2>$mday))) { print "
You entered in an invalid date range. Click the back button to try again.
\n"; } #junk values so that the generated idl program doesn't crash $doy1 = 1; $doy2 = 2; } else { $y1 = substr($startime,0,4); $y2 = substr($stoptime,0,4); $y2 = substr($stoptime,0,4); $doy1 = substr($startime,5,3); $doy2 = substr($stoptime,5,3); #check to make sure that the dates are valid if (($y1>$y2) || ($y1<1994) || ($y2>$y)) { print "
You entered in an invalid date range. Click the back button to try again.
\n"; } elsif ((($y1==$y) && ($doy1<319)) || (($y2==$y) && ($doy2>$yday))) { print "
You entered in an invalid date range. Click the back button to try again.
\n"; } #junk values so that the generated idl doesn't crash $d1 = 11; $d2 = 21; $m1 = 11; $m2 = 11; $t=0 } # now get the start and stop MM:HH:SS $startmhs = $interface->param('startmhs'); $stopmhs = $interface->param('stopmhs'); $mm1 = substr($startmhs,0,2); $mm2 = substr($stopmhs,0,2); $hh1 = substr($startmhs,2,2); $hh2 = substr($stopmhs,2,2); $ss1 = substr($startmhs,4,2); $ss2 = substr($stopmhs,4,2); # now check to make sure that the times are valid if($mm1 > 59) { $mm1 = 59; } if($mm1 < 0) { $mm1 = 0; } if($mm2 > 59) { $mm2 = 59; } if($mm2 < 0) { $mm2 = 0; } if($hh1 > 23) { $hh1 = 23; } if($hh1 < 0) { $hh1 = 0; } if($hh2 > 23) { $hh2 = 23; } if($hh2 < 0) { $hh2 = 0; } if($ss1 > 59) { $ss1 = 59; } if($ss1 < 0) { $ss1 = 0; } if($ss2 > 59) { $ss2 = 59; } if($ss2 < 0) { $ss2 = 0; } # check to see if spike removal is necessary, default to no $sp = 0; $sp = 1 if $interface->param('spkrm') eq 'YES'; # check to see if Pb and Pth should be overplotted, default to no $op = 0; $op = 1 if $interface->param('oplt') eq 'YES'; # determine the time resolution #time interval [1,0,0] 1 min (1), [0,1,0] = 3 sec (2), [0,0,1] = 1 hour (0) $time = 1; $date[0] = 0; $date[1] = 0; $date[2] = 0; $var = $interface->param('time1'); if ($var eq '1_hr') { $date[2] = 1; $time = 0; } elsif ($var eq '3_sec') { $date[1] = 1; $time = 2; } else { $date[0] = 1; } #print $date[0],$date[1],$date[2]; # grab the coordinate system type $csys = 0; $csys = 1 if $interface->param('coord') eq 'GSE'; #@max_min = (-3000) x 46; for($d=0;$d<46;$d++) { $max_min[$d] = -3000; } @name_arr=("B","Bx","By","Bz","Theta","Phi","V","Vx","Vy","Vz","VTheta","VPhi","Np","Vth","Psw","Psb","Pth","Beta","Va","Ma","Mms","Epsilon","Vbs"); if (!open(PROG, "> $idl_prog")) { # print &PrintHeader; print <

ERROR: Could not create IDL program

"; EOH } print PROG <IDL program
';
  open(PROG, $idl_prog);
  print ;
  $idl_log = '/tmp/idl.log';
} else {
  $idl_log = '/tmp/idl.log';
}

close(PROG);


# Setup IDL environment

$idl_dir  = '/usr/local/rsi/idl';
$lcl_dir  = '/usr/local/bin';
$ENV{'IDL_DIR'}=$idl_dir;
$ENV{'IDL_PATH'}="\+/data/wind/istplib:\+$idl_dir/lib:\+/home/user/asz/idl/lib";
$ENV{'IDL_STARTUP'} = '' if $ENV{'IDL_STARTUP'};
$ENV{'IDL_MASTER_PATH'}="/home/user/asz/idl/lib/aplot/";

# Run IDL in batch with IDL program

#system "$idl_dir/bin/idl $idl_prog > $idl_log 2>&1";
system "$lcl_dir/idl $idl_prog > $idl_log 2>&1";
#system("$lcl_dir/idl $idl_prog");
#unlink $idl_prog;

if ($debug) {
  print '

IDL output

';
  open(LOG, $idl_log);
  print ;
  close(LOG);
  print '
'; unlink $idl_log; } # Check if output exists and has a non-zero file length. for($t=0; $t<46; $t++) { $maxminarr[$t] = $max_min[$t] . ":"; } $maxmin = @maxminarr . ":"; $lenfile = length($dat_file); $lenmaxmin = length($maxmin); #print "$maxmin"; if (!$debug) { print "
\n"; print "\n"; print "Plot Results\n"; print ""; print ""; print "
\n"; print "

Wind MFI Plot

\n"; if (-s $gif_file) { print qq! \n!; } else { unlink $gif_file; if (!$debug) { print "IDL Graphics Error"; EOH } print "\n
An error was encountered while generating the plot.\n"; } } ## now get the high and low ranges that user can input if desired for the instruments to be plotted print "
\n"; $st1 = "min"; $st2 = "max"; print "You may enter in a high and low range for the parameter(s) that you selected.

\n"; for($k=0; $k<23; $k++) { # check to see that instrument has been chosen and is not one that already has fixed ranges (theta, phi, # vtheta, or vphi) if($in_arr[$k] == 1 && $k != 10 && $k != 11 && $k != 4 && $k !=5) { $var1 = $st1.$k; $var2 = $st2.$k; print "",$name_arr[$k],"
\n"; print "Low: \n"; print "High:

\n"; } } $datakey = 1; #make an array of everything so that it can be written to a file and read in if necessary to create a ps file for ($g=0; $g<46; $g++) { $maxminarr[$g] = $max_min[$g] . ":"; } $lenmaxmin = length($maxminarr); $lendatfile = length($dat_file); #print "
length of datfile name: $lendatfile\n
"; @file_array = (@in_arr, @date, $tformat, $startmhs, $stopmhs, $sp, $op, $datakey, $csys, $startime, $stoptime, $dat_file, @maxminarr); #use FileHandle #my $fh = new FileHandle("> $ps_data"); open(FD, "> $ps_data") || die; print FD @file_array; #foreach $line (@file_array) #{ # print FD "$line\n"; #} close(FD); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

\n"; #print "
\n"; $gfile1 = "/idl$gif_file"; $in_arr = "010101"; print "


\n"; print "a postscript version of the graph.
\n"; $Bx = "Bx"; print "

\n"; print "

Enter information here to get date specific data:
\n"; print "Input date (YYYYMMDD): \n"; print "      Input time (HHMMSS):
\n"; print "
\n"; print "\n

\n"; print "\n"; print "
Click here to go back
\n"; print "
Laura.C.Smith.1\@gsfc.nasa.gov
"; print "
Last Update: January 2000.
"; print $interface->end_html(); ## ## end of mfi_wplt.cgi ##