ObservationTimeEstimate.php 0000644 0001751 0001751 00000050374 12306061116 015726 0 ustar henrik henrik \n" : "";
return "" . $BreakStr;
}
//-----------------------------------------------------------------------------------------
// function CheckBoxBtn: Creates/returns the html code for a checkbox.
// $VarName: the name of the POST or GET html variable
// $Value: the value of "$VarName".
// $Checked: sets the checkbox as checked or unchecked.
// $Break: if it has the value "break" a html break is added as well as a \n linebreaker.
//-----------------------------------------------------------------------------------------
function CheckBoxBtn($VarName, $Value, $Checked, $Break){
$CheckStr = ($Checked == "checked") ? " checked" : "";
$BreakStr = ($Break == "break") ? " \n" : "";
return "" . $BreakStr;
}
//-----------------------------------------------------------------------------------------
// function TextField: Creates/returns the html code for a text field.
// $VarName: the name of the POST or GET html variable
// $Value: the value of "$VarName".
// $Size: sets the width of the text field.
// $Break: if it has the value "break" a html break is added as well as a \n linebreaker.
//-----------------------------------------------------------------------------------------
function TextField($VarName, $Value, $Size, $Break){
$BreakStr = ($Break == "break") ? " \n" : "";
return "" . $BreakStr;
}
//-----------------------------------------------------------------------------------------
// function TextArea: Creates/returns the html code for a text area.
// $VarName: the name of the POST or GET html variable
// $Value: the value of "$VarName".
// $Size: sets the height and width of the text area.
// $Break: if it has the value "break" a html break is added as well as a \n linebreaker.
//-----------------------------------------------------------------------------------------
function TextArea($VarName, $Value, $Size, $Break){
$BreakStr = ($Break == "break") ? " \n" : "";
return "" . $BreakStr;
}
//-----------------------------------------------------------------------------------------
// function Submit: Creates/returns the html code for a submit button.
// $Value: the text displayed in the submit button.
// $Break: if it has the value "break" a html break is added as well as a \n linebreaker.
// $Action: if $Action is "no action" no action will take place oterwise the action value
// is entered.
//-----------------------------------------------------------------------------------------
function Submit($Value, $Action, $Break){
$BreakStr = ($Break == "break") ? " \n" : "";
$ActionValue = ($Action =="no action") ? " ":" action='" . $Action . "' ";
return " 3). Values: 80 120
$FileData = file($FileName);
$Opacity = "
Frequency $Frequency GHz is out of range!
";
// Assigning frequency and Opacity values and assigning them to array elements.
for ($k = 3; $k <= sizeof($FileData)-1; $k++){
$row = $FileData[$k];
$SpacePos = strpos($row, " ");
$TableFreq = substr($row,0,$SpacePos);
$TableOpacity = substr($row,$SpacePos,$SpacePos+10);
if (is_numeric(trim($TableFreq)) and is_numeric(trim($TableOpacity))) {
$FrequencyArr[] = $TableFreq;
$OpacityArr[] = $TableOpacity;
} // end if
} // end for
// Finding the correct frequency table interval and interpolating the
// Opacity value to be returned.
for ($k = 0; $k <= sizeof($FrequencyArr)-2; $k++) {
$FreqLow = $FrequencyArr[$k];
$FreqHigh = $FrequencyArr[$k+1];
$OpacityLow = $OpacityArr[$k];
$OpacityHigh = $OpacityArr[$k+1];
// Interpolate Opacity between lower and upper frequency values.
if ($Frequency >= $FreqLow and $Frequency <= $FreqHigh) {
$Fraction = ($FreqHigh - $Frequency)/($FreqHigh - $FreqLow);
$Opacity = $Fraction*$OpacityLow + (1.0 - $Fraction)*$OpacityHigh;
} // end if
} // end for
return $Opacity;
}
//-----------------------------------------------------------------------------------------
// Sets the Trec value as a constant in the first HEMT intervals and interpolates a value
// for the SIS reciever.
//-----------------------------------------------------------------------------------------
function TrecFunc($Frequency, $FileName){
// 'TrecTable.dat' begin reading on row 4 (array index -> 3). Values: 80 120
$FileData = file($FileName);
$Trec = "
Frequency $Frequency GHz is out of range!
";
// Assigning frequency and Trec values and assigning them to array elements.
for ($k = 3; $k <= sizeof($FileData)-1; $k++){
$row = $FileData[$k];
$SpacePos = strpos($row, " "); // Position of the first: " " (space).
$TableFreq = substr($row,0,$SpacePos); // First value in the data row.
$TableTrec = substr($row,$SpacePos,$SpacePos+10); // Second value in the data row.
// Checking numeric values and assigning the first and second values of a row.
if (is_numeric(trim($TableFreq)) and is_numeric(trim($TableTrec))) {
$FrequencyArr[] = $TableFreq;
$TrecArr[] = $TableTrec;
} // end if
} // end for
// Finding the correct frequency table interval and interpolating the
// Trec value to be returned.
for ($k = 0; $k <= sizeof($FrequencyArr)-2; $k++) {
// Temporary "simplifying" variables.
$FreqLow = $FrequencyArr[$k];
$FreqHigh = $FrequencyArr[$k+1];
$TrecLow = $TrecArr[$k];
$TrecHigh = $TrecArr[$k+1];
// Interpolate Trec between lower and upper frequency values.
if ($Frequency >= $FreqLow and $Frequency <= $FreqHigh) {
$Fraction = ($FreqHigh - $Frequency)/($FreqHigh - $FreqLow);
$Trec = $Fraction*$TrecLow + (1.0 - $Fraction)*$TrecHigh;
} // end if
} // end for
// Returning the interpolated reciever temperature.
return $Trec;
}
//-----------------------------------------------------------------------------------------
// Calculates the Tsys value
//
//-----------------------------------------------------------------------------------------
function TsysFunc($Trec, $Tgp, $Tatm, $Opacity, $Elevation){
$exparg = $Opacity/sin(deg2rad($Elevation));
$Tsys = ($Trec + $Tgp + $Tatm*(1.0 - exp(-$exparg)))*exp($exparg);
return $Tsys;
}
//-----------------------------------------------------------------------------------------
// Returns the observation time in seconds.
//-----------------------------------------------------------------------------------------
function ObsTimeFunc($Tsys, $ObsModeFactor, $Sensitivity, $Resolution){
$factor1 = ($Tsys*$ObsModeFactor)/$Sensitivity;
return ($factor1*$factor1*pow(10,-3))/$Resolution;
}
//-----------------------------------------------------------------------------------------
// purpose: intiate post variables with default values. Returns the value of the POST
// variable if it is already set. Othervise it returns the entered default value ($Default).
//-----------------------------------------------------------------------------------------
function InitPostVariables($PostVariable, $Default) {
if (!isset($_POST[$PostVariable])) {
return $Default; }
else {
return $_POST[$PostVariable];
} // end if
} // end function
//-----------------------------------------------------------------------------------------
// purpose: Creates a simple table given header information and cell in form of strings.
//-----------------------------------------------------------------------------------------
function Table($Header, $TableData, $Action) {
$NRows = sizeof($TableData);
$NCols = sizeof($TableData[0]);
if (strpos($Header,"table") > 0) {
$TableArr[] = $Header . "\n";
}
// Printing all cells row by row.
for ($m = 0; $m <= $NRows-1; $m++) {
$TableArr[] = "
";
for ($n = 0; $n <= $NCols-1; $n++) {
if ($TableData[$m][$n] == ""){
$TableArr[] = $TableData[$m][$n];
}
else if (strstr($TableData[$m][$n], 'title=')){
$TableArr[] = "
".
substr($TableData[$m][$n],6) . "
";
}
else {
$TableArr[] = "
" . $TableData[$m][$n]. "
";
} // end if
} // end for (inner)
$TableArr[] = "
\n";
} // end for (outer)
if ($Action == "end table") {
$TableArr[] = " \n \n";
}
return $TableArr;
}
//-----------------------------------------------------------------------------------------
// purpose: echoes the input array.
//-----------------------------------------------------------------------------------------
function EchoArray($StrArray) {
for ($k = 0; $k <= sizeof($StrArray)-1; $k++){
echo $StrArray[$k];
} // end for
} // end function
//-----------------------------------------------------------------------------------------
// Starting main script.
//-----------------------------------------------------------------------------------------
// Values for buttons.
$Checked = "checked";
$UnChecked = "unchecked";
$Break = "break";
$NoBreak = "nobreak";
// Setting POST variables to their default values if the script is loaded the first time.
$Frequency = InitPostVariables('Frequency', 86);
$Elevation = InitPostVariables('Elevation', 50);
$ObsMode = InitPostVariables('ObsMode', 'psw');
$Sensitivity = InitPostVariables('Sensitivity', 0.1);
$Resolution = InitPostVariables('Resolution', 12.5);
// If $Obsmode is 'psw' or 'bsw' the observe mode factor is 2.0 otherwise (for fsw) 1.0.
$ObsModeFactor = ($ObsMode == "bsw" or $ObsMode == "psw") ? 2.0:1.0;
// Setting and calculating the other values.
$Tgp = (double) 20.0; // Ground pickup temperature. Some 20K.
$Tatm = (double) 260.0; // Estimate of the atmosphere's temperature .
//-----------------------------------------------------------------------------------------
// Setting conditions and warning text if the user enters parameters that are out of
// range
//-----------------------------------------------------------------------------------------
// Making sure the user is using the right intervals for the frequency.
$FrequencyInterval = ($Frequency < 18 or $Frequency > 116 or
($Frequency > 49.8 and $Frequency < 85)) ? "out of range":"in range";
// If the entered frequency is out of range a red error message is displayed.
$FrequencyText = ($FrequencyInterval == "out of range") ? "
Frequency out of range " : "Frequency";
// Making sure the user is using the right intervals for the frequency resolution.
$ResolutionInterval = ($Resolution < 2 or $Resolution > 1280000) ? "out of range":"in range";
// If the entered frequency resolution is out of range a red error message is displayed.
$ResolutionText = ($ResolutionInterval == "out of range") ? "
Frequency resolution out of range " : "Resolution";
// Making sure the user is using the right intervals for the elevation.
$ElevationInterval = ($Elevation < 6.0 or $Elevation > 87) ? "out of range":"in range";
// If the entered elevation is out of range a red error message is displayed.
$ElevationText = ($ElevationInterval == "out of range") ? "
Elevation out of range " : "Elevation";
// Making sure the user is using a sensitivity greater than zero.
$SensitivityInterval = ($Sensitivity <= 0.0) ? "out of range":"in range";
// If the entered elevation is out of range a red error message is displayed.
$SensitivityText = ($SensitivityInterval == "out of range") ? "
Sensitivity not applicable " : "Sensitivity";
// Initializing error counter wich must be zero if the Tsys, Trec and the
// observation time, Tsys, is to be calculated and displayed.
$n_errors = 0;
//-----------------------------------------------------------------------------------------
// Creating the html document
//-----------------------------------------------------------------------------------------
echo "\n";
echo "\n";
echo "Observing time estimate";
echo "\n\n";
echo "\n";
echo "
\n";
echo "
\n";
echo "
Observing time estimates
\n
\n";
echo "
\n";
echo "
\n";
// including explanatory text.
include("ObserveTimeExplanation.html");
echo "