APSF //- Imports SkyTools 3 observations. Optionally creates any site and telescope resources referenced, //- creates an object in the open plan for each observaed observation, and then creates observations //- corresponding to the SkyTools observations. //- //- Requires that you save your ST3 observations as a tab-separated text file: //- //- delimiter character: commas tabs pipes colons semicolons {drop down box} (select "tabs") //- //- select log entries: //- Matching log entries in browser object lists //- All object log entries in database //- all objects in this observing list {two drop down fields} //- //- Fields to export: {check boxes} //- Date/Time //- Observer //- Location //- Instrument //- Object Data //- Conditions //- Description //- //- //- Paul Rodman, January 2009 //- //- V1.0 25 Jan 2009 //- Initial release. function GetNewResources(existing() as APResource, all() as string) as string() // Get list of all used resources that don't already exist dim used(-1) as string, i,j as integer, found as boolean for i=0 to ubound(all) if used.IndexOf(all(i))<0 then found=false for j=0 to ubound(existing) if existing(j).Name=all(i) then found=true exit end if next if not found then used.Append all(i) end if next used.Sort return used end function function DecodeRA(sRA as string) as double // Decode RA of the form: //10h16m45.5s return val(left(sRA,2))+val(mid(sRA,4,2))/60.0+val(mid(sRA,7,4))/3600.0 end function function DecodeDec(sDec as string) as double // Decode Dec of the form: //+28∞05'15" dim v as double v=val(mid(sDec,2,2))+val(mid(sDec,5,2))/60.0+val(mid(sDec,8,4))/3600.0 if left(sDec,1)="-" then v=-v return v end function dim months(11) as string function DecodeDateTime(s as string) as double // Decode date of the form //2003 December 27 21:24 dim y,m,d,h,mn as integer y=val(NthField(s," ",1)) m=months.IndexOf(NthField(s," ",2))+1 d=val(NthField(s," ",3)) h=val(NthField(NthField(s," ",4),":",1)) mn=val(NthField(NthField(s," ",4),":",2)) return MakeDate(y,m,d)+(h+mn/60-12)*3600.0 end function sub main() dim f as APTextFile dim fields(-1),used(-1),objs(-1) as string dim existing(-1) as APResource dim id(-1),dt(-1),observer(-1),site(-1),scope(-1),objtype(-1),ra(-1),dec(-1),conditions(-1),description(-1) as string dim i,j,oblist(-1) as integer dim found as boolean dim ob as APPlanObject, obs as APObservation months(0)="January" months(1)="February" months(2)="March" months(3)="April" months(4)="May" months(5)="June" months(6)="July" months(7)="August" months(8)="September" months(9)="October" months(10)="November" months(11)="December" // Read the data f=ReadTextFile if f=nil then return while not f.EOF fields=Split(f.ReadLine,chr(9)) id.Append ReplaceAll(fields(0)," ","") dt.Append fields(1) observer.Append fields(2) site.Append trim(fields(3)) scope.Append trim(fields(4)) objtype.Append trim(fields(5)) ra.Append trim(fields(6)) dec.Append trim(fields(7)) conditions.Append trim(fields(11)) description.Append trim(fields(12)) wend f.Close // Extract the site information used=GetNewResources(Sites,site) if ubound(used)>=0 then if YesNo("The following Site resources are new:"+EndOfLine+EndOfLine+Join(used,EndofLine)+EndofLine+EndOfLine+ _ "Although it's not strictly required, would you like to create new Site resources with these names?") then for i=0 to ubound(used) call NewSite(used(i)) next Print "Remember: You'll need to set up appropriate latitudes, longitudes, etc. for those site resources later" end if end if // Extract the telescope information used=GetNewResources(Telescopes,scope) if ubound(used)>=0 then if YesNo("The following Telescope resources are new:"+EndOfLine+EndOfLine+Join(used,EndofLine)+EndofLine+EndOfLine+ _ "Although it's not strictly required, would you like to create new Telescope resources with these names?") then for i=0 to ubound(used) call NewTelescope(used(i)) next Print "Remember: You'll need to set up appropriate apertures, etc. for those telescope resources later" end if end if // Set up objects for all those observed for i=1 to nObjects objs.Append Obj(i).ID next for i=0 to ubound(id) if objs.IndexOf(id(i))<0 then objs.Append id(i) oblist.Append i end if next if YesNo("Import "+format(ubound(oblist)+1,",0")+" referenced objects into the current plan document?") then StartProgress("Importing "+format(ubound(oblist)+1,",0")+" objects to the plan. This might take a while...",true,ubound(oblist)) for j=0 to ubound(oblist) if UpdateProgress(j) then return ob = NewObject i=oblist(j) ob.ID=id(i) ob.RA=DecodeRA(ra(i)) ob.Dec=DecodeDec(dec(i)) ob.Type=objtype(i) next StopProgress end if if YesNo("Import "+format(ubound(id)+1,",0")+" observations into the current plan document? (WARNING: Do not do this more than once, or you'll have duplicate observations!)") then StartProgress("Importing "+format(ubound(id)+1,",0")+" observations to the plan. This might take a while...",true,ubound(id)) for j=0 to ubound(id) if UpdateProgress(j) then return for i=1 to nObjects if Obj(i).ID=id(j) then obs=Obj(i).NewObservation(DecodeDateTime(dt(j))) obs.Site=site(j) obs.Telescope=scope(j) redim fields(-1) if description(j)<>"" then fields.Append description(j) if observer(j)<>"" then fields.Append "Observer: "+observer(j) if conditions(j)<>"" then fields.Append "Conditions: "+conditions(j) obs.Notes=Join(fields,EndofLine) end if next next StopProgress end if end sub main