'SIDERAL.BAS converts date, time, time zone, longitude into local sidereal
' time.  This will be help point an alt-az scope when RA/Dec. conversion to
' alt/az has been done.

tapelength10 = 52.3622      'length of tape measure loop for 10 inch scope!
tapelength16 = 71.06299        'length of tape measure loop for 16 inch scope!
pi = 3.141593                'NOTE!  trig functions must be in radians!
tgt$ = "NO TARGET CHOSEN!"   'initial value to alert user that no tgt selected
declutter$ = "OFF"           'value toggles between ON and OFF to supress
zshift = 0
                             '   or display extra screen information
clock$ = "RUN"               'initial value of RUN  other value is FREEZE
                             '   used with motorized equatorial platform
clockshift = 0               'if using platform, clockshift will take into
                             '   account any rotation/shift of the platform
                             '   by means of an elapsed time shift, in hours

DIM month(12)
month(1) = 31      'days in month of jan
month(2) = 28      'feb ...ignoring leap years
month(3) = 31      'mar
month(4) = 30      'apr
month(5) = 31      'may
month(6) = 30      'jun
month(7) = 31      'jul
month(8) = 31      'aug
month(9) = 30      'sep
month(10) = 31      'oct
month(11) = 30      'nov
month(12) = 31      'dec

colornum = 4                                   'default/initial color

SCREEN 12                                       'BIG letters for night viewing
COLOR colornum                                  'use default color
49 CLS
PRINT
PRINT
PRINT "Do you want brighter letters? <y/n>"
ans$ = UCASE$(INPUT$(1))
IF ans$ = "Y" THEN GOSUB 100000                 'choose other letter color

50 PRINT
PRINT
PRINT " What scope are you using?"
PRINT
PRINT
PRINT "   1.  Donetello"
PRINT
PRINT "   2.  8 inch"
PRINT
scopesize = VAL(INPUT$(1))
IF (scopesize < 1) OR (scopesize > 2) THEN
    CLS
  GOTO 50
ELSE
  IF scopesize = 1 THEN
    tapelength = tapelength16

  ELSE
    tapelength = tapelength10
  END IF
END IF

CLS
100 PRINT
PRINT
PRINT " System date is: "; DATE$
PRINT
PRINT " Do you want to change this? <Y/N>";
ans$ = UCASE$(INPUT$(1))

IF ans$ = "N" OR ans$ = "Y" THEN  ELSE BEEP: GOTO 100
IF ans$ = "Y" THEN GOSUB 10000 ELSE

CLS
200 PRINT
PRINT
PRINT " LOCAL time is: "; TIME$
PRINT
PRINT " Do you want to change this? <Y/N>";
ans$ = UCASE$(INPUT$(1))

IF ans$ = "N" OR ans$ = "Y" THEN  ELSE BEEP: GOTO 200
IF ans$ = "Y" THEN GOSUB 11000 ELSE

starttime = TIMER

IF VAL(MID$(DATE$, 1, 2)) > 3 AND VAL(MID$(DATE$, 1, 2)) < 11 THEN
timezoneshift = 4                    'this is for daylight savings EST
ELSE
timezoneshift = 5                   'this is for standard daylight time EST
END IF

CLS
300 PRINT
PRINT
PRINT " UT is "; timezoneshift; " hours ahead of local time"
PRINT
PRINT "    Is this correct? <Y/N>";
ans$ = UCASE$(INPUT$(1))

IF ans$ = "N" OR ans$ = "Y" THEN  ELSE BEEP: GOTO 300
IF ans$ <> "Y" THEN GOSUB 12000 ELSE

PRINT
PRINT
nowtime$ = TIME$
nowhour = VAL(MID$(nowtime$, 1, 2))
nowmin = VAL(MID$(nowtime$, 4, 2))
nowsec = VAL(MID$(nowtime$, 7, 2))

nowdate$ = DATE$
nowmonth = VAL(MID$(nowdate$, 1, 2))
nowday = VAL(MID$(nowdate$, 4, 2))
nowyear = VAL(MID$(nowdate$, 9, 2))

nowhour = nowhour + timezoneshift
IF nowhour > 23 THEN
nowday = nowday + 1
nowhour = nowhour + 24
ELSE
END IF

GOSUB 13000      'calculate days since sidereal new year

nowdayfraction = nowhour / 24 + nowmin / (24 * 60)

dayfractiondiff = nowdayfraction - startdayfraction
daydiff = daydiff + dayfractiondiff

siderealshift = daydiff * .0657084     'shift (in hours) to add to local time

DO WHILE siderealshift >= 24
siderealshift = siderealshift - 24
LOOP

PRINT
PRINT
PRINT " (Optional) Define north point. . ."
PRINT
INPUT " Reading in INCHES"; inches
INPUT " Reading in 1/16ths"; sixteenths

scaleshift = inches + sixteenths / 16

GOSUB 14000                     'get latitude and longitude

nowtime$ = TIME$
nowhour = VAL(MID$(nowtime$, 1, 2))
nowmin = VAL(MID$(nowtime$, 4, 2))
nowsec = VAL(MID$(nowtime$, 7, 2))

nowhourdecimal = nowhour + nowmin / 60 + nowsec / 3600
localsiderealtime = nowhourdecimal + siderealshift - longitudetimeshift + timezoneshift

DO WHILE localsiderealtime >= 24
localsiderealtime = localsiderealtime - 24
LOOP
   
