APSF //- Minor Planet Report. Create custom minor planet observation forms //- //- Paul Rodman, March 2008 //- (with feedback from Dave Birmingham) //- //- Version 1.0 1 Mar 2008 //- Initial release //- Version 1.1 2 Mar 2008 //- Added landscape/portrait display options //- Version 1.2 2 Mar 2008 //- Added motion/hr column option //- Version 1.3 3 Mar 2008 //- Adjusted column spacing //- Version 1.4 3 Mar 2008 //- Optional output to text file //------------------------------------------------------------------ function CompareObjects(a as APPlanObject, b as APPlanObject, sortType as integer) as integer select case sortType case 1 if floor(a.RA)floor(b.RA) then return 1 if a.Decb.Dec then return 1 return 0 else if a.RAb.RA then return 1 return 0 end select end function //------------------------------------------------------------------ dim c as Canvas, tbody,thead,tpage as Table dim objects(-1),tobject as APPlanObject dim i,j,y,iRA,lastRA,theight,bheight,gr,nGroup(23),pnumber,isPrinting,yold,sortType,nLinesAfter,nLinesAfterGroup as integer dim extraColumns, fontSize, pfontSize,lastComputedColumn as integer dim swap,gridLines,motion,isFixed,outputText as boolean dim id,sunderline,colhdr,headers(-1),fontName,pfontName,fn(-1) as string dim localTime,RA(-1),Dec(-1),MotionValue(-1),t,colwidth(-1),tcolw as double dim tfile as APTextFile // Retrieve saved parameters isPrinting=RestoreIntegerValue("isPrinting",0) gridLines=RestoreBooleanValue("gridLines",false) motion=RestoreBooleanValue("motion",false) outputText=RestoreBooleanValue("outputText",false) sortType=RestoreIntegerValue("sortType",0) nLinesAfter=RestoreIntegerValue("nLinesAfter",1) nLinesAfterGroup=RestoreIntegerValue("nLinesAfterGroup",1) colhdr=RestoreStringValue("colhdr","Notes") fn=Fonts fontName=RestoreStringValue("fontName",fn(0)) pFontName=RestoreStringValue("pFontName",fn(0)) fontSize=RestoreIntegerValue("fontSize",11) pfontSize=RestoreIntegerValue("pfontSize",9) // Use dialog to change parameters where necessary SetChoiceParameter("Output",isPrinting,"Preview on screen (Landscape)","Preview on screen (Portrait)","Print") SetChoiceParameter("Sort Type",sortType,"By RA","By RA hours/Dec") SetIntegerParameter("Blank lines after each object",nLinesAfter,0,10) SetIntegerParameter("Blank lines after each RA hour group",nLinesAfterGroup,0,10) SetStringParameter("Extra column titles (one per line)",colhdr,true) SetPopupParameter("Preview Font",fn.IndexOf(fontName),fn) SetIntegerParameter("Preview Font Size",fontSize,4,100) SetPopupParameter("Printing Font",fn.IndexOf(pfontName),fn) SetIntegerParameter("Printing Font Size",pfontSize,4,100) SetBooleanParameter("Grid lines",gridLines) SetBooleanParameter("Include motion/hr column",motion) SetBooleanParameter("Also create tab-separated text file",outputText) if not EditParameters("MP Report") then return isPrinting=GetChoiceParameter("Output") gridLines=GetBooleanParameter("Grid lines") sortType=GetChoiceParameter("Sort Type") nLinesAfter=GetIntegerParameter("Blank lines after each object") nLinesAfterGroup=GetIntegerParameter("Blank lines after each RA hour group") colhdr=GetStringParameter("Extra column titles (one per line)") if trim(colhdr)<>"" then headers=Split(trim(colhdr),EndOfLine) extraColumns=ubound(headers)+1 fontName=fn(max(0,GetPopupParameter("Preview Font"))) fontSize=GetIntegerParameter("Preview Font Size") pfontName=fn(max(0,GetPopupParameter("Printing Font"))) pfontSize=GetIntegerParameter("Printing Font Size") motion=GetBooleanParameter("Include motion/hr column") outputText=GetBooleanParameter("Also create tab-separated text file") // Save prameter values for next time SaveIntegerValue("isPrinting",isPrinting) SaveBooleanValue("gridLines",gridLines) SaveBooleanValue("motion",motion) SaveBooleanValue("outputText",outputText) SaveIntegerValue("sortType",sortType) SaveIntegerValue("nLinesAfter",nLinesAfter) SaveIntegerValue("nLinesAfterGroup",nLinesAfterGroup) SaveStringValue("colhdr",colhdr) SaveStringValue("fontName",fontName) SaveStringValue("pFontName",pFontName) SaveIntegerValue("fontSize",fontSize) SaveIntegerValue("pfontSize",pfontSize) if outputText then tfile=WriteTextFile("","MPReport.txt") if tfile=nil then return end if if motion then StartProgress("Computing motion/hr") // Get current datetime localTime=PlanLocalDateTime isFixed=FixedDate // Go back a day PlanLocalDateTime=localTime-3600.0 // Collect RA/Decs for i=1 to nObj RA.Append Obj(i).RA Dec.Append Obj(i).Dec next // Revert to current time PlanLocalDateTime=localTime // Compute motion for i=1 to nObj MotionValue.Append AngleBetween(Obj(i).RA,Obj(i).Dec,RA(i-1),Dec(i-1)) next if not isFixed then FixedDate=false StopProgress end if // Gather objects for i=1 to nObj objects.Append Obj(i) j=floor(Obj(i).RA) nGroup(j)=nGroup(j)+1 next // Crude but simple bubble sort for i=ubound(objects) downto 1 swap=false for j=0 to i-1 if CompareObjects(objects(j),objects(j+1),sortType)>0 then tobject=objects(j) objects(j)=objects(j+1) objects(j+1)=tobject if motion then t=MotionValue(j) MotionValue(j)=MotionValue(j+1) MotionValue(j+1)=t end if swap=true end if next if not swap then exit next // Open a new printer document (or display window) select case isPrinting case 0 c=new Canvas(1100,800,"Minor Planet Report") case 1 c=new Canvas(800,1100,"Minor Planet Report") case 2 c=new Canvas(false) end select if not c.Cancelled then // Set up fonts if isPrinting=2 then c.TextFont(pfontname,pfontsize) else c.TextFont(fontname,fontsize) end if if gridLines then gr=grid_Thin else gr=grid_None lastComputedColumn=5 if motion then lastComputedColumn=lastComputedColumn+1 // Set up page column headings // Find column widths redim colwidth(lastComputedColumn) colwidth(1)=c.TextWidth("R.A. 00h") colwidth(2)=c.TextWidth("ID") colwidth(3)=c.TextWidth("R.A.") colwidth(4)=c.TextWidth("Declination") colwidth(5)=c.TextWidth("Magnitude") if motion then colwidth(6)=c.TextWidth("Motion/hr") for i=0 to ubound(objects) id=objects(i).ID if IsNumeric(id) then id=id+"/"+objects(i).Name else if objects(i).Name<>"" then id=id+" ("+objects(i).Name+")" end if colwidth(2)=max(colwidth(2),c.TextWidth(id)) colwidth(3)=max(colwidth(3),c.TextWidth(objects(i).RAFormatted)) colwidth(4)=max(colwidth(4),c.TextWidth(objects(i).DecFormatted)) colwidth(5)=max(colwidth(5),c.TextWidth(format(objects(i).Magnitude,"-0.0"))) next tcolw=0.0 for i=1 to ubound(colwidth) colwidth(i)=(colwidth(i)*1.3)/c.Width*100.0 tcolw=tcolw+colwidth(i) next thead=new Table(1,lastComputedColumn+extraColumns) for i=1 to lastComputedColumn thead.ColumnWidth(i)=colwidth(i) next thead.Cell(1,2)="ID" thead.Cell(1,3)="R.A." thead.Cell(1,4)="Declination" thead.Cell(1,5)="Magnitude" if motion then thead.Cell(1,6)="Motion/hr" for j=1 to extraColumns thead.Cell(1,lastComputedColumn+j)=trim(headers(j-1)) next for j=3 to lastComputedColumn+extraColumns thead.ColumnJustify(j)=justify_Center next thead.RowStyle(1)=style_Bold thead.RowHeight(1)=150.0 sunderline="" if extraColumns>0 and not gridLines then while c.TextWidth(sunderline)<((100.0-tcolw)*0.01*c.Width/extraColumns)*0.8 sunderline=sunderline+"_" wend end if // Set up body lines tbody=new Table(1,lastComputedColumn+extraColumns) for i=1 to lastComputedColumn tbody.ColumnWidth(i)=colwidth(i) next tbody.CellStyle(1,1)=style_Bold for j=1 to extraColumns tbody.Cell(1,lastComputedColumn+j)=sunderline next for j=3 to lastComputedColumn+extraColumns tbody.ColumnJustify(j)=justify_Center next if nLinesAfter>0 then tbody.RowHeight(1)=100.0*(nLinesAfter+1) // Set up title/page number lines tpage=new Table(1,2) tpage.CellStyle(1,1)=style_Italic tpage.CellStyle(1,2)=style_Italic tpage.ColumnJustify(2)=justify_Right tpage.ColumnWidth(1)=90.0 tpage.Cell(1,1) = "Local Date/Time: "+DoubleToDate(PlanLocalDateTime)+" "+DoubleToTime(PlanLocalDateTime, false) if outputText then for j=2 to thead.ColumnCount tfile.Write chr(9)+thead.Cell(1,j) next tfile.WriteLine end if pnumber=0 lastRA=-999 y=0 for i=0 to ubound(objects) iRA=floor(objects(i).RA) // Check for new page if y>c.Height-bheight then if i>0 then c.NewPage y=0 end if end if // Headers if y=0 then pnumber=pnumber+1 tpage.Cell(1,2)="Page "+str(pnumber) y=c.DrawTable(tpage,0,y,c.Width,c.Height-y,grid_None) y=c.DrawTable(thead,0,y,c.Width,c.Height-y,grid_None) if theight=0 then theight=y end if // Check for new group if iRA<>lastRA or y<=theight then tbody.Cell(1,1)="R.A. "+format(iRA,"00")+"h" lastRA=iRA if i>0 and y>theight then y=y+nLinesAfterGroup*c.TextHeight else tbody.Cell(1,1)="" end if // Set up the line id=objects(i).ID if IsNumeric(id) then id=id+"/"+objects(i).Name else if objects(i).Name<>"" then id=id+" ("+objects(i).Name+")" end if tbody.Cell(1,2)=id tbody.Cell(1,3)=objects(i).RAFormatted tbody.Cell(1,4)=objects(i).DecFormatted tbody.Cell(1,5)=format(objects(i).Magnitude,"-0.0") if motion then if MotionValue(i)<1/60.0 then tbody.Cell(1,6)=format(MotionValue(i)*3600.0,"0.00")+"""" elseif MotionValue(i)<1.0 then tbody.Cell(1,6)=format(MotionValue(i)*60.0,"0.00")+"'" else tbody.Cell(1,6)=format(MotionValue(i),"0.00")+DegreeSymbol end if end if yold=y y=c.DrawTable(tbody,0,y,c.Width,c.Height-y,gr) if outputText then for j=1 to tbody.ColumnCount if j>1 then tfile.Write chr(9) tfile.Write tbody.Cell(1,j) next tfile.WriteLine end if if bheight<=0 then bheight=y-yold next tbody.Close thead.Close c.Close if outputText then tfile.Close end if