APSF //- For each plan object, compute viewable period. //- "Viewable period" is defined as the period during which the //- object is above a given altitude, between given times, and, //- optionally, when the moon is not visible or below a given //- % illumination). //- The result/s are placed in user-defined fields. //- //- Paul Rodman, Dec 2007 //- //- V1.0 18 Dec 2007 //- Initial release. //- V1.1 19 Dec 2007 //- Fixed a bug that prevented longer lists of objects from being //- completely processed. //- V1.2 12 Feb 2008 //- Add ability to select highlighted objects only, etc. dim doMoon as boolean dim mIllum,pStart,pEnd,objAlt as double dim nStart,nEnd,nVH,nVS,nVE,which as integer dim t(-1),vs,ve,whichs(-1) as string dim d,mrise,mset,srise(3),sset(3),periodFrom,periodTo,dFrom,dTo,dStart,dBefore,dBegin(-1),dEnd(-1) as double dim iobj as integer, ob,olist(-1) as APPlanObject dim viewable as double dim cancelled as boolean const steps = 6.0 // 6 minute steps (the smaller the step, the longer the process) const dtime = 0.5 // Increase this if all objects are not getting processed // Initialise parameters doMoon = true mIllum = 5.0 nStart=3 nEnd=3 pStart=20.0 pEnd=5.0 objAlt=20.0 nVH=1 nVS=2 nVE=3 which=0 // Restore parameters from last run which = RestoreIntegerValue("which",which) doMoon = RestoreBooleanValue("doMoon",doMoon) mIllum = RestoreDoubleValue("mIllum",mIllum) nStart = RestoreIntegerValue("nStart",nStart) nEnd = RestoreIntegerValue("nEnd",nEnd) pStart = RestoreDoubleValue("pStart",pStart) pEnd = RestoreDoubleValue("pEnd",pEnd) objAlt = RestoreDoubleValue("objAlt",objAlt) nVH = RestoreIntegerValue("nVH",nVH) nVS = RestoreIntegerValue("nVS",nVS) nVE = RestoreIntegerValue("nVE",nVE) // Get parameters whichs.Append "All "+str(nObj)+" objects" if nHighlighted>0 then whichs.Append "All "+str(nHighlighted)+" highlighted objects" else if which=1 then which=0 end if if nObj>nHighlighted then whichs.Append "All "+str(nObj-nHighlighted)+" unhighlighted objects" else if which=2 then which=0 end if if SelectedObject>0 then whichs.Append "Selected object only" else if which=3 then which=0 end if SetChoiceParameter("Which objects to process",which,whichs) SetBooleanParameter("Take moon into account",doMoon) SetDoubleParameter("Moon illumination (%) greater than",mIllum,0.0,100.0) ParameterDependency("Moon illumination (%) greater than","Take moon into account") redim t(-1) t.Append "Sunset" t.Append "End of Civil twilight" t.Append "End of Nautical twilight" t.Append "End of Astronomical twilight" t.Append "Given Start Time" SetPopupParameter("Observing period start",nStart,t) SetTimeParameter("Start time (if applicable)",pStart) redim t(-1) t.Append "Sunrise" t.Append "Start of Civil twilight" t.Append "Start of Nautical twilight" t.Append "Start of Astronomical twilight" t.Append "Given End Time" SetPopupParameter("Observing period end",nEnd,t) SetTimeParameter("End time (if applicable)",pEnd) SetDoubleParameter("Minimum object altitude ("+DegreeSymbol+")",objAlt,0.0,90.0) redim t(-1) t.Append "n/a" t.Append "User Field 1" t.Append "User Field 2" t.Append "User Field 3" t.Append "User Field 4" SetPopupParameter("Put Viewable Hours into",nVH,t) SetPopupParameter("Put Viewable Start Time into",nVS,t) SetPopupParameter("Put Viewable End Time into",nVE,t) if not EditParameters("Viewable Hours") then return which=GetChoiceParameter("Which objects to process") doMoon=GetBooleanParameter("Take moon into account") mIllum=GetDoubleParameter("Moon illumination (%) greater than") nStart=GetPopupParameter("Observing period start") pStart=GetTimeParameter("Start time (if applicable)") nEnd=GetPopupParameter("Observing period end") pEnd=GetTimeParameter("End time (if applicable)") objAlt=GetDoubleParameter("Minimum object altitude ("+DegreeSymbol+")") nVH=GetPopupParameter("Put Viewable Hours into") nVS=GetPopupParameter("Put Viewable Start Time into") nVE=GetPopupParameter("Put Viewable End Time into") // Get the requisite objects for iobj=1 to nObj select case which case 0 olist.Append Obj(iobj) case 1 if Obj(iobj).IsHighlighted then olist.Append Obj(iobj) case 2 if not Obj(iobj).IsHighlighted then olist.Append Obj(iobj) case 2 if SelectedObject=iobj then olist.Append Obj(iobj) end select next // Find the time limits d=PlanLocalDateTime dStart = MakeDate(YearOfDate(d),MonthOfDate(d),DayOfDate(d))-12.0*3600.0 // Get observing period start if nStart>=4 then periodFrom=pStart else // Sunset today sset=Sunset(d) periodFrom=sset(nStart) end if // Get observing period end if nEnd>=4 then periodTo=pEnd if periodTomIllum*0.01 then // Moonrise today mrise=Moonrise(d) // Moonset today mset=Moonset(d) if mrise>0.0 and mrise>mset then mset=Moonset(d+24*3600.0)+24.0 // Check various scenarios // moon rises/sets outside period if msetperiodTo then // No change to period, moon doesn't rise elseif mriseperiodFrom and mset>periodTo then // First part of period OK periodTo=mrise elseif mrise>periodFrom and mset=objAlt then if dBegin(iobj)<0.0 then dBegin(iobj)=d if dBegin(iobj)>=0.0 then dEnd(iobj)=d end if next d=d+steps*60.0 wend PlanLocalDateTime=dBefore if not Cancelled then // Put stuff into user-defined columns if nVH>0 then UserHeading(nVH)="Viewable Period" if nVS>0 then UserHeading(nVS)="Viewable Start" if nVE>0 then UserHeading(nVE)="Viewable End" for iobj=0 to ubound(olist) ob=olist(iobj) if dBegin(iobj)<0.0 then viewable=0.0 vs="n/a" ve="n/a" else viewable=(dEnd(iobj)-dBegin(iobj))/3600.0 vs=DoubleToTime(dBegin(iobj),false) ve=DoubleToTime(dEnd(iobj),false) end if if nVH>0 then ob.User(nVH)=format(viewable,"0.0") if nVS>0 then ob.User(nVS)=vs if nVE>0 then ob.User(nVE)=ve next end if StopProgress // Save parameters for next run SaveIntegerValue("which",which) SaveBooleanValue("doMoon",doMoon) SaveDoubleValue("mIllum",mIllum) SaveIntegerValue("nStart",nStart) SaveIntegerValue("nEnd",nEnd) SaveDoubleValue("pStart",pStart) SaveDoubleValue("pEnd",pEnd) SaveDoubleValue("objAlt",objAlt) SaveIntegerValue("nVH",nVH) SaveIntegerValue("nVS",nVS) SaveIntegerValue("nVE",nVE) Bleep