DO WHILE localsiderealtime < 0
localsiderealtime = localsiderealtime + 24
LOOP

localsiderealhour = FIX(localsiderealtime)
siderealremainder = localsiderealtime - localsiderealhour
localsiderealmin = FIX(60 * siderealremainder)
siderealremainder = 60 * siderealremainder - localsiderealmin
localsiderealsec = FIX(.5 + (60 * siderealremainder))

IF localsiderealsec >= 60 THEN
localsiderealmin = localsiderealmin + 1
localsiderealsec = localsiderealsec - 60
ELSE
END IF

IF localsiderealmin >= 60 THEN
localsiderealhour = localsiderealhour + 1
localsiderealmin = localsiderealmin - 60
ELSE
END IF

DO WHILE localsiderealhour >= 24
localsiderealhour = localsiderealhour - 24
LOOP

GOSUB 20000                                    'display hot key menu

ans$ = " "                     'load dummy variable to start processing loop
DO WHILE ans$ <> "X"                       'main processing loop!

 IF clock$ = "RUN" THEN eltime = TIMER - starttime ELSE

 IF eltime < 0 THEN eltime = eltime + 86400 ELSE
 elhours = eltime / 3600        'convert to hours from seconds of elapsed time
 elhours = elhours * 1.002738      'sidereal elapsed time is fast by 1.002738
 elapsedsiderealtime = localsiderealtime + elhours + clockshift  'add elapsed time
 IF elapsedsiderealtime < 0 THEN elapsedsiderealtime = elapsedsiderealtime + 24 ELSE

 SELECT CASE ans$

   CASE "D"
     CLS
     IF declutter$ = "OFF" THEN
        declutter$ = "ON"
     ELSE
        declutter$ = "OFF"
     END IF

   CASE "M"
     GOSUB 20000

   CASE "T"
     GOSUB 30000                    'GET TARGET COORDS
     CLS
     GOSUB 49000                    'print text screen template
     GOSUB 50000                    'convert to alt az

   CASE "B"
     GOSUB 60000                    'Bright Star alignment

   CASE "A"
     GOSUB 70000                    ' Azimuth calibration shift/adjust

   CASE "E"
     GOSUB 80000                    ' Elevation Calibration shift/adjust

   CASE "L"
     GOSUB 90000                    ' Load initialization/calibration file

   CASE "S"
     GOSUB 91000                    ' Save initialization/calibration file

   CASE "C"
     GOSUB 100000                   ' Change display color

   CASE "F"
     IF clock$ = "RUN" THEN clock$ = "FREEZE" ELSE clock$ = "RUN"

   CASE "P"
     GOSUB 110000                   ' Platform shift value

   CASE "Z"
     GOSUB 120000                   ' Legend of terms in object description

 END SELECT

 GOSUB 49000                    'print text screen template
 GOSUB 50000                    'convert to alt az
 ans$ = UCASE$(INKEY$)
LOOP                                   'end of main processing loop!

SYSTEM                                  '<<<<<<<<<<<<<<<<<<<<<end of main module

10000                                                     'change system date

CLS
PRINT
PRINT
INPUT " Enter new date mm-dd-yy "; newdate$
PRINT
PRINT " New date will be "; newdate$
PRINT
PRINT " Is this correct <Y/N>";
ans$ = UCASE$(INPUT$(1))

IF ans$ <> "Y" THEN 10000 ELSE

DATE$ = newdate$

RETURN       'change system date


11000        'change system time

CLS
PRINT
INPUT " Enter new time HH:MM:SS "; newtime$
PRINT
PRINT " New time will be "; newtime$
PRINT
PRINT " Is this correct <Y/N>";
ans$ = UCASE$(INPUT$(1))

IF ans$ <> "Y" THEN 11000 ELSE
TIME$ = newtime$

newhour = VAL(MID$(newtime$, 1, 2))
newmin = VAL(MID$(newtime$, 4, 2))
newsec = VAL(MID$(newtime$, 7, 2))
newhourdecimal = newhour + newmin / 60 + newsec / 3600

RETURN       'change system time

12000        'change UT / time zone correction
CLS
PRINT
INPUT " Enter new time shift"; timezoneshift
PRINT
PRINT " Time shift will be "; timezoneshift
PRINT
PRINT " Is this correct <Y/N>";
ans$ = UCASE$(INPUT$(1))

IF ans$ <> "Y" THEN 12000 ELSE

RETURN       'change UT / time zone correction

13000        'calculate days since sideral "new year"
'future sidereal new years (should update the value of startdate$
' to match the current year. . . .)
' New year for 1998:   09-21-1998 at UTC 08:00
' New year for 1999:   09-21-1999 at UTC 13:50
' New year for 2000:   09-20-2000 at UTC 19:40
' New year for 2001:   09-21-2001 at UTC 01:20
' New year for 2002:   09-21-2002 at UTC 07:13
' New year for 2003:   09-21-2003 at UTC 13:00
' New year for 2004:   09-20-2004 at UTC 18:44
' New year for 2005:   09-21-2005 at UTC 00:34
' New year for 2006:   09-21-2006 at UTC 06:28

systemyear = VAL(RIGHT$(DATE$, 2))
systemmonth = VAL(LEFT$(DATE$, 2))
systemday = VAL(MID$(DATE$, 4, 2))
IF systemmonth <= 8 THEN systemyear = systemyear - 1 ELSE
IF (systemmonth = 9) AND (systemday <= 22) THEN systemyear = systemyear - 1 ELSE

