idlastro / Astronomical Utilities: HOR2EQ

[Source code]

NAME
HOR2EQ
PURPOSE
Converts local horizon coords (alt-az) of something to equatorial (ra-dec).
EXPLANATION
This is a nice code to calculate equatorial (ra,dec) coordinates from
horizon (alt,az) coords.    It is typically accurate to about 1 arcsecond
or better (I have checked the output against the publicly available XEPHEM
software). It performs precession, nutation, aberration, and refraction
corrections.  The perhaps best thing about it is that it can take arrays
as inputs, in all variables and keywords EXCEPT Lat, lon, and Altitude
the code assumes these aren't changing), and uses vector arithmetic in
every calculation except when calculating the precession matrices.
CALLING SEQUENCE
HOR2EQ, alt, az, jd, ra, dec, [ha, LAT= , LON= , /WS, OBSNAME= , $
                   /B1950 , PRECESS_= 0, NUTATE_= 0, REFRACT_= 0, $
                   ABERRATION_= 0, ALTITUDE= , /VERBOSE, _EXTRA= ]
INPUT VARIABLES
alt  : altitude (in degrees) [scalar or vector]
az   : azimuth angle (in degrees, measured EAST from NORTH, but see
       keyword WS below.) [scalar or vector]
JD   : Julian Date [scalar or vector], double precision
Note: if RA and DEC are arrays, then alt and az will also be arrays.
      If RA and DEC are arrays, JD may be a scalar OR an array of
       the same dimensionality.
OPTIONAL INPUT KEYWORDS
lat   : north geodetic latitude of location in degrees
lon   : EAST longitude of location in degrees
        (Specify west longitude with a negative sign.)
/WS   : Set this to get the azimuth measured westward from south
        (not East of North).
obsname   : Set this to a valid observatory name to be used by the
        astrolib OBSERVATORY procedure, which will return the latitude
        and longitude to be used by this program.
/B1950  : Set this if your ra and dec are specified in B1950,
        FK4 coordinates (instead of J2000, FK5)
precess_ : Set this to 1 to force precession [default], 0 for no
          precession.
nutate_  : Set this to 1 to force nutation [default], 0 for no nutation.
aberration_ : Set this to 1 to force aberration correction [default],
          0 for no correction.
refract_  : Set to 1 to force refraction correction [default], 0 for
            no correction.
altitude: The altitude of the observing location, in meters. [default=0].
/verbose: Set this for verbose output.  The default is verbose=0.
ra: This is for setting TEMPERATURE or PRESSURE explicitly, which are
    used by CO_REFRACT to calculate the refraction effect of the
    atmosphere. If you don't set these, the program will make an
    intelligent guess as to what they are (taking into account your
     altitude).  See CO_REFRACT for more details.
OUTPUT VARIABLES
ra   : Right Ascension of object  (J2000) in degrees (FK5); scalar or
       vector.
dec  : Declination of object (J2000) in degrees (FK5), scalar or vector.
ha   : hour angle (in degrees) (optional)
DEPENDENCIES
NUTATE, PRECESS, ADSTRING(), SUNPOS, OBSERVATORY (from the astrolib)
CO_NUTATE, CO_ABERRATION, CO_REFRACT, HADEC2ALTAZ
BASIC STEPS
Precess Ra-Dec to current equinox.
Nutation Correction to Ra-Dec
Aberration correction to Ra-Dec
Calculate Local Mean Sidereal Time
Calculate Local Apparent Sidereal Time
Calculate Hour Angle
Do Spherical Trig to find Apparent Alt-Az
Apply refraction correction to find observed Alt.
ORRECTIONS I DO NOT MAKE
*  Deflection of Light by the sun due to GR. (typically milliarcseconds,
     can be arcseconds within one degree of the sun)
*  The Effect of Annual Parallax (typically < 1 arcsecond)
*  and more (see below)
TO DO
* Better Refraction Correction.  Need to put in wavelength dependence,
   and integrate through the atmosphere.
* Topocentric Parallax Correction (will take into account elevation of
      the observatory)
* Proper Motion (but this will require crazy lookup tables or something).
* Difference between UTC and UT1 in determining LAST -- is this important?
* Effect of Annual Parallax (is this the same as topocentric Parallax?)
* Polar Motion
* Better connection to Julian Date Calculator.
EXAMPLE
You are at Kitt Peak National Observatory, looking at a star at azimuth
angle 264d 55m 06s and elevation 37d 54m 41s (in the visible).  Today is
Dec 25, 2041 and the local time is 10 PM precisely.  What is the ra and dec
(J2000) of the star you're looking at?   The temperature here is about 0
Celsius, and the pressure is 781 millibars.    The Julian date for this
time is 2466879.7083333
DL> hor2eq, ten(37,54,41), ten(264,55,06), 2466879.7083333d, ra, dec, $
        /verb, obs='kpno', pres=781.0, temp=273.0
The program produces this output (because the VERBOSE keyword was set)
Latitude = +31 57 48.0 Longitude = *** 36 0.0 ; longitude prints weirdly b/c of negative input to ADSTRING!!
Julian Date = 2466879.708333
Az, El = 17 39 40.4 +37 54 41.0 (Observer Coords)
Az, El = 17 39 40.4 +37 53 39.6 (Apparent Coords)
LMST = +03 53 54.1
LAST = +03 53 53.6
Hour Angle = +03 38 30.1 (hhmmss)
Ra, Dec 00 15 23.5 +15 25 1.9 (Apparent Coords)
Ra, Dec 00 15 24.2 +15 25 0.1 (J2041.9841)
Ra, Dec 00 13 14.1 +15 11 0.3 (J2000)
The star is therefore Algenib! Compare the derived Ra, Dec with what XEPHEM
got
Ra, Dec 00 13 14.2 +15 11 1.0 (J2000)
AUTHOR
Chris O'Dell
Assistant Professor of Atmospheric Science
Colorado State University
Email: odell@atmos.colostate.edu
REVISION HISTORY
Made all integers type LONG  W. Landsman   September 2007
Fixed for case of scalar Julian date but vector positions W L June 2009