APSF //- Export objects from an AstroPlanner catalogue to a .txt file //- that TheSky can import and create an .SDB catalog file from. //- //- Paul Rodman Dec 2008 //- //- V1.0 - 2 Dec 2008 //- Initial release //- V1.1 - 3 Dec 2008 //- Corrected problem with Dec sign //- V1.2 - 4 Dec 2008 //- Corrected assorted problems (I hope) //----------------------------------------------------------------------------------- function FormatNumber(x as double, cols as integer, doSign as boolean = false) as string dim fmt,result as string if doSign then fmt="+0.0" else fmt="-0.0" do result=format(x,fmt) fmt=fmt+"0" loop until len(result)>=cols return result end function //----------------------------------------------------------------------------------- function GetType(stype as string) as integer select case NthField(ReplaceAll(stype," ",""),"+",1) case "Star" return 0 case "VarStar" return 1 case "Dbl" return 3 case "Galaxy","Gal", "EGal", "SGal", "IrrGal" return 4 case "GalClus" return 10 case "Open" return 11 case "Globular" return 12 case "Neb" return 14 case "BrNeb","ENeb","RNeb", "DNeb" return 15 case "DkNeb" return 16 case "PNeb" return 17 else return -1 end select end function //----------------------------------------------------------------------------------- function Alphabetic(c as string) as boolean return Lowercase(c)>="a" and LowerCase(c)<="z" end function //----------------------------------------------------------------------------------- sub SplitID(id as string, byref a as string, byref b as string) if left(id,2)="3C" then a="3C" b=mid(id,3) elseif left(id,5)="2UCAC" then a="2UCAC" b=mid(id,6) else i=1 while i<=len(id) and Alphabetic(mid(id,i,1)) i=i+1 wend a=left(id,i-1) b=mid(id,i) end if end sub //----------------------------------------------------------------------------------- const maxObjects = 100000 dim IDLen,TypeLen, n, aLen, bLen as integer dim nOb, iobj, i, col as integer dim cat as APCatalog, ob as APCatalogObject dim hasMagnitude,hasSize,hasPosAngle as boolean dim fout as APTextFile dim s(4),theType,sz(-1),a,b as string SetPopupParameter("Catalogue to export",0,Catalogs) if not EditParameters("TheSky Catalogue Export") then return cat=GetCatalog(GetPopupParameter("Catalogue to export")+1) if cat=nil then Print "Could not find catalogue" return end if // Set up output file fout=WriteTextFile if fout=nil then return StartProgress("Examining catalogue",true,cat.nObjects) // Find what applicable data fields are available nOb=0 IDlen=0 TypeLen=0 theType="" hasMagnitude=false hasSize=false hasPosangle=false aLen=0 bLen=0 for iobj=1 to cat.nObjects if UpdateProgress(iobj) then return ob=cat.GetObject(iobj) IDlen=max(IDLen,len(ob.ID)) SplitID(ob.ID,a,b) aLen=max(aLen,len(a)) bLen=max(bLen,len(b)) Typelen=max(TypeLen,len(ob.Type)) if theType="" then theType=ob.Type if not hasMagnitude and ob.Magnitude>-2.0 and ob.Magnitude<30.0 then hasMagnitude=true if not hasSize and ob.Size<>"" then hasSize=true if not hasPosAngle and ob.PosAngle>0 then hasPosAngle=true nOb=nOb+1 // See if maximum number of required objects has been exceeded if maxObjects>0 and nOb>=maxObjects then if not YesNo("Too many objects in the catalogue. Only the first "+format(maxObjects,",0")+" will be exported. OK to continue?") then return exit end if next StopProgress StartProgress("Exporting catalogue",true,cat.nObjects) // Write preamble fout.WriteLine ">IDENTIFIER "+cat.Name fout.WriteLine ">CATALOG CLASS OBJECTS/POINTS" fout.WriteLine ">OBJECT TYPE "+str(GetType(theType)) fout.WriteLine ">RAHOURS 7,16" fout.WriteLine ">DECSIGN 18,18" fout.WriteLine ">DECDEGREES 19,27" fout.WriteLine ">ALIAS 29,"+str(28+IDLen) col=30+IDLen fout.WriteLine ">PARSE ""Obj Type"" "+str(col)+","+str(col+TypeLen-1) col=col+TypeLen+1 fout.WriteLine ">PARSE """+a+""" "+str(col)+","+str(col+bLen-1) fout.WriteLine ">SEARCH "+str(col)+","+str(col+bLen-1) col=col+bLen+1 if hasMagnitude then fout.WriteLine ">MAGNITUDE "+str(col)+","+str(col+4) col=col+6 s.Append "" end if if hasSize then fout.WriteLine ">MAJOR AXIS "+str(col)+","+str(col+4) col=col+6 s.Append "" fout.WriteLine ">MINOR AXIS "+str(col)+","+str(col+4) col=col+6 s.Append "" end if if hasPosAngle then fout.WriteLine ">POSITION ANGLE "+str(col)+","+str(col+2) col=col+4 s.Append "" end if // Cycle through all objects in the catalogue nOb=0 for iobj=1 to cat.nObjects if UpdateProgress(iobj) then exit ob=cat.GetObject(iobj) s(0)=FormatNumber(ob.RA,10) s(1)=FormatNumber(ob.Dec,10,true) s(2)=ob.ID while len(s(2))-2.0 and ob.Magnitude<30.0 then s(n)=FormatNumber(ob.Magnitude,5) else s(n)=" " end if n=n+1 end if if hasSize then if trim(ob.Size)<>"" then sz=Split(trim(ob.Size),"x") if ubound(sz)<0 then redim sz(1) sz(0)="0" sz(1)="0" elseif ubound(sz)=0 then sz.Append sz(0) end if if sz(0)="0" then s(n)=" " s(n+1)=" " else for i=0 to 1 s(n+i)=FormatNumber(CDbl(sz(i)),5) next end if else s(n)=" " s(n+1)=" " end if n=n+2 end if if hasPosAngle then if ob.PosAngle>0 then s(n)=format(ob.PosAngle,"000") else s(n)=" " end if n=n+1 end if a=format(iobj,"0") while len(a)<6 a=a+" " wend fout.WriteLine(a+Join(s," ")) nOb=nOb+1 // See if maximum number of required objects has been exceeded if maxObjects>0 and nOb>=maxObjects then exit next StopProgress fout.Close Bleep