SELECT CASE systemyear
 CASE 98
   startdate$ = "09-21-1998"
   starttime$ = "08:00:00"
 CASE 99
   startdate$ = "09-21-1999"
   starttime$ = "13:50:00"
 CASE 0
   startdate$ = "09-20-2000"
   starttime$ = "19:40:00"
 CASE 1
   startdate$ = "09-21-2001"
   starttime$ = "01:20:00"
 CASE 2
   startdate$ = "09-21-2002"
   starttime$ = "07:13:00"
 CASE 3
   startdate$ = "09-21-2003"
   starttime$ = "13:00:00"
 CASE 4
   startdate$ = "09-20-2004"
   starttime$ = "18:44:00"
 CASE 5
   startdate$ = "09-21-2005"
   starttime$ = "00:34:00"
 CASE 6
   startdate$ = "09-21-2006"
   starttime$ = "06:28:00"
 CASE ELSE
   BEEP
   BEEP
   CLS
   PRINT "  Need to update system calculations of sidereal new year!"
   PRINT
   PRINT "    Press any key. . . . . ."
   dummy$ = INPUT$(1)
END SELECT

startmonth$ = MID$(startdate$, 1, 2)
startday$ = MID$(startdate$, 4, 2)
startyear$ = MID$(startdate$, 9, 2)

startmonth = VAL(startmonth$)
startday = VAL(startday$)
startyear = VAL(startyear$)

starthour$ = MID$(starttime$, 1, 2)
startmin$ = MID$(starttime$, 4, 2)
startsec$ = MID$(starttime$, 7, 2)

starthour = VAL(starthour$)
startmin = VAL(startmin$)
startsec = VAL(startsec$)

startdayfraction = starthour / 24 + startmin / (24 * 60)

yeardiff = nowyear - startyear
monthdiff = nowmonth - startmonth
daydiff = nowday - startday

DO WHILE yeardiff > 0
monthdiff = monthdiff + 12
yeardiff = yeardiff - 1
LOOP

monthcounter = 9

DO WHILE monthdiff > 0
daydiff = daydiff + month(monthcounter)
monthcounter = monthcounter MOD 12
monthcounter = monthcounter + 1
monthdiff = monthdiff - 1
LOOP

RETURN             'calculate days since sideral "new year"

14000                             'get latitude and longitude
CLS
PRINT
PRINT " Observing site coordinates:"
PRINT
PRINT " 1. Groveland MA"
PRINT
PRINT " 2. Home"
PRINT
PRINT " 3. E. Killingly CT"
PRINT
PRINT " 4. Conway NH"
PRINT
PRINT " 5. User Defined"
PRINT
PRINT "Make a selection. . ."
ans = VAL(INPUT$(1))
PRINT

SELECT CASE ans

CASE 1            'Groveland  
latdeg = 42
latmin = 73
longdeg = -71
longmin = -4

CASE 2            'Home
latdeg = 42
latmin = 56
longdeg = -71
longmin = -4

CASE 3            'E. Killingly
latdeg = 41
latmin = 84
longdeg = -71
longmin = -79

CASE 4            'Conway
latdeg = 43
latmin = 96
longdeg = -71
longmin = -9

CASE 5            'User defined
14500 PRINT
INPUT "  Latitude Degrees:"; latdeg
INPUT "  Latitude Minutes:"; latmin
PRINT
PRINT
INPUT " Longitude Degrees:"; longdeg
INPUT " Longitude Minutes:"; longmin
PRINT
PRINT "Is this correct?"
ans$ = UCASE$(INPUT$(1))

IF ans$ = "N" OR ans$ = "Y" THEN  ELSE BEEP: GOTO 14500
IF ans$ = "N" THEN GOTO 14500 ELSE

CASE ELSE
BEEP: GOTO 14000

END SELECT

latitude = latdeg + latmin / 60
longitude = longdeg + longmin / 60
longitudetimeshift = longdeg / 15 + longmin / 900     'time shift in hours

RETURN                            'get latitude and longitude


20000                     '<<<<<<<<<<<<<<<<<hot key menu display routine
CLS
PRINT " HOT KEY MENU OPTIONS"
PRINT
PRINT " B Bright star align"
PRINT " D Screen declutter toggle"
PRINT " M Hot key menu display"
PRINT " A Azimuth Calibration/shift"
PRINT " E Elevation Calibration/shift"
PRINT " S Save calibration/alignment"
PRINT " L Load calibration/alignment"
PRINT " P Eq. platform shift value"
PRINT " F Freeze/Run elapsed timer"
PRINT " T Select target"
PRINT " C Change Display Color"
PRINT " Z Legend of terms"
PRINT " X Exit program"
PRINT
PRINT "Press any key. . . . . . . . . .";
dummy$ = INPUT$(1)
CLS
RETURN

