Viewing contents of file '../idllib/ghrs/pro/adxy.pro'
pro adxy,hdr,a,d,x,y	;Ra, Dec to X,Y
;+
; NAME:
;   ADXY
; PURPOSE:
;   Use an image header to compute X and Y positions, given the
;   RA and Dec in decimal degrees.  A tangent (gnomonic) projection
;   is assumed                   
; CALLING SEQUENCE:
;   ADXY,HDR		;Prompt for Ra and DEC 
;   ADXY,HDR,A,D,X,Y
; INPUTS:
;   HDR - Image header containing astrometry parameters
; OPTIONAL INPUTS:
;    A - Right ascension in decimal DEGREES, scalar or vector
;    D - Declination in decimal DEGREES, scalar or vector        
;    If A and D are not supplied, user will be prompted to supply
;    them in either decimal degrees or HR,MIN,SEC,DEG,MN,SC format.
; OPTIONAL OUTPUT:
;    X     - row position in pixels, same number of elements as A and D
;    Y     - column position in pixels
; OPERATIONAL NOTES:
;    If less than 5 parameters are supplied, or if !DEBUG=1, then
;    then the X and Y positions are displayed at the terminal.
;
;    If the procedure is to be used repeatedly with the same header,
;    then it would be faster to use AD2XY.
; REVISION HISTORY:
;    W. Landsman                 STX          January,1988
;-
npar = n_params(0)
if npar eq 0 then begin
	print,string(7B),'CALLING SEQUENCE - adxy,hdr,[a,d,x,y]
        print,'If supplied, A and D must be in decimal DEGREES
	return
endif                                                                  
extast,hdr,cd,crpix,crval,noparams
if noparams lt 0 then return 
cd = cd/!RADEG  &  crval = crval/!radeg
if npar lt 3 then begin
rd:print,'Coordinates must be entered with either 2 or 6 parameters'
   print,'Either RA,DEC or  HR,MIN,SEC,DEG,MIN,SEC
   inp = ''
   read,'ADXY: Enter coordinates: ',inp
   radec = getopt(inp,'F')
   case n_elements(radec) of 
      2: begin 
         a = radec(0) & d = radec(1)
         end
      6: begin
         a = ten(radec(0:2)*15.) & d = ten(radec(3:5))
	 end
   else: begin
         print,string(7b),'ADXY: ERROR - Illegal Format'
	 return
	 end
endcase 
endif
ad2xy,a/!radeg,d/!radeg,cd,crpix,crval,x,y
if (npar lt 5) or !DEBUG then begin
	npts = n_elements(a)
        fmt = '$(1x ,2F8.4,A,2X,2F8.2)'
	print,'    RA      DEC       RA         DEC        X       Y'
	if npts gt 1 then for i=0,npts-1 do $
	print,format=fmt,a(i),d(i),adstring([a(i),d(i)]),x(i),y(i) $
        else print,format=fmt,float(a),float(d),adstring([a,d]),x,y
endif
return
end