sun.fsp - Frink Server Pages highlighter
[Try sun.fsp]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML LANG="en">
<HEAD>
<TITLE>Sun Locator</TITLE>
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0">
<META HTTP-EQUIV="Default-Style" CONTENT="Spaceship">
<LINK REL="StyleSheet" HREF="/frinkdocs/spaceship.css"
TYPE="text/css" TITLE="Spaceship">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/apeairy.css"
TYPE="text/css" TITLE="APE Airy">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/style.css" TYPE="text/css"
TITLE="APE Classic">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/style2.css" TYPE="text/css"
TITLE="Compact">
<LINK REL="icon" HREF="/images/futureboyicon.png" TYPE="image/png">
</HEAD>
<BODY <%= (! "$latitude
") ? "onLoad=\"requestLoc();\"" : "" %>
>
<H1>Sun Locator</H1>
<%
use ../
sun.frink
use ../
HTMLUtils.frink
North = +1
South = -1
West = +1
East = -1
if (! "
$latitude
")
{
println["""
<SCRIPT type="text/javascript">
function requestLoc()
{
navigator.geolocation.getCurrentPosition(populateLoc, errorLoc, {maximumAge:600000});
}
function populateLoc(position)
{
latField = document.getElementById("latitude");
latField.value = Math.abs(position.coords.latitude);
longField = document.getElementById("long");
longField.value = Math.abs(position.coords.longitude);
latHemiField = document.getElementById("latHemi");
if (position.coords.latitude < 0) // South?
latHemiField.selectedIndex = 1;
else
latHemiField.selectedIndex = 0;
longHemiField = document.getElementById("longHemi");
if (position.coords.longitude < 0) // West?
longHemiField.selectedIndex = 0;
else
longHemiField.selectedIndex = 1;
form1 = document.getElementById("form1");
form1.submit();
}
function errorLoc(error)
{
//alert(error);
}
</SCRIPT>
"""]
}
when = (when == "spec" ? "spec" : "now")
t = ((when == "spec") ? parseDate["
$date
$timezone
"] : now[])
latitude = "
$latitude
" ? latitude : "39.58560"
long = "
$long
" ? long : "104.89598"
latHemi = "
$latHemi
" ? latHemi : "North"
longHemi = "
$longHemi
" ? longHemi : "West"
longHemis = ["West", "East"]
latHemis = ["North", "South"]
timezone = "
$timezone
" ? timezone : "Mountain"
fmt = ### yyyy-MM-dd HH:mm:ss ###
date = "
$date
" ? date : (now[] -> [fmt, timezone])
nowChecked = (when == "now" ? "CHECKED" : "")
specChecked = (when == "spec" ? "CHECKED" : "")
formatTime[t, now] :=
{
if now > t
return (now - t -> [0, "days", "hours", "min", "sec", 0]) + " ago"
else
return "in " + (t - now -> [0, "days", "hours", "min", "sec", 0])
}
%>
<FORM ACTION="sun.fsp" METHOD="POST" ID="form1" NAME="form1">
<TABLE>
<TR>
<TD>Latitude:
<TD><INPUT TYPE="text" NAME="latitude" ID="latitude" VALUE="$latitude
">
<TD>degrees
<TD>
<SELECT NAME="latHemi" ID="latHemi">
<% makeSelect[latHemis, latHemi] %>
</SELECT>
<TR>
<TD>Longitude:
<TD><INPUT TYPE="text" NAME="long" ID="long" VALUE="$long
">
<TD>degrees
<TD>
<SELECT NAME="longHemi" ID="longHemi">
<% makeSelect[longHemis, longHemi] %>
</SELECT>
<TR>
<TD>Timezone:
<TD COLSPAN="3">
<SELECT NAME="timezone" ID="timezone" onChange="this.form.submit();">
<% makeSelect[sort[timezones[]], timezone] %>
</SELECT>
</TD>
<TR>
<TD>Date:
<TD COLSPAN="4"><INPUT TYPE="RADIO" NAME="when" VALUE="now" ID="now" $nowChecked
onChecked="document.getElementById('date').disabled=true;"><LABEL FOR="now">Now</LABEL>
<BR><INPUT TYPE="RADIO" NAME="when" VALUE="spec" ID="spec" $specChecked
onChecked="document.getElementById('date').disabled=false;"><LABEL FOR="spec">Other date/time:</LABEL><INPUT TYPE="TEXT" NAME="date" ID="date" SIZE=20 VALUE="<%= HTMLEncode[date] %>
" onKeyUp="var item=document.getElementById('spec'); item.checked=true;">
</TABLE>
<INPUT TYPE="SUBMIT" VALUE="Recalculate">
</FORM>
<%
latNum = eval["$latitude
* $latHemi
"] degree
longNum = eval["$long
* $longHemi
"] degree
[azimuth, altitude] = refractedSunAzimuthAltitude[t, latNum, longNum]
[newazimuth, newaltitude] = refractedSunAzimuthAltitude[t + 5 s, latNum, longNum]
dateOnlyFormat = ### yyyy-MM-dd ###
%>
<P>
Time: <%= t->timezone %>
</P>
<P>
From latitude <%= (abs[latNum] -> degrees) + "° " + latitudeName[latNum] %>
,
longitude <%= (abs[longNum] -> degrees) + "° " + longitudeName[longNum] %>
:
</P>
<P>
The sun is located <%= format[abs[altitude], degree, 4] %>
° <%= altitude > 0 deg ? "above" : "below" %>
the horizon (<%= newaltitude > altitude ? "rising" : "setting" %>
)<BR>
True compass bearing:
<%= format[(azimuth + 180 degrees) mod circle, degree,4 ] %>
°
</P>
<P>
On date <%= t -> [dateOnlyFormat, timezone] %>
:
</P>
<TABLE BORDER="0" SUMMARY="Sunrise/Sunset">
<%
out = ### hh:mm:ss a z ###
sunrise = sunrise[t, latNum, longNum]
sunset = sunset[t, latNum, longNum]
sunTransit = sunTransit[t, latNum, longNum]
[transitAz, transitAlt] = refractedSunAzimuthAltitude[sunTransit, latNum, longNum]
println["<TR><TD>Astronomical twilight begins<TD>" + (astronomicalTwilightBegin[t, latNum, longNum] -> [out, timezone])]
println["<TR><TD>Nautical twilight begins<TD>" + (nauticalTwilightBegin[t, latNum, longNum] -> [out, timezone])]
println["<TR><TD>Civil twilight begins<TD>" + (civilTwilightBegin[t, latNum, longNum] -> [out, timezone])]
[azimuth, altitude] = refractedSunAzimuthAltitude[sunrise, latNum, longNum]
println["<TR><TD><B>Sunrise</B><TD>" + ( sunrise -> [out, timezone]) + "<TD>(<I>" + formatTime[sunrise, t] + ")</I>" +
"<TD>at bearing " + format[(azimuth + 180 degrees) mod circle, degree, 4 ] + "°"]
println["<TR><TD> "]
println["<TR><TD><B>Transit</B><TD>" + (sunTransit -> [out, timezone]) + "<TD>(<I>" + formatTime[sunTransit, t] + ")</I>" +
"<TD>at altitude " + format[transitAlt, degree, 4 ] + "°"]
println["<TR><TD> Daylight duration<TD COLSPAN=2>" + (round[sunset-sunrise, s] -> ["hours", "minutes", "seconds"])]
println["<TR><TD> "]
[azimuth, altitude] = refractedSunAzimuthAltitude[sunset, latNum, longNum]
println["<TR><TD><B>Sunset</B><TD>" + ( sunset -> [out, timezone]) + "<TD>(<I>" + formatTime[sunset, t] + ")</I>" +
"<TD>at bearing " + format[(azimuth + 180 degrees) mod circle, degree, 4 ] + "°"]
println["<TR><TD>Civil twilight ends<TD>" + (civilTwilightEnd[t, latNum, longNum] -> [out, timezone])]
println["<TR><TD>Nautical twilight ends<TD>" + (nauticalTwilightEnd[t, latNum, longNum] -> [out, timezone])]
println["<TR><TD>Astronomical twilight ends<TD>" + (astronomicalTwilightEnd[t, latNum, longNum] -> [out, timezone])]
%>
</TABLE>
<HR>
<P>
View source of <A HREF="/fsp/highlight.fsp?f=sun.fsp">This FSP
page</A> or the <A HREF="/fsp/colorize.fsp?f=sun.frink">astronomical library</A>
used by this code. Also see the <A HREF="moon.fsp">moon locator</A>.
</P>
<P>
<I><A HREF="mailto:eliasen@mindspring.com">Alan Eliasen</A></I> was born
<%= round[now[] - #1969-08-19 04:54 PM Mountain#, minute] -> ["days", "hours", "minutes"] %>
ago.
</P>
<P>
Powered by <A HREF="/frinkdocs/">Frink</A> and <A HREF="/frinkdocs/fspdocs.html">Frink Server Pages</A>.
</P>
</BODY>
</HTML>
[Try sun.fsp]
Alan Eliasen was born
20218 days, 1 hours, 19 minutes ago.
Back to Frink Server Pages
documentation.