30000                             '<<<<<<<<<<database target select routine
DBASETARGET:                      'LABEL NAME FOR GOTO/OBJECT NAME NOT FOUND
CLS
PRINT " Object name formats:"
PRINT
PRINT " 3C       XXX          Ngc0XXX..Ngc7XXX"
PRINT " ABell    XXXX         PAl     XX"
PRINT " BaRnard  XXX          PIsmis  XX"
PRINT " BAsel    XX           PK      XXX-XX.X"
PRINT " BErk     XXX          RU      XXX"
PRINT " BOchum   XX           SH      X-XXX"
PRINT " CEd      XXX          SL      XX"
PRINT " CR       XXX          STock   XX"
PRINT " CZernik  XX           TEr     XX"
PRINT " DO       XX           TR      XX"
PRINT " DoDz     XX           UGc     XXXXX"
PRINT " HAffner  XX           Vdb-Ha  XXX"
PRINT " IC       XXXX         VDb     XXX"
PRINT " KIng     XX"
PRINT " LDn      XXXX         SS AA (yy/mm/dd)"
PRINT " MCg     -XX-XX-XXX"
PRINT " MeL      XXX"
PRINT " ME1, ME99, ME109 (Messier)"
PRINT " "
PRINT " XX..... (User defined)"
PRINT
LINE INPUT ; " Object name:"; obj$
obj$ = UCASE$(obj$)
objlen = LEN(obj$)
IF objlen < 2 THEN 30000 ELSE

tgtfile$ = "notdefined"     'flag value to see if first CASE sets the variable

choose1$ = MID$(obj$, 1, 1)
choose2$ = MID$(obj$, 1, 2)

SELECT CASE choose2$
CASE "N0"
  tgtfile$ = "c:\MG-III\ngc0.CSV"
  obj$ = "NGC 0" + RIGHT$(obj$, objlen - 2)
CASE "N1"
  tgtfile$ = "c:\MG-III\ngc1.CSV"
  obj$ = "NGC 1" + RIGHT$(obj$, objlen - 2)
CASE "N2"
  tgtfile$ = "c:\MG-III\ngc2.CSV"
  obj$ = "NGC 2" + RIGHT$(obj$, objlen - 2)
CASE "N3"
  tgtfile$ = "c:\MG-III\ngc3.CSV"
  obj$ = "NGC 3" + RIGHT$(obj$, objlen - 2)
CASE "N4"
  tgtfile$ = "c:\MG-III\ngc4.CSV"
  obj$ = "NGC 4" + RIGHT$(obj$, objlen - 2)
CASE "N5"
  tgtfile$ = "c:\MG-III\ngc5.CSV"
  obj$ = "NGC 5" + RIGHT$(obj$, objlen - 2)
CASE "N6"
  tgtfile$ = "c:\MG-III\ngc6.CSV"
  obj$ = "NGC 6" + RIGHT$(obj$, objlen - 2)
CASE "N7"
  tgtfile$ = "c:\MG-III\ngc7.CSV"
  obj$ = "NGC 7" + RIGHT$(obj$, objlen - 2)
CASE "ME"
  tgtfile$ = "c:\MG-III\MESSIER.CSV"
  obj$ = "M" + RIGHT$(obj$, objlen - 2)
CASE "IC"
  tgtfile$ = "c:\MG-III\IC.CSV"
  obj$ = "IC " + RIGHT$(obj$, objlen - 2)
CASE "3C"
  tgtfile$ = "c:\MG-III\3C.CSV"
  obj$ = "3C " + RIGHT$(obj$, objlen - 2)
CASE "AB"
  tgtfile$ = "c:\MG-III\ABELL.CSV"
  obj$ = "ABELL " + RIGHT$(obj$, objlen - 2)
CASE "BR"
  tgtfile$ = "c:\MG-III\BARNARD.CSV"
  obj$ = "B " + RIGHT$(obj$, objlen - 2)
CASE "BA"
  tgtfile$ = "c:\MG-III\BASEL.CSV"
  obj$ = "BASEL " + RIGHT$(obj$, objlen - 2)
CASE "BE"
  tgtfile$ = "c:\MG-III\BERK.CSV"
  obj$ = "BERK " + RIGHT$(obj$, objlen - 2)
CASE "BO"
  tgtfile$ = "c:\MG-III\BOCHUM.CSV"
  obj$ = "BOCHUM " + RIGHT$(obj$, objlen - 2)
CASE "CE"
  tgtfile$ = "c:\MG-III\CED.CSV"
  obj$ = "CED " + RIGHT$(obj$, objlen - 2)
CASE "CR"
  tgtfile$ = "c:\MG-III\CR.CSV"
  obj$ = "CR " + RIGHT$(obj$, objlen - 2)
CASE "CZ"
  tgtfile$ = "c:\MG-III\CZERNIK.CSV"
  obj$ = "CZERNIK " + RIGHT$(obj$, objlen - 2)
CASE "DO"
  tgtfile$ = "c:\MG-III\DO.CSV"
  obj$ = "DO " + RIGHT$(obj$, objlen - 2)
CASE "DD"
  tgtfile$ = "c:\MG-III\DODZ.CSV"
  obj$ = "DODZ " + RIGHT$(obj$, objlen - 2)
CASE "HA"
  tgtfile$ = "c:\MG-III\HAFFNER.CSV"
  obj$ = "HAFFNER " + RIGHT$(obj$, objlen - 2)
CASE "KI"
  tgtfile$ = "c:\MG-III\KING.CSV"
  obj$ = "KING " + RIGHT$(obj$, objlen - 2)
CASE "LD"
  tgtfile$ = "c:\MG-III\LDN.CSV"
  obj$ = "LDN " + RIGHT$(obj$, objlen - 2)
CASE "MC"
  tgtfile$ = "c:\MG-III\MCG.CSV"
  obj$ = "MCG " + RIGHT$(obj$, objlen - 2)
CASE "ML"
  tgtfile$ = "c:\MG-III\MEL.CSV"
  obj$ = "MEL " + RIGHT$(obj$, objlen - 2)
