#!/usr/local/bin/perl # Script to take arguments from ParAng.html, 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) Make Calculations. # (4) Generate return HTML page # # J.Brewer, Sept. 1999. ############################################################################## ############################################################################## # (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... $pier = $ip{'pier'}; $exp = $ip{'exp'}; $has = $ip{'has'}; $hah = $ip{'hah'}; $hamm = $ip{'hamm'}; $decs = $ip{'decs'}; $decdd = $ip{'decdd'}; $decmm = $ip{'decmm'}; ############################################################################## ############################################################################## # (2) Verification of arguments. ############################################################################## # Set the error flag $error = 0; # $pier, $has and $decs are not verified: defined via menu # Check validity of hah (no sign allocated to hah)... if ($hah > 8){ if (! $error){&first_error;} print "ERROR: Invalid value for HA `h'...\n"; } # Check validity of hamm... if ($hamm < 0 || $hamm > 59){ if (! $error){&first_error;} print "ERROR: Invalid value for HA `mm'...\n"; } # Check validity of decdd (no sign allocated to decdd)... if ($decdd > 85){ if (! $error){&first_error;} print "ERROR: Invalid value for Dec `dd'...\n"; } # Check validity of decmm... if ($decmm < 0 || $decmm > 59){ if (! $error){&first_error;} print "ERROR: Invalid value for Dec `mm'...\n"; } # Check validity of exp time... if ($exp < 0 || $exp > 7200){ if (! $error){&first_error;} print "ERROR: negative or ridiculously long exposure time...\n"; } # Bail out if an error occured... if ($error){exit(1);} ############################################################################## ############################################################################## # (3) Make Calculations... ############################################################################## # >>> Note: PERL uses radians, not degrees... <<< # Convert geographical latitude of La Silla to radians... $lat = -29.25*(3.142/180); # Calculate hour angle (in rads) at mid-exposure... $ha = ($hah*15 + $hamm*(15/60))*(3.142/180); if ($has eq "-"){ $ha = -1*$ha } $ha = $ha + (($exp/2)/3600)*15*(3.142/180); # Calculate declination (in rads)... $dec = ($decdd + $decmm/60)*(3.142/180); if ($decs eq "-"){ $dec = -1*$dec; } # Calculate airmass at mid-exposure... $amass = 1.0/(sin($dec)*sin($lat) + cos($dec)*cos($lat)*cos($ha)); &trun($amass,2); # Calculate sin(pa) mid-exposure using eqtn. from Filippenko... $spang = (sin($ha)*cos($lat))/sqrt(1.0-(sin($lat)*sin($dec)+cos($lat)*cos($dec)*cos($ha))**2); # Calculate parallatic angle in degrees... $pang = asin($spang); $pang = $pang*(180/3.142); # Below are the transformations which Filippenko neglected to mention... if ($dec > $lat){ $pang = 180 - $pang; } if ((cos($ha) - tan($lat)/tan($dec) < 0.) && ($dec < $lat)){ $pang = 180 - $pang; } # Calculate correct DFOSC rotator angle.. if ($pier eq "E"){ # Telescope east of pier, dfosc angle=pa $dang = $pang }else{ # Telescope west of pier, dfosc angle=pa-180 $dang = $pang -180 } if ($dang < -100){ # Out of limits, rotate slit by 180 degrees to east... $dang = $dang+180 } if ($dang > 100){ # Out of limits, rotate slit by 180 degrees to west... $dang = $dang-180 } # Round off values... &trun($pang,1); &trun($dang,1); ############################################################################## ############################################################################## # (4) Make plot of parallatic angle as a function of HA for given dec... ############################################################################## # To avoid problems with netscape caching PS files, I allocate an ID # number to each file that is generated. This ID number is also used as a # strike counter # Increment the counter value... open (FILE, "<" . "public/strikes") || die "Cannot open strikes for reading"; $hits = ; close (FILE); $hits++; open (FILE, ">" . "public/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 "ParAng$old.ps"){unlink "ParAng$old.ps";} # Force a known path (external user has no path to inherit!). $ENV{"PATH"} = ".:/usr/local/bin/:/bin/"; open (FILE, ">" . "public/ip4sm") || die "Cannot open ip4sm for reading"; print FILE "$decs $decdd $decmm ParAng$hits.ps \n"; close (FILE); system("sm < DrawPA.sm"); ############################################################################## ############################################################################## # (5) Generate return HTML page ############################################################################## $dateX = `date`; print < DFOSC Parallactic Angle Calculation
[2p2 Logo]

DFOSC Parallactic Angle Calculation

[DK TN]



Entered Parameters

Pier side: $pier no units
Exp. time: $exp seconds
H.A. (start): $has$hah:$hamm h:mm
Declination: $decs$decdd:$decmm dd:mm


Results

Note: Rotate the DFOSC in steps of less than 45 degrees, checking between steps that no cables are caught.


This Page Created:
$dateX
Since 10 Sep.99:
$hits
Comments:
jbrewer\@eso.org
end_of_print ############################################################################## ############################################################################## # 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); } ############################################################################## # Rounding off subroutine... ############################################################################## sub trun { $_[0]=int($_[0]*10**$_[1]+.5)/10**$_[1]; } ############################################################################## # arcsine subroutine... ############################################################################## sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) } ############################################################################## # tan subroutine... ############################################################################## sub tan { sin($_[0])/cos($_[0]) }