<?php
/*
###########################################################################
RISE/TRANSIT/SET TIMES CALCULATOR FOR ANY GIVEN MONTH - WITH 30-DAY COOKIE.
FOR TOPOCENTRIC PERSPECTIVE TAKING INTO ACCOUNT GEOGRAPHIC LOCATION.
THIS PROGRAM WAS MODIFIED FOR LUNAR USE ONLY.
via The NASA/JPL Horizons API
AUTHOR : Jay Tanner - 2026
LANGUAGE : PHP v8.2.12
LICENSE : Public Domain
This program demonstrates the usage of the function:
RTS_Times_Table()
NOTE:
When the GPS (Lon, Lat, TimeZone) all equate to zero, the optional location
string is set to 'Null Island' automatically.
###########################################################################
*/
OB_Start(); // Initialize output buffer.
// ---------------------------------------------------------------
// Define the program cookie name and set it to expire in 30 days.
$CookieName = 'Rising-Transit-Setting-Times-Calculator';
$SetToExpireIn30Days = time() + 30*86400;
// ------------------------------------------------------------------
// Define JavaScript message to display in (TextArea1) while working.
$_COMPUTING_ = "TextArea1.innerHTML='W.O.R.K.I.N.G --- This may take several seconds.';";
// ---------------------------------
// Define PHP program and HTML info.
$_AUTHOR_ = 'Jay Tanner';
$_PROGRAM_VERSION_ = 'v1.00 - '; $at = "at Local Time "; $LTC = "UTC";
$_SCRIPT_FILE_PATH_ = Filter_Input(INPUT_SERVER, 'SCRIPT_FILENAME');
$_REVISION_DATE_ = $_PROGRAM_VERSION_ .'Revised: '. date("Y-F-d-l $at h:i:s A ($LTC", FileMTime($_SCRIPT_FILE_PATH_))."−05:00)";
$_BROWSER_TAB_TEXT_ = "Moon Local Rise/Transit/Set Times Table";
$_INTERFACE_TITLE_ = "<span style='font-size:15pt;'>Moon Rise/Transit/Set Times Table<br>For Any Given Year/Month and GPS Location on Earth</span><br><br><span style='font-size:12pt;'>Built Around The NASA/JPL Horizons API</span><br><span style='font-size:10pt;'>PHP Program by $_AUTHOR_</span>";
/* -------------------------------------
Define main TextArea text and background
colors and HTML table row span. If an
error is reported, then these colors
will change internally to red/white.
*/
$TxColor = 'black';
$BgColor = 'white';
// Home default GPS coordinates.
$DefaultLocLabel = 'Geneva, NY, USA';
$DefaultLonDeg = '-76.996490';
$DefaultLatDeg = '+42.868473';
$DefaultAltMet = '+0';
$DefaultTimeZone = '-05:00';
/* -----------------------------------
Define number of days in each month
for use with calendar computations.
*/
define('MONTHDAYS', '312831303130313130313031');
/* ----------------------------------------
Define 3-letter month name abbreviations
for use with calendar computations.
*/
define('MONTHS', 'JanFebMarAprMayJunJulAugSepOctNovDec');
/* ------------------------------------------
Define 3-letter weekday name abbreviations
for use with calendar computations.
*/
define('DOWs', 'SunMonTueWedThuFriSat');
// ---------------------------------------------
// Do this only if [SUBMIT] button was clicked.
$w = Filter_Input(INPUT_POST, 'SubmitButton');
if (!IsSet($w))
{
/* ----------------------------------------------------------------------
If this program is being called externally, rather than being executed
by clicking the [SUBMIT] button, and an active cookie also exists,
then restore the previously saved interface settings from it. If
the user leaves and comes back later, all the interface settings
will be remembered and restored if the cookie was not deleted.
That's all it does - remembers the previous interface settings.
*/
$w = Filter_Input(INPUT_COOKIE, $CookieName);
if (IsSet($w))
{
$CookieDataString = Filter_Input(INPUT_COOKIE, $CookieName);
list
(
$BodyID,
$TimeScale,
$StartBCAD,
$StartYear,
$StartMonth,
$StartDay,
$StartTime,
$TimeZone,
$StopBCAD,
$StopYear,
$StopMonth,
$StopDay,
$StopTime,
$DaySumYN,
$StepSize,
$LocLabel,
$LonDeg,
$LatDeg,
$AltMet,
$AUorKMorMI,
$LocLabel
) = Preg_Split("[\|]", $CookieDataString);
}
else
/* -----------------------------------------------------------
If there is no previous cookie with the interface settings,
then set the initial default interface startup values and
store them in a new cookie.
*/
{
$BodyID = '301';
$TimeScale = 'UT';
$StartBCAD = 'AD';
$StartYear = date('Y');
$StartMonth = date('M');
$StartDay = date('d');
$StartTime = '00:00:00';
$TimeZone = $DefaultTimeZone; // +Pos = East; 00:00 = UT
$DaySumYN = 'No';
$StopBCAD = 'AD';
$StopYear = date('Y');
$StopMonth = date('M');
$StopDay = date('t');
$StopTime = '23:00:01';
$StepSize = '1 day';
$LocLabel = 'Geneva, NY, USA';
$LonDeg = $DefaultLonDeg;
$LatDeg = $DefaultLatDeg;
$AltMet = $DefaultAltMet;
$AUorKMorMI = 'Mi';
$DefaultLocLabel = 'Geneva, NY, USA';
// -------------------------------------------
// Store current interface settings in cookie.
$CookieDataString = "$BodyID|$TimeScale|$StartBCAD|$StartYear|$StartMonth|$StartDay|$StartTime|$TimeZone|$StopBCAD|$StopYear|$StopMonth|$StopDay|$StopTime|$DaySumYN|$StepSize|$LocLabel|$LonDeg|$LatDeg|$AltMet|$AUorKMorMI|$LocLabel";
SetCookie ($CookieName, $CookieDataString, $SetToExpireIn30Days);
} // End of else {...}
} // End of if (!isset(_POST['SubmitButton']))
// ------------------------------------------
// Read values of all interface arguments and
// set any empty arguments to default values.
$w = Filter_Input(INPUT_POST, 'SubmitButton');
if (isset($w))
{
$BodyID = trim(Filter_Input(INPUT_POST, 'BodyID'));
if ($BodyID == '') {$BodyID = '301';}
$TimeScale = StrToUpper(trim(Filter_Input(INPUT_POST, 'TimeScale')));
if ($TimeScale == '') {$TimeScale = 'UT';}
$TimeScale = (substr($TimeScale, 0,1) == 'T')? 'TT' : 'UT';
// ----------------------------------------------------
// Get longitude input as decimal degrees or DMS string
// which will be converted into decimal degrees.
$LonDeg = trim(Filter_Input(INPUT_POST, 'LonDeg'));
if ($LonDeg == '') {$LonDeg = $DefaultLonDeg;}
$LonDeg = DMS_to_Deg($LonDeg, 9);
// ---------------------------------------------------
// Get latitude input as decimal degrees or DMS string
// which will be converted into decimal degrees.
$LatDeg = trim(Filter_Input(INPUT_POST, 'LatDeg'));
if ($LatDeg == '') {$LatDeg = $DefaultLatDeg;}
$LatDeg = DMS_to_Deg($LatDeg, 9);
$AltMet = trim(Filter_Input(INPUT_POST, 'AltMet'));
if ($AltMet == '') {$AltMet = $DefaultAltMet;}
$AltMet = SPrintF("%+d", $AltMet);
$StartBCAD = trim(Filter_Input(INPUT_POST, 'StartBCAD'));
if ($StartBCAD == '') {$StartBCAD = 'AD';}
$StartYear = trim(Filter_Input(INPUT_POST, 'StartYear'));
if ($StartYear == '') {$StartYear = date('Y');}
$StartYear = SPrintF("%04d", $StartYear);
/* -------------------------------------------
Get START month as a number (1 to 12) or as
a 3-letter abbreviation ('Jan' to 'Dec').
NOT case-sensitive.
*/
$StartMonth = UCFirst(substr(StrToLower(trim(Filter_Input(INPUT_POST, 'StartMonth'))),0,3));
if ($StartMonth == '') {$StartMonth = date('M');}
if (Is_Numeric($StartMonth) and $StartMonth == 0) {$StartMonth = date('M');}
for ($ii=0; $ii < 1; $ii++)
{
if (Is_Numeric($StartMonth))
{
$m = IntVal($StartMonth);
if ($m < 1 or $m > 12) {$StartMonth = date('M'); break;}
$StartMonth = substr(MONTHS, 3*($m-1), 3);
}
$jj = StrPos(MONTHS, $StartMonth);
if ($jj === FALSE) {$StartMonth = date('M'); break;}
$StartMonth = substr(MONTHS, $jj, 3);
}
$StartDay = trim(Filter_Input(INPUT_POST, 'StartDay'));
if ($StartDay == '') {$StartDay = IntVal(date('d'));}
$StartDay = SPrintF("%02d", $StartDay);
$StartTime = trim(Filter_Input(INPUT_POST, 'StartTime'));
if ($StartTime == '') {$StartTime = date('H:i:s');}
$StartTime = (!Is_Numeric(substr($StartTime,0,1)))? '00:00:00': $StartTime;
$w = HMS_to_Hours($StartTime);
$StartTime = Hours_to_HMS($w,0);
$TimeZone = trim(Filter_Input(INPUT_POST, 'TimeZone'));
if ($TimeZone == '') {$TimeZone = $DefaultTimeZone;}
$TZHours = @HMS_to_Hours($TimeZone); // Try to suppress a harmless warning.
$TimeZone = Hours_to_HMS($TZHours);
$TZSign = ($TZHours >= 0)? '+':'';
$TimeZone = substr($TZSign.$TimeZone,0,6);
$DaySumYN = trim(Filter_Input(INPUT_POST, 'DaySumYN'));
$DaySumYN = (substr(StrToUpper($DaySumYN),0,1) == 'Y')? 'Yes':'No';
$StopBCAD = trim(Filter_Input(INPUT_POST, 'StopBCAD'));
if ($StopBCAD == '') {$StopBCAD = 'AD';}
$StopYear = trim(Filter_Input(INPUT_POST, 'StopYear'));
if ($StopYear == '') {$StopYear = date('Y');}
$StopYear = SPrintF("%04d", $StopYear);
/* ------------------------------------------
Get STOP month as a number (1 to 12) or as
a 3-letter abbreviation ('Jan' to 'Dec').
*/
$StopMonth = UCFirst(substr(StrToLower(trim(Filter_Input(INPUT_POST, 'StopMonth'))),0,3));
if ($StopMonth == '') {$StopMonth = date('M');}
if (Is_Numeric($StopMonth) and $StopMonth == 0) {$StopMonth = date('M');}
for ($ii=0; $ii < 1; $ii++)
{
if (Is_Numeric($StopMonth))
{
$m = IntVal($StopMonth);
if ($m < 1 or $m > 12) {$StopMonth = date('M'); break;}
$StopMonth = substr(MONTHS, 3*($m-1), 3);
}
$jj = StrPos(MONTHS, $StopMonth);
if ($jj === FALSE) {$StopMonth = date('M'); break;}
$StopMonth = substr(MONTHS, $jj, 3);
}
$StopDay = trim(Filter_Input(INPUT_POST, 'StopDay'));
if ($StopDay == '') {$StopDay = IntVal(date('d'));}
$StopDay = SPrintF("%02d", $StopDay);
$StopTime = trim(Filter_Input(INPUT_POST, 'StopTime'));
if ($StopTime == '') {$StopTime = date('H:i:s');}
$StopTime = (!Is_Numeric(substr($StopTime,0,1)))? '00:00:00': $StopTime;
$w = HMS_to_Hours($StopTime);
$StopTime = Hours_to_HMS(HMS_to_Hours($w), 0);
$StepSize = trim(Filter_Input(INPUT_POST, 'StepSize'));
if ($StepSize == '') {$StepSize = '1 day';}
$StepSize .= (Is_Numeric($StepSize))? ' day' : '';
$LocLabel = trim(Filter_Input(INPUT_POST, 'LocLabel'));
if ($LocLabel == '') {$LocLabel = '---';}
// ---------------------------------------------------
// Get latitude input as decimal degrees or DMS string
// which will be converted into decimal degrees.
$LatDeg = trim(Filter_Input(INPUT_POST, 'LatDeg'));
if ($LatDeg == '') {$LatDeg = $DefaultLatDeg;}
$LatDeg = DMS_to_Deg($LatDeg, 9);
// Parse altitude in meters.
$AltMet = trim(Filter_Input(INPUT_POST, 'AltMet'));
if ($AltMet == '') {$AltMet = '+0';}
$AltMet = SPrintF("%+d", $AltMet);
// Parse distance units symbol.
$AUorKMorMI = StrToUpper(trim(Filter_Input(INPUT_POST, 'AUorKMorMI')));
$AUorKMorMI = substr($AUorKMorMI,0,1);
if ($AUorKMorMI == 'A') {$AUorKMorMI = 'AU';}
if ($AUorKMorMI == 'K') {$AUorKMorMI = 'Km';}
if ($AUorKMorMI == 'M') {$AUorKMorMI = 'Mi';}
if ($AUorKMorMI <> 'AU' and $AUorKMorMI <> 'Km' and $AUorKMorMI <> 'Mi')
{$AUorKMorMI = 'Mi';}
// -------------------------------------
// Store interface argument in a cookie.
$CookieDataString = "$BodyID|$TimeScale|$StartBCAD|$StartYear|$StartMonth|$StartDay|$StartTime|$TimeZone|$StopBCAD|$StopYear|$StopMonth|$StopDay|$StopTime|$DaySumYN|$StepSize|$LocLabel|$LonDeg|$LatDeg|$AltMet|$AUorKMorMI|$LocLabel";
SetCookie ($CookieName, $CookieDataString, $SetToExpireIn30Days);
}
/* -----------------------------------------------------------
Put code here to optionally check individual arguments for
validity in reverse input order. If errors found, then set
error flag and message values accordingly.
NOTE: Horizons will catch some errors, such as invalid date
errors.
*/
$ErrorReported = FALSE;
$ErrMssg = '';
// -----------------------------
// Set initial uniform width for
// tables alignment in pixels.
$TableWidth = '780';
// -------------------------------------------
// If error was reported (TRUE), then display
// the error message on a red background.
if ($ErrorReported)
{
$TxColor = 'white';
$BgColor = '#CC0000';
$TextArea2Text = '';
$TextArea1Text =
"=== ERROR ===
$ErrMssg";
}
else
{
// *********************************************************
// BEGIN MAIN COMPUTATIONS HERE IF NO ERRORS DETECTED ABOVE.
// *********************************************************
// ------------------------------------------------------
// CONSTRUCT FULL DATE AND TIME STRINGS FOR HORIZONS API.
// Determine number of days in Gregorian calendar month.
$Mmm = substr(UCFirst(StrToLower(trim($StartMonth))),0,3);
$i = StrPos('JanFebMarAprMayJunJulAugSepOctNovDec', $Mmm);
if ($i === FALSE) {$m = 1;} else {$m = 1 + $i/3;}
$mDays = Cal_Days_In_Month(CAL_GREGORIAN, $m, $StartYear);
// Construct start/stop dates for monthly table.
$StartDate = "$StartYear-$StartMonth-01";
$StopDate = "$StartYear-$StartMonth-$mDays";
// Auto switch to 'Null Island' if Lon = Lat = 0.0
// This also changes the Time Zone and Altitude to
// +00:00 and +0.0, respectively.
if ($LonDeg == 0 and $LatDeg == 0 and $TimeZone == '+00:00')
{$LocLabel = 'Null Island'; $TimeZone = '+00:00'; $AltMet = '+0.0';}
// Call main R/T/S driver function.
$RTSTable = RTS_Times_Table ($BodyID,$StartDate,$StopDate,$TimeZone,
$DaySumYN,$LonDeg,$LatDeg,$AltMet,
$AUorKMorMI,$LocLabel);
// *******************************************
// DROP THROUGH HERE AFTER COMPUTATIONS ABOVE
// TO DISPLAY THE RESULTS OF THE OPERATIONS.
// *******************************************
$TextArea1Text = "$RTSTable";
}
// ****************************
// Define TextArea2 text block.
$TextArea2Text =
"
...
";
/* --------------------------------------------------------------------------
Determine number of text columns and rows to use in the output text areas.
These values vary randomly according to the text block width and length.
The idea is to eliminate the need for scroll-bars within the text areas
or worry as much about the variable dimensions of a text display area.
*/
// ------------
// Text Area 1.
$Text1Cols = 1 + Max(Array_Map('StrLen', PReg_Split("[\n]", trim($TextArea1Text))));
if ($Text1Cols < 80) {$Text1Cols = 80;} // Default
$Text1Rows = 2 + Substr_Count($TextArea1Text, "\n");
// ------------
// Text Area 2.
$Text2Cols = 1 + Max(Array_Map('StrLen', PReg_Split("[\n]", trim($TextArea2Text))));
if ($Text2Cols < 80) {$Text2Cols = 80;} // Default
$Text2Rows = 2 + Substr_Count($TextArea2Text, "\n");
// ******************************************
// GENERATE CLIENT WEB PAGE TO DISPLAY OUTPUT
print <<< _HTML
<!DOCTYPE HTML>
<HTML>
<head>
<title>$_BROWSER_TAB_TEXT_</title>
<meta name='viewport' content='width=device-width, initial-scale=0.8'>
<meta http-equiv='content-type' content='text/html; chrset=UTF-8'>
<meta http-equiv='pragma' content='no-cache'>
<meta http-equiv='expires' content='-1'>
<meta name='description' content='Local Rising/Transit/Setting Times Table'>
<meta name='keywords' content='NeoProgrammics/PHP Science Labs'>
<meta name='author' content='Jay Tanner - https://www.NeoProgrammics.com'>
<meta name='robots' content='index,follow'>
<meta name='googlebot' content='index,follow'>
<style>
BODY {color:white; background:black; font-family:Verdana; font-size:12pt; line-height:125%;}
TABLE
{font-size:13pt; border: 1px solid black;}
TD
{
color:black; background:white; line-height:150%; font-size:10pt;
padding:6px; text-align:center;
}
UL
{font-family:Verdana; font-size:12pt; line-height:150%; text-align:justify;}
PRE
{
background:white; color:black; font-family:monospace; font-size:12.5pt;
font-weight:bold; text-align:left; line-height:125%; padding:6px;
border:2px solid black; border-radius:8px;
page-break-before:page;
}
DIV
{
background:white; color:black; font-family:Verdana; font-size:11pt;
font-weight:normal; line-height:125%; padding:6px;
}
TEXTAREA
{
background:white; color:black; font-family:monospace; font-size:12pt;
font-weight:bold; padding:4pt; white-space:pre; border-radius:8px;
line-height:125%;
}
INPUT[type='text']::-ms-clear {width:0; height:0;}
INPUT[type='text']
{
font-family:monospace; color:black; background:white; font-size:12pt;
font-weight:bold; text-align:center; box-shadow:2px 2px 3px #666666;
border:2px solid black; border-radius:4px;
}
INPUT[type='text']:focus
{
font-family:monospace; background:white; box-shadow:2px 2px 3px #666666;
font-size:12pt; border:2px solid blue; text-align:center; font-weight:bold;
border-radius:4px;
}
INPUT[type='submit']
{
background:black; color:cyan; font-family:Verdana; font-size:10pt;
font-weight:bold; border-radius:4px; border:4px solid #777777;
padding:3pt;
}
INPUT[type='submit']:hover
{
background:black; color:white; font-family:Verdana; font-size:10pt;
font-weight:bold; border-radius:4px; border:4px solid red;
padding:3pt;
}
// For HyperLinks to work correctly, link states
// MUST be defined in the following CSS order:
// :link, :visited, :hover, :active
A:link
{
font-size:10pt; background:transparent; color:#8080FF; border-radius:4px;
font-family:Verdana; font-weight:bold; text-decoration:none;
line-height:175%; padding:3px; border:1px solid transparent;
}
A:visited
{
font-size:10pt; background:transparent; color:DarkCyan; border-radius:4px;
}
A:hover
{
font-size:10pt; background:yellow; color:black; border:1px solid black;
box-shadow:1px 1px 3px #222222; border-radius:4px;
}
A:active
{
font-size:10pt; background:yellow; color:black; border-radius:4px;
}
HR {background:red; height:4px; border:0px;}
[title-text]:hover:after
{
opacity:1.0;
transition:all 1.0s ease 1.0s;
text-align:left;
visibility:visible;
}
[title-text]:after
{
opacity:1.0;
content:attr(title-text);
text-align:left;
left:50%;
background-color:yellow;
color:black;
font-size:10pt;
position:absolute;
padding:1px 5px 2px 5px;
white-space:pre;
border:1px solid red;
z-index:1;
visibility:hidden;
}
[title-text] {position: relative;}
::selection{background-color:yellow !important; color:black !important;}
::-moz-selection{background-color:yellow !important; color:black !important;}
</style>
</head>
<body>
<!-- Define container form --->
<form name="form1" method="post" action="">
<!-- Define main page title/header. --->
<table width="$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr><td colspan="99" style="color:white; background-color:#000066; border:2px solid white; border-radius:8px 8px 0px 0px;">$_INTERFACE_TITLE_</td></tr>
</table>
<!-- Define input (BodyID) text box --->
<table width="$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<!---
<tr>
<td style='line-height:175%; background:LightCyan;' width='25%'
title=' MAJOR BODY IDs
10 = Sun
199 = Mercury
299 = Venus
301 = Moon (Luna)
399 = Earth
499 = Mars
599 = Jupiter
699 = Saturn
799 = Uranus
899 = Neptune
999 = Pluto
ASTEROID IDs
1; = Ceres
2; = Pallas
3; = Juno
4; = Vesta
5; = Astraea
6; = Hebe
7; = Iris
8; = Flora
9; = Metis
10; = Hygiea'>
NASA/JPL Database Body ID# or Designation<br>
<input name="BodyID" type="text" value="$BodyID" size="33" maxlength="32"></td>
</tr>
--->
<tr>
<td style='line-height:175%; background:#CCFFCC;' width='25%'
title=''>Optional Observer Location Label<br>
<input name="LocLabel" type="text" value="$LocLabel" size="33" maxlength="32"></td>
</tr>
</table>
<!-- LONGITUDE/LATITUDE/ALTITUDE SETTINGS TABLE --->
<table width="$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr title=" IMPORTANT:\n Make sure that the given Geographic Coordinates are within the \n given Time Zone or the computed times may not be accurate. \n\n">
<!-- GPS Longitude in Degrees or DMS --->
<td width='33%' style='background:#CCFFCC; line-height:180%;'>± GPS Longitude °<br>
<input name="LonDeg" type="text" value="$LonDeg" size="15" maxlength="14" title=' GPS Longitude in Decimal Degrees\nor as\n Deg Min Sec Separated by Spaces \n'> +Pos = E</td>
<!-- GPS Latitude in Degrees or DMS --->
<td width='33%' style='background:#CCFFCC; line-height:180%;'>± GPS Latitude °<br>
<input name="LatDeg" type="text" value="$LatDeg" size="15" maxlength="14" title=' GPS Latitude in Decimal Degrees\nor as\n Deg Min Sec Separated by Spaces. \n'> +Pos = N</td>
<!-- Sea level altitude --->
<td style='background:#CCFFCC; line-height:180%;'>± Sea Level Altitude<br>
<input name="AltMet" type="text" value="$AltMet" size="8" maxlength="7" title=' Altitude in meters relative to sea level. '> meters
</td>
</tr>
</table>
<!-- Define input (TimeScale) text box --->
<table width="$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr>
<td style='line-height:175%; background:LightYellow;' width='25%' title=' Local Time Zone Offset From UT. \n −Negative = W +Positive = E \n\n IMPORTANT:\n Make sure that the given Geographic Coordinates are within the \n given Time Zone or the computed times may not be accurate. \n\n'>Time Zone<br><input name="TimeZone" type="text" value="$TimeZone" size="7" maxlength="6"></td>
<td><b>Year <span style='font-weight:normal;'> and </span> Month<br>
<input name="StartBCAD" type="hidden" value="$StartBCAD" size="3" maxlength="2">
<input name="StartYear" type="text" value="$StartYear" size="6" maxlength="5">
<input name="StartMonth" type="text" value="$StartMonth" size="4" maxlength="3">
<input name="StartDay" type="hidden" value="$StartDay" size="3" maxlength="2">
<input name="StartTime" type="hidden" value="$StartTime" size="9" maxlength="8"></td>
<td style='line-height:175%; background:LightYellow;' width='25%' title=' N = No = Standard Time Mode (Default) \n Y = Yes = Daylight / Summer Time Mode '>Daylight / Summer Time<br>
<input name="DaySumYN" type="text" value="$DaySumYN" size="4" maxlength="3"></td>
</tr>
<tr>
<td style='line-height:175%; background:LightYellow;'> <input name="StepSize" type="hidden" value="$StepSize" size="17" maxlength="16"></td>
<td title=' Output Distance Units: \n\n AU = Astronomical Unts\n Km = Kilometers\n Mi = Statute Miles '>
Distance Units Symbol<br>
<input name="AUorKMorMI" type="text" value="$AUorKMorMI" size="3" maxlength="2">
<input name="StopBCAD" type="hidden" value="$StopBCAD" size="3" maxlength="2">
<input name="StopYear" type="hidden" value="$StopYear" size="6" maxlength="5">
<input name="StopMonth" type="hidden" value="$StopMonth" size="4" maxlength="3">
<input name="StopDay" type="hidden" value="$StopDay" size="3" maxlength="2">
<input name="StopTime" type="hidden" value="$StopTime" size="9" maxlength="8"><br>
</td>
<td style='line-height:175%; background:LightYellow;' width='25%'> <br>
<input name="TimeScale" type="hidden" value="$TimeScale" size="3" maxlength="2"></td>
</tr>
</table>
<!-- Top yellow source code view link. --->
<br>
<table width="$TableWidth" align="center" cellspacing="1" cellpadding="3">
<tr>
<td colspan="1" style='font-size:10pt; color:black; background:black;
text-align:center;' title=' Tries to Open in a New Tab. '>
<b><a href="View-Source-Code.php" target="_blank"
style='font-family:Verdana; color:black; background:yellow;
text-decoration:none; border:1px solid black; padding:4px;
border-radius:4px; font-weight:normal;'>
View/Copy Source Code </a></b>
</td>
</tr>
</table>
<!-- Define [SUBMIT] button --->
<table width="$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr><td colspan="99" style="background-color:black;"><input type="submit" name="SubmitButton" value=" S U B M I T " OnClick="$_COMPUTING_"
></td></tr>
</table>
<!-- Define TextArea1 --->
<table width="$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="99" style="text-align:center; color:GreenYellow; background-color:black;">Double-Click Within Text Area to Select ALL Text<br>
<textarea ID="TextArea1" name="TextArea1" style="color:$TxColor; background:$BgColor; padding:6px; border:2px solid white;" cols="$Text1Cols" rows="$Text1Rows" ReadOnly OnDblClick="this.select();" OnMouseUp="return true;">
$TextArea1Text
</textarea>
</td>
</tr>
</table>
<!-- Define TextArea2 --->
<table width="$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="99" style="text-align:center; color:GreenYellow; background:black;">Double-Click Within Text Area to Select ALL Text<br>
<textarea ID="TextArea2" name="TextArea2" style="color:black; background:white; padding:6px;" cols="$Text2Cols" rows="$Text2Rows" ReadOnly OnDblClick="this.select();" OnMouseUp="return true;">
$TextArea2Text
</textarea>
</tr>
</table>
<!-- Define page footer --->
<table width="$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="99" style="color:GreenYellow; background:black;">PHP Program by $_AUTHOR_<br><span style="color:silver; background:black;">$_REVISION_DATE_</span></td>
</tr>
</table>
</form>
<!-- End of container form --->
<!-- Extra bottom scroll space --->
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</HTML>
_HTML;
// ####################################################
// INPUT INTERFACE UTILITY FUNCTIONS
// ####################################################
/*
###########################################################################
This function returns the decimal hours equivalent to the given HMS string.
Generic. No special error checking is done.
NO DEPENDENCIES
###########################################################################
*/
function HMS_to_Hours ($HMSString, $Decimals=16)
{
$HHmmss = trim($HMSString);
$decimals = trim($Decimals);
/* ------------------------------------------------
Account for and preserve any numerical +/- sign.
Internal work will use absolute values and any
numerical sign will be reattached the output.
*/
$NumSign = substr($HHmmss,0,1);
if ($NumSign == '-')
{$HHmmss = substr($HHmmss,1,StrLen($HHmmss));}
else
{
if ($NumSign == '+')
{$HHmmss = substr($HHmmss,1,StrLen($HHmmss));}
$NumSign = '+';
}
// ------------------------------------------------------------------
// Replace any colons : with blank spaces and remove any white space.
$HHmmss = PReg_Replace("/\s+/", " ", Str_Replace(":", " ", $HHmmss));
// ----------------------------------------
// Count the HMS time elements from 1 to 3.
$n = 1 + Substr_Count($HHmmss, ' ');
$hh = $mm = $ss = 0;
/* ----------------------------------------------------------------------
Collect all given time element values. They can be integer or decimal
values. Only counts up to three HMS values and any values beyond those
are simply ignored.
*/
for ($i=0; $i < 1; $i++)
{
if ($n == 1){list($hh) = PReg_Split("[ ]", $HHmmss);}
if ($n == 2){list($hh,$mm) = PReg_Split("[ ]", $HHmmss);}
if ($n == 3){list($hh,$mm,$ss) = PReg_Split("[ ]", $HHmmss);}
}
// ------------------------------------------------------------------------
// Compute HMS equivalent in decimal hours to the given number of decimals.
return $NumSign.(round((3600*$hh + 60*$mm + $ss)/3600,$decimals));
} // End of HMS_to_Hours(...)
/*
###########################################################################
This function returns an HMS string equivalent to an hours argument rounded
to the specified number of decimals.
Generic. No special error checking is done.
NO DEPENDENCIES
###########################################################################
*/
function Hours_to_HMS ($Hours, $Decimals=0)
{
$hours = trim($Hours); $NumSign = ($hours < 0)? '-':'';
$hours = Str_Replace('+', '', Str_Replace('-', '', $hours));
// ---------------------
// Set working decimals.
$Q = 32;
$decimals = floor(abs(trim($Decimals)));
$decimals = ($decimals > $Q)? $Q : $decimals;
$decimals = ($decimals < 0)? 0 : $decimals;
// ------------------------------------
// Compute hours,minutes and seconds to
// the specified number of decimals.
$hh = bcAdd($hours, '0');
$min = bcMul('60', bcSub($hours, $hh, $Q),$Q);
$mm = bcAdd($min, '0');
$sec = bcMul('60', bcSub($min, $mm, $Q),$Q);
$ss = SPrintF("%1.$decimals"."f", $sec);
if ($ss < 10){$ss = "0$ss";}
// -------------------------------------------
// Try to account for that blasted 60s glitch.
if ($ss == 60) {$mm += 1; $ss = 0;}
if ($mm == 60) {$hh += 1; $mm = 0;}
// ------------------------------------------
// Construct and return time elements string.
$hh = SPrintF("%02d", $hh);
$mm = SPrintF("%02d", $mm);
$ss = SPrintf("%1.$decimals"."f", $ss);
if ($ss < 10){$ss = "0$ss";}
return "$NumSign$hh:$mm:$ss";
} // End of Hours_to_HMS (...)
/*
###########################################################################
This function returns decimal degrees equivalent to a DMS string argument
to the specified number of decimals.
The Degrees, Minutes and Seconds string values are separated by spaces.
Generic. No special error checking is done.
NO DEPENDENCIES
###########################################################################
*/
function DMS_to_Deg ($DMSString, $Decimals=14)
{
$DDmmss = trim($DMSString);
$decimals = trim($Decimals);
// -----------------------------------
// Account for any numerical +/- sign.
$NumSign = substr($DDmmss,0,1);
if ($NumSign == '-')
{$DDmmss = substr($DDmmss,1,StrLen($DDmmss));}
else
{
if ($NumSign == '+')
{$DDmmss = substr($DDmmss,1,StrLen($DDmmss));}
$NumSign = '+';
}
// -----------------------
// Remove all white space.
$DDmmss = PReg_Replace("/\s+/", " ", $DDmmss);
// ----------------------------------------
// Count the DMS time elements from 1 to 3.
$n = 1 + Substr_Count($DDmmss, ' ');
$dd = $mm = $ss = 0;
// --------------------------------------
// Collect all given time element values.
// They can be integer or decimal values.
for ($i=0; $i < 1; $i++)
{
if ($n == 1){list($dd) = PReg_Split("[ ]", $DDmmss);}
if ($n == 2){list($dd,$mm) = PReg_Split("[ ]", $DDmmss);}
if ($n == 3){list($dd,$mm,$ss) = PReg_Split("[ ]", $DDmmss);}
}
// ----------------------------------
// Compute DMS equivalent in degrees.
return $NumSign.(round((3600*$dd + 60*$mm + $ss)/3600,$decimals));
} // End of DMS_to_Deg(...)
/*
###########################################################################
This function returns a topocentric ephemeris of rise/transit/set times
from the NASA/JPL Horizons API. A topocentric ephemeris takes the location
and altitude of the observer into account. Standard Earth refraction model
is also applied.
DaySumYN = Means Daylght Saving/Summer Time 'Yes|No'
'No' = Use Standard Time (Default).
'Yes' = Use Daylight Saving/Summer Time.
Angles are expressed in degrees.
NO DEPENDENCIES
###########################################################################
*/
function RTS_Times_Table ($BodyID,$StartDate,$StopDate,
$TimeZone,$DaySumYN,$LonDeg,$LatDeg,
$AltMet,$AUorKMorMI,$LocLabel)
{
// Define compass directional symbols corresponding to the azimuth.
$ZModeN0 = 'N NNENE ENEE ESESE SSES SSWSW WSWW WNWNW NNWN';
// ===========================================================================
// Construct query URL for the NASA/JPL Horizons API.
$BodyID = trim($BodyID);
$Command = URLEncode($BodyID);
$AltKm = trim($AltMet) / 1000;
// Output distance units (Default = 'AU').
$AUorKMorMI = substr(StrToUpper(trim($AUorKMorMI)),0,2);
if ($AUorKMorMI <> 'AU' and $AUorKMorMI <> 'KM' and $AUorKMorMI <> 'MI')
{$AUorKMorMI = 'AU';}
/* -----------------------------------------------------------
Adjust for Daylight/Summer Time, if indicated. This assumes
that the Time Zone string is given in the standard +-HH:mm
format or an error may occur. EXAMPLES: '+05:30', '-05:00'
*/
$DaySumYN = substr(StrToUpper(trim($DaySumYN)),0,1);
$DaySumAdj = ($DaySumYN == 'N')? 0:1;
$xTimeZone = $TimeZone;
list($TZHH, $TZmm) = PReg_Split("[\:]", $TimeZone);
$TZSign = substr($TZHH,0,1);
$TZHours = (($TZSign == '-')? -1:1)*(abs($TZHH) + $TZmm/60) + $DaySumAdj;
$i = StrPos($TZHours, '.'); if ($i == FALSE) {$TZHours .= '.00';}
$i = StrPos($TZHours, '.');
$TZHH = $TZSign.SPrintF("%02d", abs(substr($TZHours,0,$i)));
$TimeZone = "$TZHH:$TZmm";
// -------------------------------------
// Construct URL for Horizons API query.
$From_Horizons_API =
"https://ssd.jpl.nasa.gov/api/horizons.api?format=text" .
"&COMMAND='$Command'" .
"&OBJ_DATA='YES'" .
"&MAKE_EPHEM='YES'" .
"&EPHEM_TYPE='OBSERVER'" .
"&CAL_FORMAT='CAL'" .
"&REF_SYSTEM='ICRF'" .
"&APPARENT='REFRACTED'" .
"&RANGE_UNITS='AU'" .
"&SUPPRESS_RANGE_RATE='YES'" .
"&CENTER='COORD@399'" .
"&COORD_TYPE='GEODETIC'" .
"&SITE_COORD='$LonDeg,$LatDeg,$AltKm'" .
"&TIME_DIGITS='MINUTES'" .
"&TIME_ZONE='$TimeZone'" .
"&START_TIME='$StartDate 00:00:00.000'" .
"&STOP_TIME='$StopDate 23:59:59.999'" .
"&STEP_SIZE='1 MINUTE'" .
"&EXTRA_PREC='YES'" .
"&R_T_S_ONLY='TVH'" .
"&QUANTITIES='4,9,20'" .
"&CSV_FORMAT='YES'" ;
// ==========================================
/* -----------------------------------------------------------------------
Send query to Horizons API to obtain the apparent topocentric ephemeris
data we need for the RTS times of the given target body.
*/
$RawRTS = Str_Replace(",\n", " \n", File_Get_Contents($From_Horizons_API));
/* ----------------------------------------------------------
If no ephemeris data is found, then return raw text as-is.
*/
if (StrPos($RawRTS, '$$SOE') === FALSE) {return $RawRTS;}
// ------------------------------------------------------
// Get target body designation and source info substring.
$i = StrPos($RawRTS, 'Target body name:');
$j = StrPos($RawRTS, '{');
$BodyDesignation = trim(substr($RawRTS, $i+17, $j-$i-17));
$BodyDesignation = PReg_Replace("/\s+/", " ", trim($BodyDesignation));
/* -----------------------------------------------------
Set pointers to start and end of CSV ephemeris table.
A value of FALSE means no ephemeris was found within
the given source text.
*/
$i = StrPos($RawRTS, '$$SOE');
$j = StrPos($RawRTS, '$$EOE');
/* ------------------------------------------------
Extract ONLY the existing ephemeris data line(s)
from between the pointers.
*/
$RTS = trim(substr($RawRTS, $i+5, $j-$i-5));
// ====================================
// NOW WE PARSE THE RETURNED RTS TABLE.
// Store table in working array.
$wArray = PReg_Split("[\n]", trim($RTS));
$wCount = count($wArray);
$output = '';
$PrevDateTime = '';
// Extract data into the corresponding variables.
for($i=0; $i < $wCount; $i++)
{
$CurrLine = trim($wArray[$i]);
list
(
$DateTime,
$w,
$RorTorS,
$AzimDeg,
$ElevDeg,
$VMag,
$SBrt,
$DistAU
) = PReg_Split("[,]", $CurrLine);
// --------------------------
// Do some output formatting.
$DateTime = Str_Replace(' ', ' ', $DateTime);
$AzimDeg = SPrintF("% 6.2f", trim($AzimDeg));
$ElevDeg = SPrintF("% 5.2f", trim($ElevDeg));
if (Is_Numeric(trim($VMag)))
{$VMag = SPrintF("% +7.3f", trim($VMag));}
else
{$VMag = ' - ';}
$DistAU = $Dist = trim($DistAU);
// Compute distance in AUs, Km and Mi.
$DistKm = $DistAU * 149597870.7;
$DistMi = $DistKm / 1.609344;
$DistAU = SPrintF("% 16.12f", $DistAU);
$DistKm = SPrintF("% 12.5f", $DistKm);
$DistMi = SPrintF("% 12.5f", $DistMi);
// Determine which distance units and symbols to apply.
if ($AUorKMorMI == 'AU') {$Dist = $DistAU; $DistUnits = 'AU';}
if ($AUorKMorMI == 'KM') {$Dist = Number_Format($DistKm,0); $DistUnits = 'Km';}
if ($AUorKMorMI == 'MI') {$Dist = Number_Format($DistMi,0); $DistUnits = 'Mi';}
// Adjust distance symbols and decimals display for the moon.
if ($BodyID == '301' and $AUorKMorMI == 'KM')
{$Dist = SPrintF("% 10.3f", $DistKm); $Dist = Number_Format($Dist,3);}
if ($BodyID == '301' and $AUorKMorMI == 'MI')
{$Dist = SPrintF("% 10.3f", $DistMi); $Dist = ' '.Number_Format($Dist,3);}
// Apply special symbols formatting.
if ($RorTorS == 'r'){$ElevDeg = ' - ';}
if ($RorTorS == 't'){$AzimDeg = ' | ';}
if ($RorTorS == 's'){$ElevDeg = ' - ';}
// Determine compass direction symbol.
// corresponding to the azimuth value.
$az = FloatVal(trim($AzimDeg));
$az -= 360*floor($az/360);
$k = ($az < 11.25 or $az > 348.75)? 0:floor(0.5 + $az/22.5);
$CmpssDir = trim(substr($ZModeN0, 3*$k, 3));// . ' ';
if (StrLen($CmpssDir) == 1) {$CmpssDir = " $CmpssDir ";}
if (StrLen($CmpssDir) == 2) {$CmpssDir = " $CmpssDir";}
$Dist = substr("$Dist ", 0, 14);
// Insert blank line between calendar dates.
$CRLF = (substr($PrevDateTime,0,11) == substr($DateTime,0,11))? '' : "\n";
$PrevDateTime = $DateTime;
$output .= "$CRLF$DateTime $RorTorS, $AzimDeg $CmpssDir $ElevDeg $VMag $Dist\n";
}
$output = trim($output);
// Parse RTS symbols.
$output = Str_Replace(' r,', ' Rise ', $output);
$output = Str_Replace(' t,', ' Transit', $output);
$output = Str_Replace(' s,', ' Set ', $output);
$output = Str_Replace(' N ', ' | ', $output);
// Define special time mode note:
$TimeMode = ($DaySumYN == 'Y') ? 'Daylight Saving / Summer Time' : 'Standard Time';
// Minor letter-case adjustment for neatness.
$AUorKMorMI = StrToUpper($AUorKMorMI);
if ($AUorKMorMI == 'KM' or $AUorKMorMI == 'MI')
{$AUorKMorMI = UCFirst(StrToLower($AUorKMorMI));}
// Define table header lines.
$HLine1 = Str_Repeat('=', 78);
$HLine2 =
'=========== ===== ======= ======== === ======== ======= ===============';
// DONE.
return
"$HLine1
THE MOON
==============================================================================
RISE / TRANSIT / SETTING TIMES TABLE FOR EACH DATE OF ANY GIVEN YEAR/MONTH
For Body ID# = $BodyID
Body Designation = $BodyDesignation
Observer Location = $LocLabel
Time Zone = $xTimeZone
Time Mode = $TimeMode
GPS Longitude = $LonDeg°
GPS Latitude = $LatDeg°
Sea Level Altitude = $AltMet m
Start Date = $StartDate
Stop Date = $StopDate
Distance Units = $AUorKMorMI
$HLine1
Calend_Date Time Event Azim_Deg Dir Elev_Deg Vis_Mag Distance_$DistUnits
$HLine2
$output
$HLine2
Calend_Date Time Event Azim_Deg Dir Elev_Deg Vis_Mag Distance_$DistUnits
$HLine1
";
/*
##############################################################################
BELOW IS THE ORIGINAL RAW R/T/S TABLE RETURNED FROM THE NASA/JPL HORIZONS API
PRIOR TO BEING PARSED AND REFORMATTED INTO THE CUSTOM TABLE DISPLAYED ABOVE.
$RawRTS
";
*/
} // END OF RTS_Times_Table(...)
// END OF PROGRAM
?>