CASE "PA"
  tgtfile$ = "c:\MG-III\PAL.CSV"
  obj$ = "PAL " + RIGHT$(obj$, objlen - 2)
CASE "PI"
  tgtfile$ = "c:\MG-III\PISMIS.CSV"
  obj$ = "PISMIS " + RIGHT$(obj$, objlen - 2)
CASE "PK"
  tgtfile$ = "c:\MG-III\PK.CSV"
  obj$ = "PK " + RIGHT$(obj$, objlen - 2)
CASE "RU"
  tgtfile$ = "c:\MG-III\RU.CSV"
  obj$ = "RU " + RIGHT$(obj$, objlen - 2)
CASE "SH"
  tgtfile$ = "c:\MG-III\SH.CSV"
  obj$ = "SH " + RIGHT$(obj$, objlen - 2)
CASE "SL"
  tgtfile$ = "c:\MG-III\SL.CSV"
  obj$ = "SL " + RIGHT$(obj$, objlen - 2)
CASE "ST"
  tgtfile$ = "c:\MG-III\STOCK.CSV"
  obj$ = "STOCK " + RIGHT$(obj$, objlen - 2)
CASE "TE"
  tgtfile$ = "c:\MG-III\TER.CSV"
  obj$ = "TER " + RIGHT$(obj$, objlen - 2)
CASE "TR"
  tgtfile$ = "c:\MG-III\TR.CSV"
  obj$ = "TR " + RIGHT$(obj$, objlen - 2)
CASE "UG"
  tgtfile$ = "c:\MG-III\UGC.CSV"
  obj$ = "UGC " + RIGHT$(obj$, objlen - 2)
CASE "VH"
  tgtfile$ = "c:\MG-III\VDB-HA.CSV"
  obj$ = "VDB-HA " + RIGHT$(obj$, objlen - 2)
CASE "VD"
  tgtfile$ = "c:\MG-III\VDB.CSV"
  obj$ = "VDB " + RIGHT$(obj$, objlen - 2)
CASE "SS"
   tgtfile$ = "c:\MG-III\SOLAR.CSV"
   obj$ = RIGHT$(obj$, objlen - 2)
   obj$ = obj$ + MID$(DATE$, 9, 2) + "/"    'add year to text string
   obj$ = obj$ + MID$(DATE$, 1, 2) + "/"    'add month to text string
   obj$ = obj$ + MID$(DATE$, 4, 2)          'add day to text string
CASE ELSE
  'do nothing
END SELECT

IF tgtfile$ = "notdefined" THEN

  SELECT CASE choose1$
  CASE "X"
    tgt$ = obj$
    GOSUB 40000    'get user defined target routine
    RETURN
  CASE ELSE
    tgtfile$ = "c:\MG-III\5magstar.CSV"
  END SELECT
ELSE
  'do nothing
END IF

OPEN tgtfile$ FOR INPUT AS #2
DO WHILE (NOT (EOF(2))) AND (obj$ <> nam$)
INPUT #2, nam$, aa, bb, cc, dd, ee, ff, type$, mag$, surfbrt$, descrip$, size$
LOOP                                '>>>>>>>>>>>>>end of file read loop
IF (obj$ <> nam$) THEN              'If desired object not found. . . .
  CLOSE #2
  BEEP
  PRINT : PRINT : PRINT : PRINT : PRINT "        NOT FOUND: "; obj$
  dummy$ = INPUT$(1)
  GOTO DBASETARGET
ELSE
END IF

CLOSE #2

tgt$ = nam$
rahours = aa
ramins = bb
rasecs = cc
decdegs = dd
decmins = ee
decsecs = ff
IF decdegs < 0 AND decmins > 0 THEN decmins = -1 * decmins
IF decdegs < 0 AND decsecs > 0 THEN decsecs = -1 * decsecs
CLS
PRINT
PRINT " "; tgt$
PRINT
PRINT " RA:  "; rahours; ramins; rasecs
PRINT
PRINT " DEC:  "; decdegs; decmins; decsecs
PRINT
PRINT " TYPE:  "; type$
PRINT
PRINT " MAGNITUDE:  "; mag$
PRINT
PRINT " SURFACE BRIGHTNESS:  "; surfbrt$
PRINT
PRINT " DESCRIPTION:  "; descrip$
PRINT
PRINT " SIZE:  "; size$
PRINT
PRINT "Is this correct (Y/N)";
ans$ = INPUT$(1)
IF UCASE$(ans$) = "N" THEN GOTO 30000 ELSE

RETURN                              '<<<<<<<<<<database target select routine


40000                               '<<<<<<<<<<<<<user defined target routine

ans$ = "N"
DO UNTIL UCASE$(ans$) = "Y"
CLS
PRINT " Coordinates to point to?"
PRINT
PRINT
INPUT " RA Hours"; rahours
INPUT " RA Minutes"; ramins
INPUT " RA seconds"; rasecs
PRINT
PRINT
INPUT " DEC degrees"; decdegs
INPUT " DEC minutes"; decmins
INPUT " DEC seconds"; decsecs

DO WHILE UCASE$(MID$(tgt$, 1, 1)) = "X"
tgt$ = MID$(tgt$, 2, 30)
LOOP

