#!/usr/local/bin/perl # Script to take arguments from Exp_Meter.html, call C programs to # make plots and tables, and return an HTML page to the client. # # The script can be considered as consisting of the following parts: # # (1) Read in arguments passed to script. # (2) Verification of arguments. # (3) Determine sky magnitude # (4) Read, increment and write id number. Delete old files. # (5) Execute C programs to make graph and table # (6) Generate return HTML page # # J.Brewer 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... $inst = $ip{'inst'}; $filt = $ip{'filt'}; $see = $ip{'see'}; $airm = $ip{'airm'}; $s_or_m = $ip{'s_or_m'}; $msky = $ip{'msky'}; $moon = $ip{'moon'}; $pnt_src = $ip{'pnt_src'}; $mobj = $ip{'mobj'}; $l_mag = $ip{'l_mag'}; $l_xt = $ip{'l_xt'}; $h_mag = $ip{'h_mag'}; $h_xt = $ip{'h_xt'}; $m_xt = $ip{'m_xt'}; ############################################################################## ############################################################################## # (2) Verification of arguments. ############################################################################## # Set the error flag $error = 0; # $inst, $filt, $moon and $pnt_src are not verified as they are defined # via pull/radio down menus # Seeing must be greater than 0 if ($see <= 0){ if (! $error){&first_error;} print "ERROR: Seeing must be greater than 0 \n"; } # The faintest sky magnitude is ~23, and the brightest ~17. Verify only # the faint limit in case the program is being used for stars embedded in # a nebula. if ($msky > 23){ if (! $error){&first_error;} print "ERROR: Sky Magnitude is unrealistically faint \n"; } # The minimum airmass is 1, while a erudite choice for maximum is 10 if($airm < 1 || $airm > 10){ if (! $error){&first_error;} print "ERROR: Airmass must be between 1 and 10 \n"; } # A reasonable range for the star/surface magnitude is -5 to 30 if($mobj < -5 || $mobj > 30){ if (! $error){&first_error;} print "ERROR: Choose Star magnitude between -5 and 30 \n"; } # Minimum xt should be >= 1 sec (shutter timing errors). if($l_xt < 1){ if (! $error){&first_error;} print "ERROR: Choose Minimum Exposure >= 1 second \n"; } # Check that maximum xt is larger than minimum xt... if($l_xt > $h_xt){ if (! $error){&first_error;} print "ERROR: Max Exposure must be larger than Min Exposure \n"; } # Low magnitude should be greater than -5 if($l_mag < -5){ if (! $error){&first_error;} print "ERROR: Choose Low Magnitude > -5 \n"; } # High magnitude should be less than 30 if($h_mag > 30){ if (! $error){&first_error;} print "ERROR: Choose High Magnitude < 30 \n"; } # High magnitude should be greater than Low Magnitude if($h_mag < $l_mag){ if (! $error){&first_error;} print "ERROR: High Magnitude must be larger than Low Magnitude \n"; } # Maximum Exposure should be >= 1 second if($m_xt < 1){ if (! $error){&first_error;} print "ERROR: Maximum Exposure should be >= 1 second \n"; } # Bail out if an error occured... if ($error){exit(1);} ############################################################################## ############################################################################## # (3) Determine sky mag if days from new moon specified... ############################################################################## # N.B. This section only executed if user opted to specify moon age... if ($s_or_m eq "m"){ # Below is a 2-d array with skybrightnesses for U,B,V,R,I filters # (columns) at moon ages of 0, 3, 7, 10 and 14 days (rows). @sky_mags = ( [22.0, 22.7, 21.8, 20.9, 19.9], [21.5, 22.4, 21.7, 20.8, 19.9], [19.9, 21.6, 21.4, 20.6, 19.7], [18.5, 20.7, 20.7, 20.3, 19.5], [17.0, 19.5, 20.0, 19.9, 19.2], ); @f_list = ("U","B","V","R","I"); # The order of the filters (columns). @m_list = (0,3,7,10,14); # The order of the days (rows). # Find the column for the filter... $i=0; foreach $filter (@f_list){ if($filter eq $filt){ $filt_id = $i; } $i++; } # Find the row for the days... $i=0; foreach $days (@m_list){ if($days == $moon){ $moon_id = $i; } $i++; } # Assign appropriate value to msky... $msky = $sky_mags[$moon_id][$filt_id]; } ############################################################################## ############################################################################## # (4) 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 # Set the name of the id/counter file: $id_file = "strikes"; # Open file and read in current id value... open (FILE, "<" . $id_file) || die "Cannot open $id_file for reading"; $hits = ; close (FILE); # Incremented id value, open file a save new id... $hits++; open (FILE, ">" . $id_file) || die "Cannot open $id_file for writing"; print FILE $hits; close (FILE); # To avoid disk space problems, delete the (n-4)th files... $old = $hits - 4; if(-e "T$old.shtml"){unlink "T$old.shtml";} if(-e "G$old.gif"){unlink "G$old.gif";} if(-e "G$old.ps"){unlink "G$old.ps";} ############################################################################## ############################################################################## # (5) Execute C programs to make graph and table ############################################################################## # 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/"; if ($inst eq "DFOSC"){ # Execute programs compiled for DFOSC... system("DK_sn_d_g $filt $see $msky $mobj $pnt_src $airm $l_xt $h_xt"); rename("TEMP.ps","G$hits.ps"); rename("TEMP.gif","G$hits.gif"); system("DK_sn_d_t $filt $see $msky $l_mag $h_mag $pnt_src $airm $m_xt > T$hits.shtml"); } if ($inst eq "Dutch"){ # Execute programs compiled for DUTCH... system("DU_sn_d_g $filt $see $msky $mobj $pnt_src $airm $l_xt $h_xt"); rename("TEMP.ps","G$hits.ps"); rename("TEMP.gif","G$hits.gif"); system("DU_sn_d_t $filt $see $msky $l_mag $h_mag $pnt_src $airm $m_xt > T$hits.shtml"); } if ($inst eq "EFOSC2"){ # Execute programs compiled for EFOSC2... system("EF_sn_d_g $filt $see $msky $mobj $pnt_src $airm $l_xt $h_xt"); rename("TEMP.ps","G$hits.ps"); rename("TEMP.gif","G$hits.gif"); system("EF_sn_d_t $filt $see $msky $l_mag $h_mag $pnt_src $airm $m_xt > T$hits.shtml"); } ############################################################################## ############################################################################## # (6) Generate return HTML page ############################################################################## $dateX = `date`; print < S/N Calculation for the $inst
[ESO Logo]

