APSF //- Display/print a monthly calendar showing hours of darkness and moon info //- By Paul Rodman, with modifications by Joe Novak. //- //- V1.1 4 Nov 2007 //- Fixed problem with choosing any year other than "Current" //- V1.2 5 Nov 2007 //- Fixed problem with systems not having a font called "Times" //- V1.3 5 Nov 2007 //- Fixed problem if no fonts defined, no sites defined, etc. //- V1.3a 6 Nov 2007 //- Display version of script in dialog title //- V1.4 26 May 2008 //- Workaround to fix twilight bug. const scriptversion = "V1.4" dim mo(-1),yr(-1) as string, dp,i,j,siteid,month,year,day,y,col as integer, st(-1),theSite as SiteResource dim c as Canvas, s as string, t as Table, d,r,rr(-1) as double dim pfont,dfont,fontlist(-1) as string, psize,dsize as integer const startYear = 2008 // printreport is false to Display, true to Print dim printreport as boolean printreport = false // Default fonts fontlist=Fonts if ubound(fontlist)<0 then print "No fonts defined in your OS!" return end if pfont="Times" if fontlist.IndexOf(pfont)<0 then pfont="Times New Roman" end if if fontlist.IndexOf(pfont)<0 then pfont="System" end if if fontlist.IndexOf(pfont)<0 then pfont=fontlist(0) end if dfont="System" if fontlist.IndexOf(dfont)<0 then dfont=fontlist(0) end if psize=10 dsize=11 // First get site and month to display, and fonts, etc. mo=MonthNames mo(0)="Current" yr.Append "Current" for i=startYear to startYear+10 yr.Append str(i) next st=Sites if ubound(st)<0 then print "You must have at least one Site resource defined!" return end if siteID=st.IndexOf(CurrentSite) if siteID>=0 then st.Remove siteID st.Insert 0,CurrentSite end if siteID=0 SetPopupParameter("Site",0,st) SetPopupParameter("Month",0,mo) SetPopupParameter("Year",0,yr) SetChoiceParameter("Display/Print",dp,"Display","Print") SetPopupParameter("Display Font",fontlist.IndexOf(dfont),fontlist) SetIntegerParameter(true,"Size.1",dsize,4,128) SetPopupParameter("Print Font",fontlist.IndexOf(pfont),fontlist) SetIntegerParameter(true,"Size.2",psize,4,128) if not EditParameters("Darkness Calendar ("+scriptversion+")") then return siteid=GetPopupParameter("Site") theSite=st(siteid) month=GetPopupParameter("Month") year=GetPopupParameter("Year") if month<=0 then month=MonthOfDate(CurrentDate) if year<=0 then year=YearOfDate(CurrentDate) else year=year+startYear-1 end if dfont=fontlist(GetPopupParameter("Display Font")) dsize=GetIntegerParameter("Size.1") pfont=fontlist(GetPopupParameter("Print Font")) psize=GetIntegerParameter("Size.2") if GetChoiceParameter("Display/Print")=1 then printreport = true end if // Create a canvas window to display it in. s="Darkness Calendar for "+st(siteid).Name+": "+mo(month)+" "+str(year) if printreport then c=new Canvas(false) c.TextFont(pfont,psize) else c=new Canvas(1100,800,s) c.TextFont(dfont,dsize) end if if not c.cancelled then // Construct a table containing the values // Headings t=new Table(DaysInMonth(month,year),13,s) t.ColumnTitle(1)="Date" t.ColumnTitle(2)="Moon Rise" t.ColumnTitle(3)="Moon Set" t.ColumnTitle(4)="Moon Phase" t.ColumnTitle(5)="Moon Illum." t.ColumnTitle(6)="Astronomical Twilight starts" t.ColumnTitle(7)="Nautical Twilight starts" t.ColumnTitle(8)="Civil Twilight starts" t.ColumnTitle(9)="Sun Rise" t.ColumnTitle(10)="Sun Set" t.ColumnTitle(11)="Civil Twilight ends" t.ColumnTitle(12)="Nautical Twilight ends" t.ColumnTitle(13)="Astronomical Twilight ends" t.ColumnWidth(2)=7 t.ColumnWidth(3)=7 t.ColumnWidth(4)=7 t.ColumnWidth(9)=7 t.ColumnWidth(10)=7 t.RowHeight(0)=300.0 t.RowStyle(0)=style_Bold+style_Inverted+Style_Gray // Iterate over the days in the month for day=1 to DaysInMonth(month,year) d=MakeDate(year,month,day) t.Cell(day,1)=DoubleToDate(d) r=MoonRise(d,theSite) if r<0 then t.Cell(day,2)="---" else t.Cell(day,2)=DoubleToTime(r,false) r=MoonSet(d,theSite) if r<0 then t.Cell(day,3)="---" else t.Cell(day,3)=DoubleToTime(r,false) r=MoonPhase(d,theSite) if abs(r)>170 then s="New" elseif abs(r)<10 then s="Full" elseif r>80 and r<100 then s="1st Q" elseif r>-100 and r<-80 then s="Last Q" else s="" end if t.Cell(day,4)=s r=MoonIllumination(d,theSite) t.Cell(day,5)=format(r*100.0,"-0")+"%" rr=Sunrise(d,theSite) col=6 for i=3 downto 0 if rr(i)<0 or (rr(i)>9 and rr(i)<15) then t.Cell(day,col)="---" else t.Cell(day,col)=DoubleToTime(rr(i),false) col=col+1 next rr=Sunset(d,theSite) for i=0 to 3 if rr(i)<0 or (rr(i)>9 and rr(i)<15) then t.Cell(day,col)="---" else t.Cell(day,col)=DoubleToTime(rr(i),false) col=col+1 next next // Draw the table into the canvas window. y=c.DrawTable(t,0,0,c.Width,c.Height,grid_Thin) end if c.Close