APSF //- Import RTGUI data file //- //- Paul Rodman, Jan 2009 //- //- V1.0 13 jan 2009 //- Initial release function StartsWith(extends s as string, v as string) as boolean return left(s,len(v))=v end function function StringToDegrees(s as string) as double dim ss as string, i as integer, d,m as double ss=trim(s) ss=Replace(ss,"'","") for i = lenb(ss) downto 1 if midb(ss,i,1)<>" " and midb(ss,i,1)<>"-" and midb(ss,i,1)<>"+" and _ midb(ss,i,1)<>"." and not IsNumeric(midb(ss,i,1)) then ss=leftb(ss,i-1)+midb(ss,i+1) next d=val(NthField(ss," ",1)) m=val(NthField(ss," ",2)) if d<0.0 then return d-m/60.0 else return d+m/60.0 end if end function sub main() dim tf as APTextFile dim s,s2,fields(-1) as string dim ob as APPlanObject dim i as integer // Get file to import tf = ReadTextFile if tf=nil then return // Skip over heading lines while not tf.EOF s = trim(tf.ReadLine) if s="" then exit wend // Read data lines while not tf.EOF // Read an object's fields s = trim(tf.ReadLine) s2 = trim(tf.ReadLine) fields=split(s+s2,",") // Create a new object in the plan ob = NewObject ob.Notes="" // Fill in the fields // First field is number of object, followed by ID i=instr(fields(0),".") ob.ID=trim(mid(fields(0),i+1)) ob.Type="Star" fields.Remove 0 for i = ubound(fields) downto 0 s=trim(fields(i)) if s.StartsWith("R.A. =") then ob.RA=TimeToDouble(trim(mid(s,7))) fields.Remove i elseif s.StartsWith("Dec =") then ob.Dec=StringToDegrees(trim(mid(s,6))) fields.Remove i elseif s.StartsWith("Mag=") then ob.Magnitude=val(trim(mid(s,5))) fields.Remove i elseif s.StartsWith("Dbl ") then s=Replace(trim(mid(s,5)),"""","") ob.Separation=val(NthField(s," ",1)) ob.PosAngle=val(NthField(s," ",2)) ob.Type="Dbl" fields.Remove i elseif s="galaxy" or s="BrightNebula" or s="Open Cluster" or s="Globular" then ob.Type=s fields.Remove i elseif s.StartsWith("Alt=") or s.StartsWith("Az=") then fields.Remove i else if s="" then fields.Remove i else fields(i)=s end if next ob.Name = Join(fields,", ") wend tf.Close Bleep end sub main()