IF decdegs < 0 AND decmins > 0 THEN decmins = -1 * decmins ELSE
IF decdegs < 0 AND decsecs > 0 THEN decsecs = -1 * decsecs ELSE
PRINT
PRINT
PRINT tgt$
PRINT
PRINT "Hr Mn Sec"
PRINT USING "## ## ##"; rahours; ramins; rasecs
PRINT
PRINT " Dg  Mn Sec"
PRINT USING "+## +## +##"; decdegs; decmins; decsecs
PRINT
PRINT "Is this correct (Y/N)";
ans$ = INPUT$(1)

raaligndegs = 15 * rahours + ramins / 4 + rasecs / 240
decaligndegs = decdegs + decmins / 60 + decsecs / 3600
tgtra = raaligndegs / 15   'set target ra (in decimal hours)
tgtdec = decaligndegs   'set target dec (in decimal deg's)

LOOP                           'end of user input loop

type$ = "USR DEF"
mag$ = "99.9"
surfbrt$ = "99.9"
descrip$ = "USER DEFINED"
size$ = "USR DEF"

RETURN                         '<<<<<<<<<<<<<user defined target routine


49000                                    'print text screen template
LOCATE 1, 1
IF declutter$ = "OFF" THEN
  PRINT " RA: "; rahours; ramins; rasecs; "  DEC: "; decdegs; decmins; decsecs
  PRINT
  PRINT " TYPE: "; type$; "         MAG: "; mag$
  PRINT "                SURF BRT: "; surfbrt$
  PRINT
  PRINT " NOTES: "; descrip$
  PRINT
  PRINT " SIZE: "; size$
ELSE
END IF

LOCATE 13, 8
PRINT "Target: "; tgt$;
LOCATE 15, 10
PRINT "Tape measure (AZ)      Protractor (EL)";

RETURN                                   'print text screen template


50000                                       'Convert to alt az coordinates
rightascension = 15 * rahours + ramins / 4 + rasecs / 240
hourangle = (15 * elapsedsiderealtime) - rightascension
rightascension = rightascension * pi / 180
hourangle = hourangle * pi / 180      'convert to radians for trig functions

declination = decdegs + decmins / 60 + decsecs / 3600
declination = declination * pi / 180

latitude = latdeg + latmin / 60
latitude = latitude * pi / 180

cosz = SIN(latitude) * SIN(declination) + COS(latitude) * COS(declination) * COS(hourangle)
sinz = SQR(1 - cosz ^ 2)                'sinz needed to get to tanz
tanz = sinz / cosz                      'tanz needed to run ARCTAN function

z = ATN(tanz) * 180 / pi
IF z < 0 THEN z = z + 90 ELSE  'chaged 90 from 180*********


IF z > 90 THEN                    'display below horizon statement
  COLOR 15
  LOCATE 11, 1
  PRINT "********* OBJECT BELOW HORIZON *********";
  LOCATE 20, 1
  PRINT "********* OBJECT BELOW HORIZON *********";
  COLOR colornum
ELSE
END IF                            'display below horizon statement

cosa = ((SIN(latitude) * cosz) - (SIN(declination))) / (COS(latitude) * sinz)
tana = SIN(hourangle) / ((COS(hourangle) * SIN(latitude)) - (TAN(declination) * COS(latitude)))

a = ATN(tana) * 180 / pi
IF cosa < 0 THEN a = 180 + a
a = a + 180

DO WHILE a >= 360
a = a - 360
LOOP

currentaz = a

IF tapelength = tapelength16 THEN

a = 360 - a      'reversed tape measure on 16 inch requires
                 'reversed azimuth readings that decrease when moving in
                 'increasing azimuth

ELSE

END IF

tape = a * tapelength / 360  'scale change for tape measure
tape = tape + scaleshift     'shift for north correction

DO WHILE tape < 0
tape = tape + tapelength
LOOP

DO WHILE tape > tapelength
tape = tape - tapelength
LOOP

shiftedinches = FIX(tape)
shiftedsixteenths = FIX(160 * (tape - FIX(tape)))
shiftedsixteenths = shiftedsixteenths / 10
IF shiftedsixteenths >= 16 THEN
  shiftedsixteenths = shiftedsixteenths - 16
  shiftedinches = shiftedinches + 1
ELSE
END IF

cmsix = (shiftedsixteenths * 6.25) / 100
cm = (shiftedinches + cmsix) * 2.54

LOCATE 18, 1

PRINT USING "## in  ##.#   16ths"; shiftedinches; shiftedsixteenths
LOCATE 20, 1
PRINT USING "###.## cm"; cm

GOSUB 130000          ' get correction value for warped dob base....

LOCATE 18, 30
PRINT USING "###.#"; z + zshift - warpfix;

IF declutter$ = "OFF" THEN
  LSThour = FIX(elapsedsiderealtime)
  LSTleftover = elapsedsiderealtime - LSThour
  LSTminute = FIX(60 * LSTleftover)
  IF LSTminute = 60 THEN
    LSTminute = 0
    LSThour = LSThour + 1
  ELSE
  END IF
  LSTleftover = (60 * LSTleftover) - FIX(60 * LSTleftover)
  LSTsecond = FIX(LSTleftover * 60)
  IF LSTsecond >= 60 THEN
    LSTsecond = 0
    LSTminute = LSTminute + 1
  ELSE
  END IF
 
  IF LSTminute >= 60 THEN
    LSTminute = LSTminute - 60
    LSThour = LSThour + 1
  ELSE
  END IF

  IF LSThour >= 24 THEN
     LSThour = LSThour - 24
  ELSE
  END IF

  PRINT
  PRINT
  PRINT
  PRINT
  PRINT USING "AZ (degrees)  ###.#        LST: ##:##:##"; currentaz; LSThour; LSTminute; LSTsecond
  PRINT USING "Z dist (deg)  ###.#      Local: "; z; : PRINT TIME$;
