APSF //- Display/print a monthly calendar showing rise/transit/set info for the selected object //- at the current site. //- //- Paul Rodman, April 2008 //- //- V1.0 11 Apr 2008 //- Initial release //- V1.1 11 Apr 2008 //- Handles solar system objects correctly (albeit much slower) //- Removes problems with Site selection //- V1.2 12 Apr 2008 //- Removes problem with moon rise/set being reported as Circumpolar const scriptversion = "V1.1" const DegreesToRadians=0.017453292 const RadiansToDegrees=57.29577951 //--------------------------------------------------------------------------------------------- function Elevation(ob as APPlanObject) as double dim r as double r=(90.0-CurrentSite.Latitude)+ob.Dec if r>90 then r=180-r return r end function //--------------------------------------------------------------------------------------------- function Azimuth(ob as APPlanObject, which as integer) as double dim az as double if which=2 then // Azimuth of transit is either north or south if ob.Dec>CurrentSite.Latitude then return 0.0 else return 180.0 end if az=acos(sin(ob.Dec*DegreesToRadians)/cos(CurrentSite.Latitude*DegreesToRadians))*RadiansToDegrees select case which case 1 // Rise return abs(az) case 3 // Set return 360.0-abs(az) end select end function //--------------------------------------------------------------------------------------------- dim mo(-1),yr(-1) as string, dp,i,j,month,year,day,y,col as integer dim c as Canvas, s as string, t as Table, d,r,rr(-1),oldDate, riseTime,transitTime,setTime as double dim pfont,dfont,fontlist(-1) as string, psize,dsize as integer dim ob as APPlanObject, solarSystem as boolean const startYear = 2008 const incr = 0.065708418 // 24/365.25 // printreport is false to Display, true to Print dim printreport as boolean printreport = false // Check that an object is selected if SelectedObject<=0 then print "No object is selected!" return end if ob=Obj(SelectedObject) // 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 if CurrentSite=nil then print "Please select a Current Site for this plan" return end if 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("Rise/Transit/Set Calendar ("+scriptversion+") for "+ob.ID) then return 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="Rise/Transit/Set Calendar for "+ob.ID+" at "+CurrentSite.Name+": "+mo(month)+" "+str(year) if printreport then c=new Canvas(false) c.TextFont(pfont,psize) else c=new Canvas(800,1100,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),8,s) t.ColumnTitle(1)="Date" t.ColumnTitle(2)="Rise Time" t.ColumnTitle(3)="Azimuth" t.ColumnTitle(4)="Transit Time" t.ColumnTitle(5)="Azimuth" t.ColumnTitle(6)="Elevation" t.ColumnTitle(7)="Set Time" t.ColumnTitle(8)="Azimuth" t.RowHeight(0)=150.0 t.RowStyle(0)=style_Bold+style_Inverted+Style_Gray // Iterate over the days in the month if FixedDate then oldDate=PlanLocalDateTime else oldDate=0.0 solarSystem = ob.Type="Planet" or ob.Type="Moon" or ob.Type="Sun" or ob.Type="Comet" or ob.Type="Minor" if solarSystem then StartProgress("Computing calendar",true,DaysInMonth(month,year)) for day=1 to DaysInMonth(month,year) d=MakeDate(year,month,day) if day=1 or solarSystem then PlanLocalDateTime=d riseTime=ob.Rise transitTime=ob.Transit setTime=ob.Set else riseTime=riseTime-incr if riseTime<0.0 then risetime=riseTime+24.0 transitTime=transitTime-incr if transitTime<0.0 then transitTime=transitTime+24.0 setTime=setTime-incr if setTime<0.0 then setTime=setTime+24.0 end if t.Cell(day,1)=DoubleToDate(d) if solarSystem and riseTime<0 then t.Cell(day,2)="---" t.Cell(day,3)="---" elseif riseTime=-2 then t.Cell(day,2)="Never" t.Cell(day,3)="---" elseif riseTime=-1 then t.Cell(day,2)="Circum" t.Cell(day,3)="---" else t.Cell(day,2)=DoubleToTime(riseTime,false) t.Cell(day,3)=format(Azimuth(ob,1),"0")+DegreeSymbol end if if solarSystem and (riseTime<0 or setTime<0) then t.Cell(day,4)="---" t.Cell(day,5)="---" t.Cell(day,6)="---" else t.Cell(day,4)=DoubleToTime(transitTime,false) t.Cell(day,5)=format(Azimuth(ob,2),"0")+DegreeSymbol r=Elevation(ob) if r<0.0 then t.Cell(day,6)="---" else t.Cell(day,6)=format(Elevation(ob),"0.0")+DegreeSymbol end if end if if solarSystem and setTime<0 then t.Cell(day,7)="---" t.Cell(day,8)="---" elseif setTime=-2 then t.Cell(day,7)="---" t.Cell(day,8)="---" elseif setTime=-1 then t.Cell(day,7)="Circum" t.Cell(day,8)="---" else t.Cell(day,7)=DoubleToTime(setTime,false) t.Cell(day,8)=format(Azimuth(ob,3),"0")+DegreeSymbol end if if solarSystem then if UpdateProgress(day) then exit end if next if solarSystem then StopProgress // Draw the table into the canvas window. y=c.DrawTable(t,0,0,c.Width,c.Height,grid_Thin) PlanLocalDateTime=oldDate end if c.Close