<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Mars Sundial"
scaling="false"
height="155"
width="300"
author="Simon Porter"
author_email="portersb@gmail.com"
screenshot="http://www.public.asu.edu/~sbporter/MarsSundialPreview.jpg"
thumbnail="http://www.public.asu.edu/~sbporter/MarsSundialThumb.jpg"
description="A Martian sundial/clock displaying the current Mars Coordinated Time (MTC),
Areocentric Solar Longitude (Ls), and local mean solar time, elevation, and sol number
for the Phoenix, Spirit, and Opportunity sites."/>
<Content type="html"><![CDATA[

<style type="text/css">

<!--

INPUT { border:0px; width:100%}
.d1 { color: #c6956c; background: #725035; font-family: arial; font-size: 16; font-weight: bold}
.d2 { color: black;   background: #c6956c; font-family: arial; font-size: 16;}
.i1 { color: #c6956c; background: #725035; font-family: arial; font-size: 10;}

-->
</style>

<script language="JavaScript">
<!--
function pHour(ti) {
        m = 60*(ti-Math.floor(ti));
        s = 60*(m-Math.floor(m));
        if (ti<10) {r = "0"+Math.floor(ti);} else {r = Math.floor(ti);}
        if (m<10) {r += ":0"+Math.floor(m);} else {r += ":"+Math.floor(m);}
        if (s<10) {r += ":0"+Math.floor(s);} else {r += ":"+Math.floor(s);}
        return r;
}

function LMST(MTC,lon) {
	LMS = MTC - (lon/15);
	while (LMS<0) { LMS += 24; }
	return pHour(LMS);
	//return LMS;
}

function sEle(MTC,lon,lat) {
	latr = lat*pi/180;
	lons  = (15*MTC) + EOT + 180;
	dsr  = Math.asin(0.42565*Math.sin(Lsr)) + ((0.25*pi/180)*Math.sin(Lsr));
	Hr = (lon-lons)*(pi/180);
	Zr = Math.acos((Math.sin(dsr)*Math.sin(latr))+(Math.cos(dsr)*Math.cos(latr)*Math.cos(Hr)));
	ele = 90-(Zr*180/pi);
	return Math.round(ele*100)/100;
}

function solLon(time) {
	JDut = 2440587.5+(time/8.64e4);
	//JDut = 2453029.71181-((14.210089295467982/24)*(88775.24409/(24*60*60)));
	//JDut = 2453029.10344573;
	T = (JDut-2451545)/36525;
	diff = 64.183 + 59*T + 51.2*T*T - 67.1*T*T*T - 16.4*T*T*T*T;
	JDtt = JDut + (diff/86400);
	del_t = JDtt - 2451545.0;

	M = 19.3870 + (0.52402075*del_t);
	Mr = M*(pi/180);
	afms = 270.3863+(0.52403840*del_t);
	A = new Array(0.0071, 0.0057,   0.0039,  0.0037, 0.0021, 0.0020,  0.0018);
	t = new Array(2.2353, 2.7543,   1.1177, 15.7866, 2.1354, 2.4694, 32.8493);
	p = new Array(49.409, 168.173, 191.837,  21.763, 15.704, 95.528,  49.095);
	PBS = 0; for (i=0;i<7;i++) {
        PBS += A[i]*Math.cos(((2*pi*del_t)/(365.25*t[i])) + (p[i]*pi/180)); }

vM = ((10.691 + (3.0e-7*del_t))*Math.sin(Mr)) + (0.623*Math.sin(2*Mr))
+ (0.050*Math.sin(3*Mr)) + (0.005*Math.sin(4*Mr)) +
(0.0005*Math.sin(5*Mr)) + PBS;
	Ls = afms+vM;
	while (Ls>360) { Ls -= 360; }
	return Ls*pi/180;
}

function MTime(Lsr) {
	EOT = (2.861*Math.sin(2*Lsr)) - (0.071*Math.sin(4*Lsr)) + (0.002*Math.sin(6*Lsr))-vM;
	MTC = (24 * (((JDtt-2451549.5)/1.027491252)+44796.0-0.00096));
	while (MTC>24) { MTC -= 24; }
	return MTC;
}

function Sol(time, start) {
	JDut = 2440587.5+(time/8.64e4);
	return Math.floor((JDut-start)/(88775.24409/(24*60*60)));
}

function update() {
	now = new Date()
	sys_t = now.valueOf()/1e3;
	Lsr = solLon(sys_t);
	MTC = MTime(Lsr) - (1.5/(24*60));

	document.g.MTC.value = pHour(MTC);
	document.g.Ls.value = (Math.round(Lsr*100*180/pi)/100);
	//for (i=0;i<3;i++) {
	//	this("document.g."+name[i]+"T.value") = LMST(MTC,lonA[i]);
	//}
	document.g.PhoenixT.value = LMST(MTC,lonA[0]);
	document.g.SpiritT.value = LMST(MTC,lonA[1]);
	document.g.OpportunityT.value = LMST(MTC,lonA[2]);

	document.g.PhoenixE.value = sEle(MTC,lonA[0],latA[0]);
	document.g.SpiritE.value = sEle(MTC,lonA[1],latA[1]);
	document.g.OpportunityE.value = sEle(MTC,lonA[2],latA[2]);

	document.g.PhoenixS.value = Sol(sys_t, solA[0]);
	document.g.SpiritS.value = Sol(sys_t, solA[1]);
	document.g.OpportunityS.value = Sol(sys_t, solA[2]);

        window.setTimeout("update()",1000);
}

pi = 3.14159265358979323846;
var name = new Array("Phoenix","Spirit","Opportunity");

var lonA = new Array(126.02,184.52,5.53);

var latA = new Array(68.41,-14.94,-1.97);

var solA = new Array(2454611.78383705,2453008.0369928-1.02749125104167,2453029.10344573-1.02749125104167);



//-->

</script>



<form name="g"><table width="300" border="0" cellpadding="3" cellspacing="0">

<tr class="d1">

<td width="1%" align="right"><b>MTC:</td><td width="25%"><input name=MTC class="d1"></td>

<td width="20%"
align="right"><b>L<sub>s</sub>:</td><td><input
name=Ls class="d1"></td></tr>

<tr
class="d2"><td></td><td>LMST</td><td>&theta;<sub>s</sub>:</td><td>Sol:</td></tr>



<script>

<!--

for(i=0;i<3;i++) {

	document.write("<tr class=d2><td>"+name[i]+":</td>");

	document.write("<td><input name=\""+name[i]+"T\" class=\"d2\"></td>");

	document.write("<td><input name=\""+name[i]+"E\" class=\"d2\"></td>");

	document.write("<td><input name=\""+name[i]+"S\" class=\"d2\"></td>");

	document.write("</tr>");

}



//-->

</script>



<tr class="i1"><td colspan="6">Times are Local Mean
Solar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&theta;<sub>s</sub>:
Local Solar Elevation</td></tr>

</table></form>





<script> update(); </script>



]]></Content>

</Module>

