Viewing contents of file '../idllib/ghrs/pro/ad2xy.pro'
pro ad2xy,a,d,cd,crpix,crval,x,y
;+
; NAME:
;    AD2XY
; PURPOSE:
;   Compute an X and Y position given the RA and DEC and the astrometry
;   parameters CD, CRPIX, and CRVAL.  A tangent (gnomonic) projection is
;   assumed.  AD2XY is meant to be used internal to other procedures.
;   For interactive purposes, use ADXY.
; CALLING SEQUENCE:
;    AD2XY,A,D,CD,CRPIX,CRVAL,X,Y
; INPUTS:
;    A -     R.A. in RADIANS, scalar or vector
;    D -     Dec. in RADIANS, scalar or vector
;    CD    - 2 x 2 array containing the CD parameters CD11 CD12
;            in RADIANS.                              CD21 CD22
;    CRPIX - 2 element vector containing X and Y coordinates 
;            of reference pixel
;    CRVAL - 2 element vector containing R.A. and DEC 
;            of reference pixel in radians
; OUTPUTS:
;    X     - row position in pixels, scalar or vector
;    Y     - column position in pixels, scalar or vector
; RESTRICTIONS:
;    Note that all angles must be in radians, including CD and CRVAL
;    Also note that the CRPIX vector should be in FORTRAN convention
;    (starts at (1,1)), while X and Y are given in IDL convention
;    (starting at (0,0)).                           
;    No parameter checking is performed
; REVISION HISTORY:
;    Written by R.H. Cornett, SASC Tech, 4/7/86
;    Converted to IDL by B. Boothman, SASC Tech, 4/21/86
;-
radif = a - crval(0)
h = sin(d)*sin(crval(1)) + cos(d)*cos(crval(1))*cos(radif)
;
xsi = cos(d)*sin(radif)/h
eta = (sin(d)*cos(crval(1)) -  cos(d)*sin(crval(1))*cos(radif))/h
;
cdinv = invert(cd)
x = cdinv(0,0)*xsi + cdinv(0,1)*eta + crpix(0) - 1
y = cdinv(1,0)*xsi + cdinv(1,1)*eta + crpix(1) - 1
return
end