#!/usr/local/bin/perl # Script to take arguments from FilterDB.html, and return # an HTML page to the client. # # The script can be considered in as consisting of the following parts: # # (1) Read in arguments passed to script. # (2) Verification of arguments. # (3) Make Calculations. # (4) Generate return HTML page # # J.Brewer, August 1998. ############################################################################## ############################################################################## # (1) Read in arguments passed to script. ############################################################################## # Below is from Gundavaram (Nutshell book) $webmaster = "jbrewer\@eso\.org"; &parse_form_data (*ip); # For compactness, assign array elements to variables... $ccd = $ip{'ccd'}; $lbls = $ip{'lbls'}; $lo_x = $ip{'lo_x'}; $hi_x = $ip{'hi_x'}; $lo_y = $ip{'lo_y'}; $hi_y = $ip{'hi_y'}; $filt1 = $ip{'filt1'}; $filt2 = $ip{'filt2'}; $filt3 = $ip{'filt3'}; $filt4 = $ip{'filt4'}; ############################################################################## ############################################################################## # (2) Verification of arguments. ############################################################################## # Set the error flag $error = 0; # Only check graph limits; other values submitted via # pull down menus # Check validity of lo wavelength limit... if ($lo_x <= 0){ if (! $error){&first_error;} print "ERROR: Unphysical low-wavelength value...\n"; } # Check validity of hi wavelength limit... if ($hi_x > 1100){ if (! $error){&first_error;} print "ERROR: High wavelength limit beyond silicon band-gap\n"; } # Check that hi_x > lo_x... if ($lo_x > $hi_x){ if (! $error){&first_error;} print "ERROR: Low wavelength must be smaller than large wave\n"; } # Check validity of lo transmission %age limit... if ($lo_y < -10){ if (! $error){&first_error;} print "ERROR: Low TX value...\n"; } # Check validity of lo transmission %age limit... if ($lo_y > 110){ if (! $error){&first_error;} print "ERROR: High TX value...\n"; } # Check that hi_y is > lo_y... if ($lo_x > $hi_x){ if (! $error){&first_error;} print "ERROR: Low tx %age must be smaller than large tx %age\n"; } # Bail out if an error occured... if ($error){exit(1);} ############################################################################## ############################################################################## # (3) Read, increment and write id number. Delete old files. ############################################################################## # To avoid problems with netscape caching old GIF and PS files, I # allocate an ID number to each file that is generated. This ID number is # also used as a strike counter # Open file and read in current id value... open (FILE, "<" . strikes) || die "Cannot open strikes for reading"; $hits = ; close (FILE); # Incremented id value, open file a save new id... $hits++; open (FILE, ">" . strikes) || die "Cannot open strikes for writing"; print FILE $hits; close (FILE); # To avoid disk space problems, delete the (n-4)th files... $old = $hits - 4; if(-e "G$old.gif"){unlink "G$old.gif";} if(-e "G$old.ps"){unlink "G$old.ps";} ############################################################################## ############################################################################## # (4) Make plot: use c-shell script calling sm... ############################################################################## # Force a known path (external user has no path to inherit!). This is # needed as the sm program uses ppmtogif. $ENV{"PATH"} = ".:/usr/local/bin/:/bin/:/usr/local/netpbm/"; open (FILE, ">" . ip4sm) || die "Cannot open ip4sm for reading"; print FILE "$ccd $lbls $lo_x $hi_x $lo_y $hi_y $filt1 $filt2 $filt3 $filt4\n"; close (FILE); system("sm < DrawTX.sm"); rename("TEMP.gif","G$hits.gif"); rename("TEMP.ps","G$hits.ps"); ############################################################################## # (4) Generate return HTML page ############################################################################## $dateX = `date`; print < WFI Filter Transmission Plot
[eso logo]

WFI Filter Transmission Plot

[2p2 Logo]



Entered Parameters

Plot CCD: $ccd Labels: $lbls
Low X: $lo_x High X: $hi_x
Low Y: $lo_y High Y: $hi_y
Filter 1: $filt1 Filter 2: $filt2
Filter 3: $filt3 Filter 4: $filt4

(Click on graph to download PostScript)

Click to download PostScript


This Page Created:
$dateX
Strikes since Sept.99:
$hits
Comments:
jbrewer\@eso.org
end_of_print1 ############################################################################## ############################################################################## # sub first error: executed the first time an error occurs... ############################################################################## sub first_error{ print"Content-type: text/plain","\n\n"; print"You have entered invalid data, please return to the form and \n"; print"check your input using the below diagnostics \n\n\n"; $error = 1; } ############################################################################## # sub parse_form_data: decode arguments... ############################################################################## sub parse_form_data { local (*FORM_DATA) = @_; local ( $request_method, $query_string, @key_value_pairs, $key_value, $key, $value); $request_method = $ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $query_string = $ENV{'QUERY_STRING'}; } elsif ($request_method eq "POST") { read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); } else { &return_error (500, "Server Error", "Server uses unsupported method"); } @key_value_pairs = split (/&/, $query_string); foreach $key_value (@key_value_pairs) { ($key, $value) = split (/=/, $key_value); $value =~ tr/+/ /; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; if (defined($FORM_DATA{key})) { $FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value); } else { $FORM_DATA{$key} = $value; } } } ############################################################################## # sub return_error: Error routine for form decoding.... ############################################################################## sub return_error { local($status, $keyword, $message) = @_; print "Content-type: text/html", "\n"; print "Status: ", $status, " ", $keyword, "\n\n"; print <CGI Program -- Unexpected Error

$keyword


$message
Please contact $webmaster for more information. End_of_Error exit(1); }