Viewing contents of file '../idllib/uit/pro/chngcam.pro'
PRO chngcam,hdn,hdf,angle=angle,compress=compress,offset=offset,distort=distort
;+
; NAME:
;    CHNGCAM
; PURPOSE:
;	For UIT images.   Transforms astrometry for an NUV image to that for 
;	an FUV image in the same acquisition.
;
; CALLING SEQUENCE:
;	chngcam, hdn, hdf, [ ANGLE =, COMPRESS = , OFFSET = , DISTORT = ] 
;
; INPUT PARAMETERS:
;	hdn = NUV image header
; OPTIONAL INPUT KEYWORDS:
;	angle  = angle of rotation in degrees (DEFAULT = 174.6, 174.87 if image 
;		distortion is present)
;	compress = compression factor as compared to 20 micron pixel spacing on
;		film (DEFAULT = 1)
;	distort = If present and non-zero, forces angle to be 174.87, regardless
;		of what HDN says.  ANGLE keyword over-rides DISTORT.
;	offset = offset of centers in pixels 
;	(DEFAULT = -[28.62/COMPRESS, 15.11/COMPRESS])
;
; OUTPUT PARAMETERS:
;	hdf = FUV image header (modified, not created)
;
; PROCEDURE:
;	Matrix multiplication.
; MODIFICATION HISTORY:
;    Written by J. K. Hill, STX
;    CRPIX change added.  R. S. Hill, STX, 7 March 1991
;    Image distortion angles added, Updated to use ASTROMETRY structure.
;			M.R. Greason & J.D. Offenberg  Hughes STX, Jan 1993
;    Brought into conformity with BDR routine ULCCAM.  Conversion
;       based on MRG's angle, together with an FUV-->NUV scale change and a
;       revised offset.  Based on two pairs of images, NUV0402-FUV0496
;       (M33) and NUV0442-FUV0556 (M81).   R. S.Hill, HSTX, 18 Feb 93.
;    Astrometry recentered on middle of image, in conformity with BDR
;       version of algorithm.  RSH, HSTX, 2 July 1993.
;-
 On_error,2
 
if N_params() LT 2 then begin
    print,'Syntax - chngcam,hdr_nuv,hdr_fuv'
    return
 endif

 zparcheck,'CHNGCAM',hdn,1,7,1,'NUV FITS header array'
 zparcheck,'CHNGCAM',hdf,2,7,1,'FUV FITS header array'

 UIT_extast,hdn,astrc	;cdp,crp,crv

 IF n_elements(compress) lt 1 THEN compress = 1
 IF keyword_set(distort) OR (astrc.ctype(0) eq 'RA---UIT') THEN BEGIN
   IF n_elements(offset) ne 2 THEN offset = [-32.46,-12.37]/compress
   IF n_elements(angle) ne 1 THEN angle = 174.87
   scales = [0.983, 1.008]
 ENDIF ELSE BEGIN
   IF n_elements(offset) ne 2 THEN offset=[-28.62,-15.11]/compress
   IF n_elements(angle) ne 1 THEN angle = 174.6
   scales = [1.0, 1.0]
 ENDELSE

 nax1 = sxpar(hdn,'NAXIS1')
 nax2 = sxpar(hdn,'NAXIS2')
 nax1b= sxpar(hdf,'NAXIS1')
 nax2b= sxpar(hdf,'NAXIS2')

 IF (nax1 NE nax1b) OR (nax2 NE nax2b) THEN BEGIN
   print,'Images are not same size.'
   print,'NAXIS1','NAXIS2',form='(10X,3X,A6,3X,A6)'
   print,'NUV',nax1,nax2,form='(A3,10X,I6,3X,I6)'
   print,'FUV',nax1b,nax2b,form='(A3,10X,I6,3X,I6)'
   RETALL
ENDIF
 xcen = nax1/2.0 + 0.5
 ycen = nax2/2.0 + 0.5
 cdrot,astrc.cd,cd,angle
 cd(0,0) = cd(*,0) * scales(0)
 cd(0,1) = cd(*,1) * scales(1)

 astrc.cd = cd
 pos_vector = astrc.crpix - [xcen,ycen]
 cdrot,pos_vector,pos_vector_2,angle

 astrc.crpix = offset + [pos_vector_2(0),pos_vector_2(1)] + [xcen,ycen]

 UIT_xy2ad,xcen-1,ycen-1,astrc,aacen,ddcen

 astrc.crpix = [xcen, ycen]
 astrc.crval = [aacen, ddcen]

 putast,hdf,astrc

 RETURN
 END