'
' Create Starry Night database from Landolt-gray.all standard data.
'
'  http://stupendous.rit.edu/tass/catalogs/landolt.all
'
' source of the position is encoded in the 's' field
'   A   USNO-A2.0  (I/252)
'   B   Bordeaux meridian circle  (2001A&A...376..325R, I/272)
'   C   Carlsberg meridian circle  (I/256)
'   c   CPC2  (1999AJ....117.2895Z, I/265)
'   G   GSC-ACT  (I/255)
'   g   GSC-2.2  (I/271)
'   H   Hipparcos  (1997A&A...323L..49P, I/239)
'   L   Lick NPM1  (1987AJ.....94..501K, I/199)
'   M   2MASS second release  (B/2mass/out)
'   T   Tycho-2  (2000A&A...357..367H, I/259)
'   U   UCAC1  (2000AJ....120.2131Z, I/268)
' 
' 0        1         2         3         4         5         6         7
' 123456789012345678901234567890123456789012345678901234567890123456789012345678
' ------------------------------------------------------------------------------
' SA 140-84       0 03 38.09 -28 41 47.0 U  6418-1076  CD-29 18942
' SA 140-85       0 03 38.51 -28 37 25.4 U  6418-0783  CD-29 18943
' HD 315          0 07 44.11 -02 32 55.2 T  4666-0548  HD 315       NSV 15027
' T Phe A         0 30 09.59 -46 31 28.9 U  8024-0394
' T Phe B         0 30 16.31 -46 27 58.6 U  8024-0363  CD-47 128    RW Phe
' T Phe C         0 30 16.98 -46 32 21.5 U  8024-0400
' T Phe D     *   0 30 18.34 -46 31 19.8 U  8024-0677
' T Phe E         0 30 19.77 -46 24 35.6 U  8024-0755  
' T Phe F         0 30 49.82 -46 33 24.1 U  8024-0830               NSV 184
' PG 1530+057B   15 33 17.46 +05 33 46.3 g  0358-0997
' SA 107-298     15 36 33.71 -00 33 41.5 T  5016-0787  HD 139137
' SA 107-544     15 36 48.10 -00 15 07.1 T  5016-0561  HD 139197
' SA 107-684     15 37 18.15 -00 09 49.7 T  5016-0518  HD 139287
' SA 107-969     15 37 25.58 +00 15 46.9 F  0350-0772             
' SA 107-970  *  15 37 25.83 +00 18 33.8 F  0350-0676               NSV 20355
' SA 113-276     21 42 27.45 +00 26 20.4 T  0543-1595  BD-00 4251s  AG+00 2733
'
'  Field          Columns
'  -----------    -------
'  Name            1-12
'  RA (J2K deg)   16-26
'  Dec (J2K deg)  28-38
'  Source         40
'  GSC Number     43-51
'  HD/DM          54-64
'  Remarks        67-...
'
Option Explicit

Const ROOT = "E:\StarryNight Catalogs\Landolt Names and Markers\"
Dim FSO, TB, LF, SF, U, Buf, Name, LL, CatNum, Mag

'
' Translate source code into human-readable String
'
Function TransSource(Code)
	Select Case Code
		Case "A": TransSource = "USNO-A2.0"
		Case "B": TransSource = "Bordeaux mer cir"
		Case "C": TransSource = "Carlsberg mer cir"
		Case "c": TransSource = "CPC2"
		Case "G": TransSource = "GSC-ACT"
		Case "g": TransSource = "GSC-2.2"
		Case "H": TransSource = "Hipparcos"
		Case "L": TransSource = "Lick NPM1"
		Case "M": TransSource = "2MASS R2"
		Case "T": TransSource = "Tycho-2"
		Case "U": TransSource = "UCAC1"
		Case Else: TransSource = "Unk"
	End Select
End Function

TB = Chr(9)								' Tab for delimiter

'
' Convert magnitude - 99.0 -> ""
' Return string for catalog
'
Function ConvMag(Raw)
	If CDbl(Raw) = 99.0 Then
		ConvMag = ""
	Else
		ConvMag = Raw
	End If
End Function

'
' MAIN PROGRAM
'
Set FSO = CreateObject("Scripting.FileSystemObject")
Set U = CreateObject("DriverHelper.Util")


Set LF = FSO.OpenTextFile(ROOT & "landolt-gray.all.txt")
Set SF = FSO.CreateTextFile(ROOT & "landolt-sn-in.txt")

' WARNING! Watch it, there are tabs in these strings!
SF.WriteLine "//	Revision 1 20-May-2005 (R. B. Denny)"
SF.WriteLine "HEADER	DataName	Landolt"
SF.WriteLine "// Stars group"
SF.WriteLine "HEADER	OptionsGroup	3000"
SF.WriteLine "HEADER	Description	Landolt standard stars with V magnitudes for Starry Night plotting. (R.B. Denny 20-May-2005)"
SF.WriteLine "HEADER	NumberOfObjects	1154"
SF.WriteLine "HEADER	DrawDepth	8600"
SF.WriteLine "HEADER	CataloguePreamble	1	Landolt"
SF.WriteLine "HEADER	KindName	4	Landolt Standard"
SF.WriteLine "HEADER	KindColour	4	1.0	0.0	0.0"
SF.WriteLine "HEADER	AuxillaryLabel	1	Source"
SF.WriteLine "HEADER	AuxillaryLabel	2	GSC #"
SF.WriteLine "HEADER	AuxillaryLabel	3	HD/DM"
SF.WriteLine "HEADER	AuxillaryLabel	4	Remarks"
SF.WriteLine "HEADER	AuxillaryLabel	5	."
SF.WriteLine "HEADER	AuxillaryLabel	6	."
SF.WriteLine "HEADER	AuxillaryLabel	7	."
SF.WriteLine "HEADER	AuxillaryLabel	8	."
SF.WriteLine "// (rbd - added this key)"
SF.WriteLine "//  Cat# CatKind VMag Kind RA-J2K Dec-J2K Name Src GSC# HD/DM Remarks"
SF.WriteLine "//  -----------------------------------------------------------------"

CatNum = 1
Do While Not LF.AtEndOfStream
	Buf = LF.ReadLine											' Read a line of LONEOS
	LL = Len(Buf)												' Length for tests
	If LL > 146 And Left(Buf, 1) <> "#" Then					' Take only records with Henden mags
		Name = Trim(Mid(Buf, 1, 12))
		SF.Write CatNum & TB & "1" & TB							' Write Cat# and Catkind
		SF.Write Trim(Mid(Buf, 147, 6)) & TB					' Write 0.0 for mag
		SF.Write "4" & TB										' Write Kind (4)
		SF.Write U.HMSToDegrees(Trim(Mid(Buf, 16, 11))) & TB	' Write RA
		SF.Write U.DMSToDegrees(Trim(Mid(Buf, 28, 11))) & TB	' Write Dec
		SF.Write Name & TB										' Write Name (again)
		SF.Write TransSource(Trim(Mid(Buf, 40, 1))) & TB		' Translated source
		If LL > 42 Then SF.Write Trim(Mid(Buf, 43, 9))			' GSC number
		SF.Write TB
		If LL > 53 Then SF.Write Trim(Mid(Buf, 54, 11))			' HD/DM
		SF.Write TB
		If LL > 66 Then SF.Write Trim(Mid(Buf, 67, 11))			' Remarks
		SF.Write VbCrLf
		CatNum = CatNum + 1
	End If
Loop
LF.Close
SF.Close


	
	
	
	
	