S/N Calculation for the $inst

[ESO Logo]



Telescope/Atmospheric Parameters

Instrument: $inst (No units)
Filter: $filt (No units)
Seeing: $see (FWHM of PSF in arcseconds)
Sky Mag.: $msky (Mag/arcsec2)
Airmass: $airm (Note: airmass=1 at zenith)


Observational Parameters

end_of_print1 if ($pnt_src == 1){ print"

Graphical Output

Tabular Output

Star Magnitude ",$mobj,"(No units)\n"; }else{ print" Surface Brightness",$mobj,"(Mag/arcsec2) \n"; } print"            \n"; if ($pnt_src == 1){ print" Low Magnitude ",$l_mag," (No units) \n"; }else{ print" Low SB ",$l_mag," (Mag/arcsec2) \n"; } print < Minimum Exposure $l_xt (Seconds)             end_of_print2 if ($pnt_src == 1){ print" High Magnitude ",$h_mag," (No units) \n"; }else{ print" High SB ",$h_mag," (Mag/arcsec2) \n"; } print < Max Exposure $h_xt (Seconds)             Max Exposure $m_xt (Seconds)

Graph (Postscript)

View the Table

[S/N Graph (GIF)]

Options

Choose from:

(Note: to view the graph click left mouse button. To save the graph press shift and then click the middle mouse button.)


This Page Created:
$dateX
Since 15.Apr.98:
$hits
Comments:
jbrewer\@eso.org
end_of_print3 ############################################################################## ############################################################################## # 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); }