ELSE
END IF

IF clock$ = "FREEZE" THEN
  LOCATE 14, 2
  PRINT "CLOCK FROZEN"
ELSE
  LOCATE 14, 2
  PRINT "            "
END IF

IF clockshift <> 0 THEN
  LOCATE 14, 17
  PRINT USING "TIME SHIFT: #.###"; clockshift; : PRINT " Hrs";
ELSE
  LOCATE 14, 17
  PRINT "                       ";
END IF

RETURN                          'Convert to alt az coordinates


60000                'Bright star alignment

DO UNTIL UCASE$(ans$) = "Y"
BSTARSCREEN:                  'LABEL FOR GOTO IF STAR NUMBER NOT CHOSEN
CLS
PRINT
PRINT " 1  a.UMi-Polaris     2  a.Per-Mirfak"
PRINT "*3* a.Tau-Aldebaran  *4* b.Ori-Rigel"
PRINT " 5  a.Aur-Capella     6  g.Ori-Bellatrix"
PRINT " 7  b.Tau-Elnath      8  e.Ori-Alnilam"
PRINT "*9* a.Ori-Betelgeuse 10  a.CMa-Sirius"
PRINT " 11 e.CMa-Adhar      12  a.Gem-Castor"
PRINT "*13*a.CMi-Procyon    14  b.Gem-Pollux"
PRINT "*15*a.Leo-Regulus    16  a.UMa-Dubhe"
PRINT " 17 a.Vir-Spica     *18* a.Boo-Arcturus"
PRINT "*19*a.Sco-Antares    20  l.Sco-Shaula"
PRINT " 21 a.Lyr-Vega      *22* a.Aql-Altair"
PRINT " 23 a.Cyg-Deneb      24  a.Psa-Fomalhaut"
PRINT "*25*g.Peg-Algenib, SE corner great sqr."
PRINT
INPUT "Bright star number"; bstarnumb
IF bstarnumb < 0 OR bstarnumb > 25 THEN BEEP: GOTO BSTARSCREEN
 
OPEN "c:\MG-III\bstars.txt" FOR INPUT AS #2

FOR readcount = 1 TO (bstarnumb - 1)
INPUT #2, nam$, aa, bb, cc, dd, ee, ff, dummy$
NEXT readcount

INPUT #2, nam$, aa, bb, cc, dd, ee, ff, dummy$
CLOSE #2

tgt$ = nam$
rahours = aa
ramins = bb
rasecs = cc
decdegs = dd
decmins = ee
decsecs = ff
IF decdegs < 0 AND decmins > 0 THEN decmins = -1 * decmins
IF decdegs < 0 AND decsecs > 0 THEN decsecs = -1 * decsecs
PRINT
PRINT bstarnumb; nam$
PRINT
PRINT "Hr Mn Sec"
PRINT rahours; ramins; rasecs
PRINT
PRINT "Dg Mn Sec"
PRINT decdegs; decmins; decsecs
PRINT
PRINT "Is this correct (Y/N)";
ans$ = INPUT$(1)

LOOP
CLS

type$ = "Bright star"
mag$ = ""
surfbrt$ = ""
descrip$ = ""
size$ = ""

RETURN               'Bright star alignment

70000                    'Shift azimuth calibration

CLS
PRINT
PRINT "Your target: "; tgt$
PRINT
PRINT USING "Calculated AZIMUTH  ## in  ##.#   16ths"; shiftedinches; shiftedsixteenths
PRINT
PRINT
PRINT " Does AZIMUTH need correction? <Y/N>";
ans$ = UCASE$(INPUT$(1))

IF ans$ = "Y" THEN

PRINT
PRINT
PRINT
INPUT "INCHES shift value"; inchesshiftvalue
INPUT "1/16ths shift value"; sixteenthsshiftvalue
inches = inches + inchesshiftvalue
sixteenths = sixteenths + sixteenthsshiftvalue

ELSE
  CLS
  RETURN  'get out of subroutine and back to main processing loop

END IF

scaleshift = inches + sixteenths / 16
CLS

RETURN                   'Shift azimuth calibration

80000                    'Shift Elevation Calibration
' Use variable name  zshift
CLS
PRINT
PRINT "Your target: "; tgt$
PRINT
PRINT USING "Calculated ELEVATION ###.#"; z + zshift - warpfix
PRINT
PRINT
PRINT " Does ELEVATION need correction? <Y/N>";
ans$ = UCASE$(INPUT$(1))

IF ans$ = "Y" THEN
  PRINT
  PRINT
  PRINT
  INPUT "Elevation shift value"; zshift2
  zshift = zshift + zshift2
ELSE
  CLS
  RETURN  'get out of subroutine and back to main processing loop
END IF

CLS

RETURN                   'Shift Elevation Calibration

90000                ' Load initialization/calibration file

OPEN "C:\MG-III\CALIBRAT.DAT" FOR INPUT AS #3
INPUT #3, saveddate$, savedtime$, scaleshift, zshift

