APSF // Convert catalogue to Starry Night data file dim restrictToType, IDCode as string dim maxObjects, nOb, iobj, i as integer dim cat as APCatalog, ob as APCatalogObject dim doThis as boolean dim fout as APTextFile dim types(-1),s(6),obtypes(-1),catNumber,lastCatNumber as string SetPopupParameter("Catalogue",0,Catalogs) SetStringParameter("Restrict to Type","") SetCaptionParameter("(leave blank for all types)",1,true,false,false,true) SetIntegerParameter("Maximum objects to convert",0,0) SetCaptionParameter("(Use 0 for all objects)",1,true,false,false,true) if not EditParameters then return cat=GetCatalog(GetPopupParameter("Catalogue")+1) restrictToType=GetStringParameter("Restrict to Type") maxObjects=GetIntegerParameter("Maximum objects to convert") if cat=nil then Print "Could not find catalogue" return end if IDCode=cat.GetObject(1).ID if not IsNumeric(right(IDCode,1)) then Print "Primary ID must be numeric" return end if while IDCode<>"" and IsNumeric(right(IDCode,1)) IDCode=Left(IDCode,len(IDCode)-1) wend // Set up output file fout=WriteTextFile if fout=nil then return // Write preamble fout.WriteLine "HEADER"+chr(9)+"DataName"+chr(9)+cat.FileName fout.WriteLine "HEADER"+chr(9)+"Description"+chr(9)+cat.Name fout.WriteLine "HEADER"+chr(9)+"NumberOfObjects"+chr(9)+format(cat.nObjects,"0") fout.WriteLine "HEADER"+chr(9)+"UnknownMagnitude"+chr(9)+"10.0" fout.WriteLine "HEADER"+chr(9)+"DrawDepth"+chr(9)+"8000" fout.WriteLine "HEADER"+chr(9)+"CataloguePreamble"+chr(9)+"1"+chr(9)+IDCode types=cat.GetTypes for i=0 to ubound(types) fout.WriteLine "HEADER"+chr(9)+"KindName"+chr(9)+str(i)+chr(9)+types(i) next // Cycle through all objects in the catalogue nOb=0 for iobj=1 to cat.nObjects ob=cat.GetObject(iobj) doThis=true // Check for type restriction if restrictToType<>"" and instr(ob.Type,restrictToType)<=0 then doThis=false if doThis then catNumber=mid(ob.ID,len(IDCode)+1) if catNumber<>LastCatNumber then // Ignore duplicates s(0)=catNumber // Catalogue number s(1)="1" // Catalogue kind if ob.Magnitude>=30.0 then s(2)="" // No Magnitude else s(2)=str(ob.Magnitude) // Magnitude end if obtypes=ob.GetTypes s(3)=str(types.IndexOf(obtypes(0))) // Kind s(4)=format(ob.RA*15.0,"-0.000000") // RA (in degrees) s(5)=format(ob.Dec,"-0.000000") // Dec (in degrees) s(6)=left(ob.Name,30) // Name fout.WriteLine(Join(s,chr(9))) nOb=nOb+1 // See if maximum number of required objects has been exceeded if maxObjects>0 and nOb>=maxObjects then exit end if lastCatNumber=catNumber end if next fout.Close Bleep