'
' Convert a target list from CALL into a Starry Night asteroids.txt file.
'
Const ROOT = "E:\StarryNight Catalogs\CALL Targets\"
Const CFile = "Q2-Q3-2005.txt"

Dim FSO, F, SF, Buf, LBuf, ANums(), I, ACount

Set FSO = CreateObject("Scripting.FileSystemObject")
Set F = FSO.OpenTextFile(ROOT & CFile)
'
' Create array of minor planet numbers
'
ReDim ANums(50)
ACount = 0
Do While Not F.AtEndOfStream
	If ACount = UBound(ANums) Then ReDim Preserve ANums(ACount + 50)
	ANums(ACount) = CLng(Trim(Left(F.ReadLine(), 6)))
	ACount = ACount + 1
Loop
F.Close
'
' Scan through astorb.dat and extract the lines whose numbers
' match those in the array.
'
' WARNING! ASTORB.DAT has numbers up to 99999 only! Eventually this
' will have to be modified to match the name!
'
Set F = FSO.OpenTextFile(ROOT & "astorb.dat")
Set SF = FSO.CreateTextFile(ROOT & "Asteroids-CALL.txt", True)
Do While Not F.AtEndOfStream
	LBuf = F.ReadLine()
	Buf = Trim(Left(LBuf, 5))
	If Buf = "" Then Exit Do	' Ran out of numbered MPs
	For I = 0 To ACount - 1
		If CLng(Buf) = ANums(I) Then SF.WriteLine LBuf
	Next
Loop
F.Close
SF.Close
