var sitelon,sitelat,AltitudeLimit,Thedateinquestion, Twilight
var deg_pr_hour=15.04107 ; // for higher accuracy/ iteration
// this accounts for the difference between the solar day and the sidereal day
var deg_pr_hour=15.00 ; // for normal accuracy/ no iteration
var deg_pr_hour_15=15 ; //no iteration
function PrintResults(){
var page
// PrintWindow = window.open("","Print_window","menubar=no,status=yes,toolbar=yes,scrollbars=yes,height=480,width=800");
page='
\n';
page+='\n';
page+=' 20©06 Jens T. Satre\n';
page+=' http://www.satellite-calculations.com\n';
page+='\n';
page+='\n';
page+='\n';
page+=document.Sun.Results.value;
page+='\n';
page+=' Calculated after the method on http://www.stjarnhimlen.se/comp/riset.html\n';
page+='
\n';
document.write(page);
}
function UpdateAltitude(){
//document.Sun.SelectedAltitudeLimit.value=AltitudeLimit;
}
function init()
{
var justnow
justnow= new Date();
Thedateinquestion = new Date();
Thedateinquestion = justnow;
AltitudeLimit=-0.833;
//window.alert('Alt limit='+document.Sun.Alt.value);
//document.Sun.SelectedAltitudeLimit.value=AltitudeLimit;
document.Sun.Day.value=justnow.getDate();
document.Sun.Month.value=justnow.getMonth()+1;
document.Sun.Year.value=justnow.getFullYear();
}
function OnChangeSelectedAltitudeLimit(){
//document.Sun.Alt.value=document.Sun.SelectedAltitudeLimit.value;
Twilight='Manually selected.';
}
function DateManuallyChanged()
{
Thedateinquestion.setDate(document.Sun.Day.value);
Thedateinquestion.setMonth(document.Sun.Month.value-1);
//document.Sun.Month.value=Thedateinquestion.getMonth()+1;
Thedateinquestion.setFullYear(document.Sun.Year.value);
}
function d_to_date_and_time(d)
{
var today,t
var MinMilli = 1000 * 60;
var HrMilli = MinMilli * 60;
var DyMilli = HrMilli * 24;
today = new Date();
// d+10956= Date() format
//window.alert('d= '+d );
d=d+10956;
d*DyMilli;
today.setTime(d*DyMilli);
//t=((today.getTime()/DyMilli)-10956);
//window.alert('t= '+t );
time_offset=today.getTimezoneOffset() ;
Hour= today.getUTCHours() ;
Minute=today.getUTCMinutes() ;
Second=today.getUTCSeconds() ;
Month= today.getUTCMonth()+1;
Day= today.getUTCDate() ;
Year= today.getUTCFullYear();
return(today)
}
function Main(){
var Day,Month,Year,Hour,Minute,Second,today,t,d,d_sun_south,d_sun_south_yesterday
var nautical_twilight_start,nautical_twilight_stop
var civil_twilight_start,civil_twilight_stop
var astronomical_twilight_start,astronomical_twilight_stop
var amateur_astronomical_twilight_start,amateur_astronomical_twilight_stop
var sun_rise,sun_set,Daylength_hour,Daylength_minute,Daylength_hour_yesterday,Daylength_minute_yesterday
var Difference,Difference_hour,Difference_minute,DifferenceSign,Difference_seconds
var result_array = new Array( );
var input_array = new Array( );
var astromical,amateur,civil,nautical
var sun_above_userdefined,sun_below_userdefined
var sun_rise_solstice,sun_set_solstice,d_sun_solstice,d_sun_south_solstice
var Daylength_minute_solstice,Daylength_hour_solstice,Difference_hour_solstice,Difference_minute_solstice,Difference_seconds_solstice
var Difference_solstice,DifferenceSign_solstice
var eq_Month,eq_Day,eq_Year,equivalent_day,d_today,d_selected,sun_above_horison,solstice_above_horison
today = new Date();
equivalent_day = new Date();
t=today.getTime();
document.Sun.Results.value='';
time_offset=today.getTimezoneOffset() ;
Hour= Thedateinquestion.getUTCHours() ;
Minute=Thedateinquestion.getUTCMinutes() ;
Second=Thedateinquestion.getUTCSeconds() ;
Month= Thedateinquestion.getUTCMonth()+1;
Day= Thedateinquestion.getUTCDate() ;
Year= Thedateinquestion.getUTCFullYear();
//window.alert('AltitudeLimit selected= '+AltitudeLimit);
//**** FIND d_sun_south ******
d=daynumber(Day,Month,Year,12,00,00);
d_today=d;
d=d+(time_offset/(60*24)); // Noon local time
//window.alert('time_offset= '+(time_offset/60));
// Iterates for the Sun in south
result_array=SunSouth(d);
d_sun_south=result_array[0];
d=d_sun_south;
result_array=SunSouth(d);
d_sun_south=result_array[0];
d=d_sun_south;
result_array=SunSouth(d);
d_sun_south=result_array[0]; // Sun in south time OK
d_to_date_and_time(d_sun_south);
// Iterates for the Sun in south yesterday
result_array=SunSouth(d-1);
d_sun_south_yesterday=result_array[0];
d=d_sun_south_yesterday;
result_array=SunSouth(d);
d_sun_south_yesterday=result_array[0];
d=d_sun_south_yesterday;
result_array=SunSouth(d);
d_sun_south_yesterday=result_array[0]; // Sun in south yesterday
document.Sun.Results.value = document.Sun.Results.value+'Suns altitude limit :' +AltitudeLimit+'_deg (used for sun rise & set)\n';
document.Sun.Results.value = document.Sun.Results.value+Twilight+'\n';
if (document.Sun.LatDir.value=='North') document.Sun.Results.value = document.Sun.Results.value+'Sun south: ' +d_to_date_and_time(d_sun_south)+' Altitude: '+formatvalue(result_array[1],6)+'_deg Azimuth: 180.0_deg\n';
else document.Sun.Results.value = document.Sun.Results.value+'Sun north: ' +d_to_date_and_time(d_sun_south)+' Altitude: '+formatvalue(result_array[1],6)+'_deg Azimuth: 0.0_deg\n';
document.Sun.Results.value = document.Sun.Results.value+'*********************************************************************************************\n';
//****Astronomical twilight OK works
h=-18 ;// degrees
input_array[0]=d_sun_south;
input_array[1]=h;
result_array= CalculateStartStop(d_sun_south,h);
if (result_array[2]==0){
astronomical=1;
astronomical_twilight_stop=result_array[0];
astronomical_twilight_start=result_array[1];
} else astronomical=0;
//****Amateur Astronomical twilight OK works
h=-15 ;// degrees
input_array[0]=d_sun_south;
input_array[1]=h;
result_array= CalculateStartStop(d_sun_south,h);
if (result_array[2]==0){
amateur=1;
amateur_astronomical_twilight_stop=result_array[0];
amateur_astronomical_twilight_start=result_array[1];
} else amateur=0;
//****Nautical twilight OK works
h=-12 ;// degrees
input_array[0]=d_sun_south;
input_array[1]=h;
result_array= CalculateStartStop(d_sun_south,h);
if (result_array[2]==0){
nautical=1;
nautical_twilight_stop=result_array[0];
nautical_twilight_start=result_array[1];
} else nautical=0;
//****Civil twilight OK works
h=-6 ;// degrees
input_array[0]=d_sun_south;
input_array[1]=h;
result_array= CalculateStartStop(d_sun_south,h);
if (result_array[2]==0){
civil=1;
civil_twilight_stop=result_array[0];
civil_twilight_start=result_array[1];
} else civil=0;
//**** Sunrise & set
h=AltitudeLimit ;// degrees
input_array[0]=d_sun_south;
input_array[1]=h;
result_array= CalculateStartStop(d_sun_south,h);
if (result_array[2]==0){
sun_rise=result_array[0];
sun_set=result_array[1];
sun_above_horison=result_array[2];
}
//**** Sunrise & set yesterday
h=AltitudeLimit ;// degrees
input_array[0]=d_sun_south_yesterday;
input_array[1]=h;
result_array= CalculateStartStop(d_sun_south_yesterday,h);
if (result_array[2]==0){
sun_rise_yesterday=result_array[0];
sun_set_yesterday=result_array[1];
}
Daylength_hour_yesterday=Math.floor((sun_set_yesterday-sun_rise_yesterday)*24);
Daylength_minute_yesterday=Math.floor(((sun_set_yesterday-sun_rise_yesterday)*24-Daylength_hour_yesterday)*60);
Difference= (sun_set-sun_rise) -(sun_set_yesterday - sun_rise_yesterday);
DifferenceSign='';
if (Difference<0) DifferenceSign='-';
if (Difference>0) DifferenceSign='+';
Difference=Math.abs(Difference);
Difference_hour=Math.floor(Difference*24);
Difference_minute=Math.floor(((Difference*24) -Difference_hour)*60);
Difference_seconds=Math.floor(( ((Difference*24) -Difference_hour)*60 -Difference_minute) *60);
// calculate daylength for 21 December and 21 June and
// display difference since last solstice
// equinox = 0 deg. At solstice = 23.45 degs
// find last solstice, calculate daylength, use this as reference
//
// must find a way of calculating last d_sun_solstice
//
// if Year
//document.Sun.Day.value=justnow.getDate();
//document.Sun.Month.value=justnow.getMonth()+1;
//document.Sun.Year.value=justnow.getFullYear();
d_selected=daynumber(document.Sun.Day.value*1,document.Sun.Month.value*1,document.Sun.Year.value*1,12,00,00);
//if (document.Sun.LatDir.value=='North') sitelat=document.Sun.Latitude.value
// else sitelat=-document.Sun.Latitude.value;
//if (document.Sun.LonDir.value=='West') sitelon=- document.Sun.Longitude.value
// else sitelon=document.Sun.Longitude.value;
// sjekk i stedet mot dag/måned , etter 21.12 , før 21.06
if (document.Sun.LatDir.value=='North') {
if (DifferenceSign=="+") {
if ((document.Sun.Day.value*1>21)&&(document.Sun.Month.value*1==12)) d_sun_solstice=daynumber(21,12,(document.Sun.Year.value*1),12,00,00)
else d_sun_solstice=daynumber(21,12,(document.Sun.Year.value*1-1),12,00,00);
// unntak når dagen i året er passert 21,12...
}
else
{
//alert('test');
// if ((document.Sun.Day.value*1>21)&&(document.Sun.Month.value*1==06)) d_sun_solstice=daynumber(21,06,(document.Sun.Year.value*1),12,00,00)
// else d_sun_solstice=daynumber(21,06,(document.Sun.Year.value*1),12,00,00);
// unntak når dagen i året er passert 21,12...
d_sun_solstice=daynumber(21,06,(document.Sun.Year.value*1),12,00,00); // fixed at this time
}
}
else
{
if (DifferenceSign=="-") {
if ((document.Sun.Day.value*1>21)&&(document.Sun.Month.value*1==12)) d_sun_solstice=daynumber(21,12,(document.Sun.Year.value*1),12,00,00)
else d_sun_solstice=daynumber(21,12,(document.Sun.Year.value*1-1),12,00,00);
// unntak når dagen i året er passert 21,12...
}
else
{
//alert('test');
// if ((document.Sun.Day.value*1>21)&&(document.Sun.Month.value*1==06)) d_sun_solstice=daynumber(21,06,(document.Sun.Year.value*1),12,00,00)
// else d_sun_solstice=daynumber(21,06,(document.Sun.Year.value*1),12,00,00);
// unntak når dagen i året er passert 21,12...
d_sun_solstice=daynumber(21,06,(document.Sun.Year.value*1),12,00,00); // fixed at this time
}
}
//
// Iterates for sun_south solstice
result_array=SunSouth(d_sun_solstice);
d_sun_south_solstice=result_array[0];
d=d_sun_south_solstice;
result_array=SunSouth(d);
d_sun_south_solstice=result_array[0];
d=d_sun_south_solstice;
result_array=SunSouth(d);
d_sun_south_solstice=result_array[0]; // Sun in south at selected solstice
h=AltitudeLimit ;// degrees
input_array[0]=d_sun_south_solstice; // blir feil...
input_array[1]=h;
result_array= CalculateStartStop(d_sun_south_solstice,h);
//alert(d_sun_south_solstice);
solstice_above_horison=result_array[2];
if (result_array[2]==0){ // sun above the limit on parts of the day
sun_rise_solstice=result_array[0];
sun_set_solstice=result_array[1];
Daylength_hour_solstice=Math.floor((sun_set_solstice-sun_rise_solstice)*24);
Daylength_minute_solstice=Math.floor(((sun_set_solstice-sun_rise_solstice)*24-Daylength_hour_solstice)*60);
Difference_solstice= (sun_set-sun_rise) -(sun_set_solstice- sun_rise_solstice);
DifferenceSign_solstice='';
if (Difference_solstice<0) DifferenceSign_solstice='-';
if (Difference_solstice>0) DifferenceSign_solstice='+';
Difference_solstice=Math.abs(Difference_solstice);
Difference_hour_solstice=Math.floor(Difference_solstice*24);
Difference_minute_solstice=Math.floor(((Difference_solstice*24) -Difference_hour_solstice)*60);
Difference_seconds_solstice=Math.floor(( ((Difference_solstice*24) -Difference_hour_solstice)*60 -Difference_minute_solstice) *60);
}
if (solstice_above_horison==-1) { // always below horizon at solstice
//alert("always below horizon");
Difference_solstice=-(1-(sun_set-sun_rise));
//DifferenceSign_solstice='';
if (Difference_solstice<0) DifferenceSign_solstice='-';
if (Difference_solstice>0) DifferenceSign_solstice='+';
Difference_solstice=Math.abs(Difference_solstice);
Difference_hour_solstice=Math.floor(Difference_solstice*24);
Difference_minute_solstice=Math.floor(((Difference_solstice*24) -Difference_hour_solstice)*60);
Difference_seconds_solstice=Math.floor(( ((Difference_solstice*24) -Difference_hour_solstice)*60 -Difference_minute_solstice) *60);
Daylength_hour_solstice=24;
Daylength_minute_solstice=0;
sun_rise_solstice=0;
sun_set_solstice=0;
}
if (solstice_above_horison==1) { // always above horizon at solstice
//alert("always above horizon");
Difference_solstice=(sun_set-sun_rise); // i.e. 24 hours - daylength
//DifferenceSign_solstice='';
if (Difference_solstice<0) DifferenceSign_solstice='-';
if (Difference_solstice>0) DifferenceSign_solstice='+';
Difference_solstice=Math.abs(Difference_solstice);
Difference_hour_solstice=Math.floor(Difference_solstice*24);
Difference_minute_solstice=Math.floor(((Difference_solstice*24) -Difference_hour_solstice)*60);
Difference_seconds_solstice=Math.floor(( ((Difference_solstice*24) -Difference_hour_solstice)*60 -Difference_minute_solstice) *60);
Daylength_hour_solstice=0;
Daylength_minute_solstice=0;
sun_rise_solstice=0;
sun_set_solstice=0;
}
/*
Try to calculate the other day of the year with equivalent day length
*/
if (d_selected>d_sun_solstice)
{
equivalent_day=d_to_date_and_time( (d_sun_solstice-(d_selected-d_sun_solstice)));
eq_Month= equivalent_day.getUTCMonth()+1;
if (eq_Month<10) eq_Month='0'+eq_Month;
eq_Day= equivalent_day.getUTCDate() ;
if (eq_Day<10) eq_Day='0'+eq_Day;
eq_Year= equivalent_day.getUTCFullYear();
}
else
{
//alert('d_selected"
listing+=""
listing+=""
listing+="Sun azimuth ~ Satellite Longitude"
listing+=""
listing+=""
listing+=""
listing+=""+UTCDateString+""
listing+=""+LTDateString+""
listing+="
"
listing+="
"
listing+="Satellite Position:"+document.Output.Satpos.value+""
listing+="
"
listing+="Sun Azimuth:"+document.Output.SunAzimuth.value+""
listing+="Satellite Elevation:"+document.Output.Satel.value+""
listing+="
"
listing+="Sun Elevation:"+document.Output.SunAltitude.value+""
listing+="
"
listing+="|Satellite Elevation-Sun Elevation|:"+document.Output.Offaxis.value+""
listing+=""
PrintWindow=window.open("","Print_window")
//PrintWindow =window.open("","Print_window","menubar=yes,status=yes,toolbar=yes,scrollbars=yes"); //height=800,width=1000
PrintWindow.oldWindow = top
//PrintWindow.document.write(document.Output.Satpos.value)
PrintWindow.document.write(listing)
PrintWindow.document.close()
}
function CalculateStartStop(d_sun_south,h)
{
var UT_Sun_in_south,today,time_offset,Day,Month,Year,Hour,Minute,Second,today,d,d_sunrise,d_sunset,t,above
// d = noon local time
var result_array = new Array();
var CosLHA
var return_array = new Array( );
//var deg_pr_hour=15.0;
above=0;
var inputvalues = new Array( );
CosLHA=SunRiseLHA(d_sun_south,h);
if (CosLHA<-1) above=-1
else if (CosLHA>1) above=1
else
{
above=0;
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sun_south,h)))/deg_pr_hour)/24);
//window.alert('First d_sunrise='+d_sunrise); // OK
// Sjekk første LHA for midnattsol eller mørketid
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
d_sunrise =d_sun_south-((Deg(Math.acos(SunRiseLHA(d_sunrise,h)))/deg_pr_hour)/24);
//window.alert('Second d_sunrise='+d_sunrise); // OK
// OK
//document.Sun.Results.value = document.Sun.Results.value+'Sun rise : ' +d_to_date_and_time(d_sunrise)+' (above defined altitude limit)\n';
}
if (CosLHA<-1) above=-1
else if (CosLHA>1) above=1
else
{
above=0;
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sun_south,h)))/deg_pr_hour)/24);
//window.alert('First d_sunrise='+d_sunrise); // OK
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
d_sunset =d_sun_south+((Deg(Math.acos(SunRiseLHA(d_sunset,h)))/deg_pr_hour)/24);
//window.alert('Second d_sunrise='+d_sunrise); // OK
// document.Sun.Results.value = document.Sun.Results.value+'Sun set : ' +d_to_date_and_time(d_sunset)+' (below defined altitude limit)\n';
// Daylength_hour=Math.floor((d_sunset-d_sunrise)*24)
// Daylength_minute=Math.floor(((d_sunset-d_sunrise)*24-Daylength_hour)*60);
// document.Sun.Results.value = document.Sun.Results.value+'Length above altitude limit: ' +Daylength_hour+'h '+Daylength_minute+'m\n';
}
return_array[0]=d_sunrise;
return_array[1]=d_sunset;
return_array[2]=above;
//return_array[2]=0;
return(return_array);
}
function SunSouth(d)
{
var SunSouth,HourAngle,SIDEREALTIME,SatAz,SunSat,Tst,SatelliteAzimuth,pi,NewRA
var w,a,e,M,L,oblecl,E,x,y,r,v,sunlon,z,xequat,yequat,zequat,RA,Decl,GMST0,UT,SIDTIME,HA
var CosLHA,h,UT_SunRise,UT_SunSet,d_SUNRISE,Elevation
pi=Math.PI;
var return_array = new Array( );
//*********CALCULATE SUN DATA *********************
// d kommer ikke fram
w=282.9404 + 4.70935E-5 * d ; //OK
a=1;
e= 0.016709 - 1.151E-9 *d ;
M= 356.0470 + 0.9856002585 * d;
oblecl=23.4393 -3.563E-7 * d ;
L=w+Rev(M);
L=Rev(L);
E=M+ (180/pi)*e*Math.sin(Radians(M))*( 1+e * Math.cos(Radians(M)) );
E=Rev(E); // OK
x= Math.cos(Radians(E)) -e ;
y= Math.sin(Radians(Rev(E)))*Math.sqrt(1-e*e);
r=Math.sqrt(x*x+y*y);
v=Deg(Math.atan2(y,x));
sunlon=Rev(v+w);
x=r*Math.cos(Radians(sunlon));
y=r*Math.sin(Radians(sunlon));
z=0;
xequat=x;
yequat=y*Math.cos(Radians(oblecl)) +z*Math.sin(Radians(oblecl));
zequat=y*Math.sin(Radians(oblecl)) +z*Math.cos(Radians(oblecl));
RA=Rev(Deg(Math.atan2(yequat,xequat))); // OK
//window.alert('RA='+RA);
Decl=Deg(Math.atan2(zequat,Math.sqrt(xequat*xequat + yequat*yequat ) )); // OK
//window.alert('Decl='+Decl);
GMST0=(L+180);
//*********CALCULATE SUNRISE *********************
UT_Sun_in_south=Rev(RA-GMST0-sitelon)/deg_pr_hour_15; // is ok -time when sun=south
d_sunsouth=(Math.floor(d)+(UT_Sun_in_south/24));
Elevation = Deg(Math.asin( Math.sin(Radians(sitelat))*Math.sin(Math.atan2(zequat,Math.sqrt(xequat*xequat + yequat*yequat ) )) + Math.cos(Radians(sitelat)) *Math.cos(Math.atan2(zequat,Math.sqrt(xequat*xequat + yequat*yequat ) )) ) );
//document.Sun.Results.value= formatvalue(Elevation,6)+'_deg\n';
return_array[0]=d_sunsouth;
return_array[1]=Elevation;
return(return_array) // OK
}
function SunRiseLHA(d,h_limit)
{
var SunSouth,HourAngle,SIDEREALTIME,SatAz,SunSat,Tst,SatelliteAzimuth,pi,NewRA
var w,a,e,M,L,oblecl,E,x,y,r,v,sunlon,z,xequat,yequat,zequat,RA,Decl,GMST0,UT,SIDTIME,HA
var CosLHA,h,UT_SunRise,UT_SunSet,d_SUNRISE;
pi=Math.PI;
//*********CALCULATE SUN DATA *********************
h=h_limit;
w=282.9404 + 4.70935E-5 * d ; //OK
a=1;
e= 0.016709 - 1.151E-9 *d ;
M= 356.0470 + 0.9856002585 * d;
oblecl=23.4393 -3.563E-7 * d ;
L=w+Rev(M);
L=Rev(L);
E=M+ (180/pi)*e*Math.sin(Radians(M))*( 1+e * Math.cos(Radians(M)) );
E=Rev(E); // OK
x= Math.cos(Radians(E)) -e ;
y= Math.sin(Radians(Rev(E)))*Math.sqrt(1-e*e);
r=Math.sqrt(x*x+y*y);
v=Deg(Math.atan2(y,x));
sunlon=Rev(v+w);
x=r*Math.cos(Radians(sunlon));
y=r*Math.sin(Radians(sunlon));
z=0;
xequat=x;
yequat=y*Math.cos(Radians(oblecl)) +z*Math.sin(Radians(oblecl));
zequat=y*Math.sin(Radians(oblecl)) +z*Math.cos(Radians(oblecl));
RA=Rev(Deg(Math.atan2(yequat,xequat))); // OK
//window.alert('RA='+RA);
Decl=Deg(Math.atan2(zequat,Math.sqrt(xequat*xequat + yequat*yequat ) )); // OK
//window.alert('Decl='+Decl);
GMST0=(L+180);
//*********CALCULATE SUNRISE *********************
UT_Sun_in_south=Rev(RA-GMST0-sitelon)/deg_pr_hour_15; // is ok -time when sun=south
CosLHA= ( Math.sin(Radians(h)) - (Math.sin(Radians(sitelat))*Math.sin(Radians(Decl)) ) )/(Math.cos(Radians(sitelat))*Math.cos(Radians(Decl)) );
//document.Sun.Results.value = document.Sun.Results.value+'CosLHA : ' +CosLHA+'\n';
//***** Return SunRise d ,makes it possible to iterate in next round
UT_SunRise=(Rev((RA-GMST0-sitelon))/deg_pr_hour)- (Deg(Math.acos(( Math.sin(Radians(h)) - (Math.sin(Radians(sitelat))*Math.sin(Radians(Decl)) ) )/(Math.cos(Radians(sitelat))*Math.cos(Radians(Decl)) )))/deg_pr_hour);
UT_SunSet=Rev((RA-GMST0-sitelon)+Deg(Math.acos(CosLHA)))/deg_pr_hour;
//window.alert('UT_SunRise='+UT_SunRise); // OK
//window.alert('UT_SunSet='+UT_SunSet); // OK
d_SUNRISE=(Math.floor(d)+(UT_SunRise/24));
return(CosLHA)
}
function Rev(number)
{
var x
x= number -Math.floor(number/360.0)*360 ;
return(x)
}
function Radians(number)
{
var rad
rad=number*Math.PI/180;
return(rad)
}
function Deg(number)
{
var rad
rad=number*180/Math.PI;
return(rad)
}
function daynumber(Day,Month,Year,Hour,Minute,Second)
{
//window.alert(Day+" "+Month+" "+Year+" "+Hour+" "+Minute+" "+Second);
d=367*Year - Div( (7*(Year+(Div((Month+9),12)))),4 ) + Div((275*Month),9) + Day - 730530
// d is correct
//window.alert(d);
d=d+ Hour/24 + Minute/(60*24) + Second/(24*60*60) // OK
return(d)
}
function Div(a,b)
{
return((a-a%b)/b) //OK
}
function showcredit()
{
var credit
credit= "Script programmed by Jens T.Saetre 04012004"
credit+="\n02012004 Started programming"
credit+="\n04012004 First uploaded"
credit+="\n04012004 Added user date input(default set to computer date)"
credit+="\n05012004 Calculate length of the day between sunrise & sunset"
credit+="\n11012004 Calculate altitude at sun south or north for southern hemisphere"
credit+="\n18012004 Added manual altitude limit input and better description of the limits"
credit+="\n01022004 Calculate rise,set and twilight in one operation"
credit+="\n03022004 Added button for printable display of results"
credit+="\n01012006 Added daylength difference from last solstice"
credit+="\n01022006 Automatic selection of winter & summer solstice"
credit+="\n11022006 Automatic selection of solstice for any year"
credit+="\n11022006 Calculation of the other day of the year which has got equal daylength or sun altitude"
credit+="\n17022006 Corrected bug in rise&set times for high latitudes"
credit+="\n17022006 Corrected bug in daylength at solstice and daylength difference since solstice"
window.alert(credit);
//var theResponse = window.prompt("Welcome?","Enter your name here.");
}
function ReadCookie()
{
var CookieValue
CookieValue= document.cookie;
if (CookieValue == null)
{
document.Sun.Location.selectedIndex=1074 // Set default groundstation
}
else
{
var tabell=new Array();
tabell = CookieValue.split(":") ;
document.Sun.Location.selectedIndex=tabell[4] ;// Set default groundstation
//window.alert(tabell[4]+" Readcookie");
}
} // end readcookie - works !!!
function Calculate()
{
//document.sun.UTHour.value=10;
}
function SetCookie()
{
var CookieValue
var expires=";expires=Tue, 10 Jul 2040 23:59:59 UTC;"
CookieValue=document.cookie;
if (CookieValue == null)
{
var alrt="Error in CookieValue"
alrt+="\nUse Antenna Look Angles calculator to cure the problem";
window.alert(alrt);
}
else
{
var tabell=new Array();
tabell = CookieValue.split(":") ;
tabell[4]=document.Sun.Location.selectedIndex ;// Set default groundstation
CookieValue="";
document.cookie="";
CookieValue=tabell[0]+":"+tabell[1]+":"+tabell[2]+":"+tabell[3]+":"+tabell[4]+":"+tabell[5]+":"+tabell[6]+":"+tabell[7]+":"+tabell[8]+":"+tabell[9]+":"+tabell[10]+":"+expires;
//window.alert(tabell[4]+" Setcookie");
//window.alert(CookieValue);
document.cookie=CookieValue ;
}
} // end SetCookie - works !!!
function SetLocation()
{
var Location=Array();
var Longitude=Array();
var Latitude= Array();
var LatDeg,LatMin,LatSec,LonDeg,LonMin,LonSec
var s = document.Sun.Location.value ;
// Split at each space character.
Location= s.split(","); // split into two
Latitude=Location[0].split(":");// split into degrees and North/South
Longitude=Location[1].split(":");// split into degrees and East/West
// window.prompt(Longitude[1],"Enter your name here.");
document.Sun.Latitude.value= Latitude[0]; // Latitude
document.Sun.Longitude.value= Longitude[0]; // Longitude
document.Sun.LatDir.value = Latitude[1]; // Latitude direction
document.Sun.LonDir.value =Longitude[1]; //Longitude direction
document.Sun.LatHour.value=formatvalue( Math.floor(Latitude[0]),2);
LatMin=Math.floor((Latitude[0]- Math.floor(Latitude[0]))*60);
LatSec=Math.floor( ((Latitude[0]- Math.floor(Latitude[0]))*60 - LatMin)*60 );
document.Sun.LatMin.value=formatvalue(LatMin ,2);
document.Sun.LatSec.value=formatvalue(LatSec ,2);
document.Sun.LonHour.value=formatvalue( Math.floor(Longitude[0]),2);
LonMin=Math.floor((Longitude[0]- Math.floor(Longitude[0]))*60);
LonSec=Math.floor( ((Longitude[0]- Math.floor(Longitude[0]))*60 - LonMin)*60 );
document.Sun.LonMin.value=formatvalue(LonMin ,2);
document.Sun.LonSec.value=formatvalue(LonSec ,2);
if (document.Sun.LatDir.value=='North') sitelat=document.Sun.Latitude.value
else sitelat=-document.Sun.Latitude.value;
if (document.Sun.LonDir.value=='West') sitelon=- document.Sun.Longitude.value
else sitelon=document.Sun.Longitude.value;
}
function formatvalue(input, rsize) // Desimal avrunding
{
var invalid = "**************************";
var nines = "999999999999999999999999";
var strin = "" + input;
var fltin = parseFloat(strin);
if (strin.length <= rsize) return strin;
if (strin.indexOf("e") != -1 ||
fltin > parseFloat(nines.substring(0,rsize)+".4"))
return invalid.substring(0, rsize);
var rounded = "" + (fltin + (fltin - parseFloat(strin.substring(0, rsize))));
return rounded.substring(0, rsize);
}
function UpdateCoordinates()
{
var LatDeg,LatMin,LatSec,LonDeg,LonMin,LonSec
LatDeg=1*document.Sun.LatHour.value;
LatMin=1*document.Sun.LatMin.value;
LatSec=1*document.Sun.LatSec.value;
LonDeg=1*document.Sun.LonHour.value;
LonMin=1*document.Sun.LonMin.value;
LonSec=1*document.Sun.LonSec.value;
document.Sun.Latitude.value=formatvalue((LatDeg + (LatMin/60) + (LatSec/3600)),5) ; // Latitude
document.Sun.Longitude.value=formatvalue( (LonDeg+ (LonMin/60) + (LonSec/3600)),5); // Longitude
if (document.Sun.LatDir.value=='North') sitelat=document.Sun.Latitude.value
else sitelat=-document.Sun.Latitude.value;
if (document.Sun.LonDir.value=='West') sitelon=- document.Sun.Longitude.value
else sitelon=document.Sun.Longitude.value;
}
function Convert_to_deg_min_sec(){
var Latitude,Longitude,LatDeg,LatMin,LatSec,LonDeg,LonMin,LonSec
Latitude=document.Sun.Latitude.value // Latitude
Longitude=document.Sun.Longitude.value // Longitude
document.Sun.LatHour.value=formatvalue( Math.floor(Latitude),2);
LatMin=Math.floor((Latitude- Math.floor(Latitude))*60);
LatSec=Math.floor( ((Latitude- Math.floor(Latitude))*60 - LatMin)*60 );
document.Sun.LatMin.value=formatvalue(LatMin ,2);
document.Sun.LatSec.value=formatvalue(LatSec ,2);
document.Sun.LonHour.value=formatvalue( Math.floor(Longitude),2);
LonMin=Math.floor((Longitude- Math.floor(Longitude))*60);
LonSec=Math.floor( ((Longitude- Math.floor(Longitude))*60 - LonMin)*60 );
document.Sun.LonMin.value=formatvalue(LonMin ,2);
document.Sun.LonSec.value=formatvalue(LonSec ,2);
if (document.Sun.LatDir.value=='North') sitelat=document.Sun.Latitude.value
else sitelat=-document.Sun.Latitude.value;
if (document.Sun.LonDir.value=='West') sitelon=- document.Sun.Longitude.value
else sitelon=document.Sun.Longitude.value;
}
function LatLon()
{
if (document.Sun.LatDir.value=='North') sitelat=document.Sun.Latitude.value
else sitelat=-document.Sun.Latitude.value;
if (document.Sun.LonDir.value=='West') sitelon=- document.Sun.Longitude.value
else sitelon=document.Sun.Longitude.value;
}