CLS
PRINT
PRINT
PRINT " DATA BEING LOADED:"
PRINT
PRINT
PRINT "                DATE SAVED: "; saveddate$
PRINT "                TIME SAVED: "; savedtime$
PRINT "SCALE SHIFT (TAPE MEASURE): "; scaleshift
PRINT "      Z SHIFT (PROTRACTOR): "; zshift
PRINT
PRINT "Press any key. . ."
dummy$ = INPUT$(1)
CLS

CLOSE #3

inches = FIX(scaleshift)
sixteenths = (scaleshift - inches) * 16

RETURN               ' Load initialization/calibration file


91000                ' Save initialization/calibration file

OPEN "C:\MG-III\CALIBRAT.DAT" FOR OUTPUT AS #3

saveddate$ = DATE$
savedtime$ = TIME$

CLS
PRINT
PRINT
PRINT " DATA BEING SAVED:"
PRINT
PRINT
PRINT "                DATE SAVED: "; saveddate$
PRINT "                TIME SAVED: "; savedtime$
PRINT "SCALE SHIFT (TAPE MEASURE): "; scaleshift
PRINT "      Z SHIFT (PROTRACTOR): "; zshift
PRINT
PRINT "Press any key. . ."
dummy$ = INPUT$(1)
CLS

PRINT #3, saveddate$; ","; savedtime$; ","; scaleshift; ","; zshift
CLOSE #3

RETURN               ' Save initialization/calibration file

100000               'choose different letter color for screen display
CLS

FOR colornum = 1 TO 15
  COLOR colornum
  PRINT "This is color number"; colornum
NEXT colornum

COLOR 7
PRINT
INPUT "Choose a color from 1 to 15"; colornum

SELECT CASE colornum

CASE IS <= 0
  BEEP: GOTO 100000

CASE 1 TO 15
  COLOR colornum

CASE IS > 15
  BEEP: GOTO 100000

END SELECT
CLS
RETURN               'choose different letter color for screen display

110000               ' Eq. Platform shift value
CLS
PRINT
PRINT
PRINT " Platform shift (in degrees"
INPUT " of platform motion)"; clockshift

PRINT
PRINT
PRINT "    Is "; clockshift; " degrees correct?";
ans$ = UCASE$(INPUT$(1))

IF ans$ = "N" THEN GOTO 110000 ELSE

clockshift = clockshift / 15.04                 'convert to hours of time
CLS

RETURN               ' Eq. Platform shift value

120000               ' Legend of notes & terms in object description

CLS
PRINT "am  among           att attached        "
PRINT "bet between         B    bright         "
PRINT "b   brighter        C    compressed     "
PRINT "c   considerably    Cl   cluster        "
PRINT "D   double          def  defined        "
PRINT "deg degrees         dif  diffuse        "
PRINT "E   elongated       e    extremely      "
PRINT "er  easily rslvd    F    faint          "
PRINT "f   following       g    gradually      "
PRINT "iF  irr. figure     inv  involved       "
PRINT "L   large           l    little         "
PRINT "M   middle          m    much           "
PRINT "n   north           N    nucleus        "
PRINT "P w paired with     p    pretty         "
PRINT "p   preceding       p    poor           "
PRINT "R   round           Ri   rich           "
PRINT "r   not well rslvd  rr   partially rslvd"
PRINT "rrr well resolved   S    small          "
PRINT "s   suddenly        s    south          "
PRINT "sc  scattered       susp suspected      "
PRINT "st  star/stellar    v    very           "
PRINT "nf  nrth following  np   north preceding"
PRINT "11m 11th magnitude  8... mag 8 & fainter"
PRINT "9..13  9th to 13th magnitude            ";

dummy$ = INPUT$(1)
CLS

RETURN               ' Legend of notes & terms in object description


130000          'Routine to correct for warped dob base - empirically derived
                ' for each telescope

decimalinches = shiftedinches + (shiftedsixteenths / 16)  'make decimal value

IF scopesize = 2 THEN   'warp correction values for ten inch scope

  SELECT CASE decimalinches        'determine value of warpfix

    CASE 0 TO 5
      warpfix = 0
    
    CASE 5 TO 15
      warpfix = (decimalinches - 5) * (.7 / 10)

    CASE 15 TO 22
      warpfix = .7 - ((decimalinches - 15) * (.7 / 7))

    CASE 22 TO 27
      warpfix = -(decimalinches - 22) * (.4 / 5)

    CASE 27 TO 37
      warpfix = -(.4 - (decimalinches - 27) * (.4 / 10))

    CASE 37 TO 50
      warpfix = -(decimalinches - 37) * (.6 / 13)

    CASE 50 TO 60
      warpfix = -(.6 - (decimalinches - 50) * (.6 / 10))

    CASE 60 TO 65
      warpfix = (decimalinches - 60) * (.3 / 5)

    CASE 65 TO 73.5
      warpfix = .3 - (decimalinches - 65) * (.3 / 8.5)

    CASE ELSE
      warpfix = 0
  
  END SELECT

ELSE                   'warp correction values for sixteen inch scope
 
  SELECT CASE decimalinches        'determine value of warpfix

    CASE 0 TO 4
      warpfix = .2 * (decimalinches / 4)

    CASE 4 TO 50
      warpfix = .2

    CASE 50 TO 58
      warpfix = .2 - (.2 * ((decimalinches - 50) / 8))

    CASE 58 TO 66
      warpfix = 0

    CASE ELSE
      warpfix = 0
 
  END SELECT

END IF

RETURN          'Routine to correct for warped dob base - empirically derived

