ASTROM


List of Routines


Routine Descriptions

ABSCAL

[Next Routine] [List of Routines]
 NAME:
	ABSCAL
 PURPOSE:
	Apply the BZERO and BSCALE keyword values in an FITS header to a data
	array

 CALLING SEQUENCE:
	RESULT = ABSCAL( VALUE, HEADER)

 INPUTS:
	VALUE -  Any scalar, vector, or array (usually an integer type giving a
		relative intensity).
	HEADER - A FITS  header array containing the absolute calibration
		keyword BSCALE, and optionally BZERO and BUNIT.

 OUTPUT:
	RESULT = BSCALE*VALUE + BZERO, where the BSCALE and BZERO scalars
		are taken from the FITS header.  
		If the absolute calibration keywords do not exist, then
		RESULT = VALUE, and !ERR = -1.

 SYSTEM VARIABLES:
	If the system variable !DEBUG is set, then ABSCAL will print the
	calibration units given by the BUNIT keyword.

 REVISION HISTORY:
	Written W. Landsman, STX Corporation     January 1987

(See /usr/local/idl/lib/zastron/astrom/abscal.pro)


AD2XY

[Previous Routine] [Next Routine] [List of Routines]
 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
	computed directly; other projections are computed using WCSXY2SPH.  
	AD2XY is meant to be used internal to other procedures.   For 
	interactive purposes, use ADXY.

 CALLING SEQUENCE:
	AD2XY, a ,d, cd, astr, x, y   

 INPUTS:
	A -     R.A. in DEGREES, scalar or vector
	D -     Dec. in DEGREES, scalar or vector
	ASTR - astrometry structure, output from EXTAST procedure containing:
   	 .CD   -  2 x 2 array containing the astrometry parameters CD1_1 CD1_2
		in DEGREES/PIXEL                                   CD2_1 CD2_2
	 .CDELT - 2 element vector giving increment at reference point in
		DEGREES/PIXEL
	 .CRPIX - 2 element vector giving X and Y coordinates of reference pixel
		(def = NAXIS/2)
	 .CRVAL - 2 element vector giving R.A. and DEC of reference pixel 
		in DEGREES
	 .CTYPE - 2 element vector giving projection types 

 OUTPUTS:
	X     - row position in pixels, scalar or vector
	Y     - column position in pixels, scalar or vector

 REVISION HISTORY:
	Converted to IDL by B. Boothman, SASC Tech, 4/21/86
	Use astrometry structure,  W. Landsman      Jan. 1994	

(See /usr/local/idl/lib/zastron/astrom/ad2xy.pro)


ADXY

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	ADXY
 PURPOSE:
	Use an image header to compute X and Y positions, given the
	RA and Dec in decimal degrees.  

 CALLING SEQUENCE:
	ADXY, HDR		;Prompt for Ra and DEC 
	ADXY, hdr, a, d, x, y, [ /PRINT ]

 INPUTS:
	HDR - FITS 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

 OPTIONAL KEYWORD INPUT:
	PRINT - If this keyword is set and non-zero, then results are displayed
		at the terminal.

 OPERATIONAL NOTES:
	If less than 5 parameters are supplied, or if the /PRINT keyword is
	set, 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                 HSTX          January, 1988
	Use astrometry structure   W. Landsman   January, 1994	

(See /usr/local/idl/lib/zastron/astrom/adxy.pro)


CONS_DEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	CONS_DEC
 PURPOSE:
	Returns a set of Y pixels values, given an image with tangent projection
	astrometry, and either
	(1)  A set of X pixel values, and a scalar declination value, or
	(2)  A set of declination values, and a scalar X value

	Form (1) can be used to find the (X,Y) values of a line of constant
	declination.  Form (2) can be used to find the Y positions of a set
	declinations, along a line of constant X.

 CALLING SEQUENCE:
	Y = CONS_DEC( DEC, X, CD, ASTR, ALPHA)

 INPUTS:
	DEC - Declination value(s) in DEGREES (-!PI/2 < DEC < !PI/2).  
		If X is a vector, then DEC must be a scalar.
	X -   Specified X pixel value(s) for line of constant declination 
		If DEC is a vector, then X must be a scalar.
	ASTR - Astrometry structure, as extracted from a FITS header by the
		procedure EXTAST
 OUTPUT:
	Y   - Computed set of Y pixel values.  The number of Y values is the
		same as either DEC or X, whichever is greater.

 OPTIONAL OUTPUT:
	ALPHA - the right ascensions (DEGREES) associated with the (X,Y) points

 RESTRICTIONS:
	Program will have difficulty converging for declination values near
	90.  For tangent (gnomonic) projections only.  

 REVISION HISTORY:
	Written, Wayne Landsman  STX Co.	                  April 1988
	Algorithm  adapted from AIPS memo 27. by Eric Griessen
	Use new astrometry structure,     W. Landsman    HSTX     Jan. 1994

(See /usr/local/idl/lib/zastron/astrom/cons_dec.pro)


CONS_RA

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	CONS_RA
 PURPOSE:
	Return a set of X pixel values given an image with astrometry, 
	and either
	(1) a set of Y pixel values, and a scalar right ascension, or
	(2) a set of right ascension values, and a scalar Y value.

	In usage (1), CONS_RA can be used to determine the (X,Y) values
	of a line of constant right ascension.  In usage (2), CONS_RA can
	used to determine the X positions of specified RA values, along a
	line of constant Y.

 CALLING SEQUENCE:
	X = CONS_RA( RA, Y, ASTR)

 INPUTS:         
	RA -  Right Ascension value in DEGREES (0 < RA < 2*PI).  If Y is a
		vector, then RA must be a scalar
	Y -   Specified Y pixel value(s) for line of constant right ascension
		If RA is a vector, then Y must be a scalar
	ASTR - Astrometry structure as extracted from a FITS header by the 
		procedure EXTAST
 OUTPUTS
	X   - Computed set of X pixel values.   The number of elements of X
		is the maximum of the number of elements of RA and Y.

 RESTRICTIONS:
	Program will have difficulty converging for declination values near
	90.    For tangent projection only.  

 REVISION HISTORY:
	Written, Wayne Landsman  STX Co.	April, 1988
	Algorithm adapted from AIPS memo No. 27 by Eric Griessen
	New astrometry structure

(See /usr/local/idl/lib/zastron/astrom/cons_ra.pro)


EXTAST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	EXTAST
 PURPOSE:
	Extract astrometry parameters from a FITS image header.
	The astrometry in the header can be in either CD (Coordinate
	description) format, or CROTA and CDELT (AIPS-type) format.
	However, the output astrometry will always be in CD format.

 CALLING SEQUENCE:
	EXTAST, hdr, [ astr, noparams ]   

 INPUT:
	HDR - variable containing the FITS header (string array)

 OUTPUTS:
	ASTR - Anonymous structure containing astrometry info from the FITS 
		header.  ASTR always contains the following tags (even though 
		some projections do not require all the parameters)
   	 .CD   -  2 x 2 array containing the astrometry parameters CD1_1 CD1_2
		in DEGREES/PIXEL                                   CD2_1 CD2_2
	 .CDELT - 2 element vector giving physical increment at reference pixel
	 .CRPIX - 2 element vector giving X and Y coordinates of reference pixel
		(def = NAXIS/2)
	 .CRVAL - 2 element double precision vector giving R.A. and DEC of 
		reference pixel in DEGREES
	 .CTYPE - 2 element string vector giving projection types, default
		['RA---TAN','DEC--TAN']
	 .LONGPOLE - scalar longitude of north pole (default = 180) 
        .PROJP1 - Scalar parameter needed in some projections
	 .PROJP2 - Scalar parameter needed in some projections

	NOPARAMS -  Scalar indicating the results of EXTAST
		-1 = Failure - Header missing astrometry parameters
		0 = Success - Header contains CD00n00m + CDELT* astrometry
		1 = Success - Header contains CROTA + CDELT (AIPS-type) astrometry
		2 = Success - Header contains CDn_m astrometry

 PROCEDURE
	EXTAST checks for astrometry parameters in the following order:
	(1) the CD matrix CD1_1,CD1_2... plus CRPIX and CRVAL.   
	(2) the CD matrix CD001001,CD001002...plus CRPIX and CRVAL
	(3) CROTA2 (or CROTA1) and CDELT plus CRPIX and CRVAL.
	See the Memo: Representations of Celestial Coordinates in FITS by
		Griesen and Calabretta, available at fits.cv.nrao.edu

 NOTES:
	(1) An anonymous structure is created to avoid structure definition
		conflicts.    This is needed because some projection systems
		require additional dimensions (i.e. spherical cube
		projections require a specification of the cube face).

 PROCEDURES CALLED:
	ZPARCHECK, SXPAR
 REVISION HISTORY
	Written by B. Boothman 4/15/86
	Accept CD001001 keywords               1-3-88
	Accept CD1_1, CD2_1... keywords    W. Landsman    Nov. 92

(See /usr/local/idl/lib/zastron/astrom/extast.pro)


FITS_CD_FIX

[Previous Routine] [Next Routine] [List of Routines]
  NAME
	FITS_CD_FIX
  PURPOSE:
	Convert from the representation of the CD matrix in a FITS header
	with an underscore (e.g. CDn_m) to that with all integers (e.g.
	CD00n00m).    According to the proposed World Coordinate System
	standard by Griesen and Calabretta, the CD00n00m form is to be
	preferred and does not include the plate scale, so that CDELT* 
	keywords are also needed.     The CD1_1 form (used in IRAF) includes 
	the plate scale (CDELT) factor. 

	Because of past confusion as to which form to use, it will sometimes
	be necessary to convert from one form to the other.

  CALLING SEQUENCE:
	FITS_CD_FIX, Hdr, [/REVERSE]

  INPUT-OUTPUT: 
	HDR - FITS header, 80 x N string array.   If the header does not
           contain the CDn_m keywords then it is left unmodified.  Other-
           wise the CDn_m keywords are removed and the CD00n00m keywords
           inserted (with the same values).
   
  OPTIONAL KEYWORD INPUT
	REVERSE - If this keyword is set and non-zero, then the process is
		reversed, i.e. CD00n00m keywords are removed from the header
		and CDn_m keywords are inserted.

  REVISION HISTORY:
     Written   W. Landsman             Feb 1990
     Major rewrite                     Feb 1994

(See /usr/local/idl/lib/zastron/astrom/fits_cd_fix.pro)


GETROT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	GETROT
 PURPOSE:
	Derive the counterclockwise rotation angle, and the X and Y scale
	factors of an image, from a FITS image header.     First parameter 
	may be either an image header or a CD matrix (in radians).

 CALLING SEQUENCE:
	GETROT, Hdr, [ Rot, CDelt ]   
		or 
	GETROT, Astr, Rot, CDelt       

 INPUT PARAMETERS:
	HDR - FITS Image header (string array).  Program will extract the 
		astrometry structure
		or
	ASTR -  ASTROMETRY structure, of the type returned by BUILDAST or 
		EXTAST.   See BUILDAST.PRO or EXTAST.PRO for details.

 OUTPUT PARAMETERS:
	ROT - Scalar giving the counterclockwise rotation of NORTH in DEGREES 
		from the +Y axis of the image.
	CDELT- 2 element vector giving the scale factors in DEGREES/PIXEL in 
		the X and Y directions.  Values correspond to the FITS 
		parameters CDELT1 and CDELT2 

 SYSTEM VARIABLES:
	If the non-standard system variable !DEBUG is set, then procedure 
	will print the rotation for both the X and Y axis when these values 
	are unequal.  If !DEBUG is set to 2, then the output parameter ROT 
	will contain both X and Y rotations.

 PROCEDURE:
 	If the FITS header already contains CDELT (and CD or CROTA) keyword,
	(as suggested by the proposed Greisen & Calabretta FITS standard) 
	then this is used for the scale factor.
	
       If the header contains CD keywords but no CDELT keywords, then 
	
 REVISION HISTORY:
	Written W. Landsman STX January 1987 
	Convert to IDL V2. M. Greason, STX, May 1990
	Option to return both rotations added.  J. D. Offenberg, STX, Aug 1991
	Accept ASTROMETRY structures as well as CD, HDR.  JDO, HSTX, Jan 1993

(See /usr/local/idl/lib/zastron/astrom/getrot.pro)


GET_EQUINOX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	GET_EQUINOX
 PURPOSE:
	Return the equinox value from a FITS header.  Checks for 3 possibilities
	(1)  If the EQUINOX keyword is found and has a numeric value, then this
		value is returned
	(2)  If the EQUINOX keyword has the values 'J2000' or 'B1950', then
		either 2000. or 1950. is returned.
	(3)  If the EQUINOX keyword is not found, then GET_EQUINOX will return
		the EPOCH keyword value.   This usage of EPOCH is disparaged.

 CALLING SEQUENCE:
	Year = GET_EQUINOX( Hdr, [ Code ] )   

 INPUTS:
	Hdr - FITS Header, string array, will be searched for the EQUINOX
		(or EPOCH) keyword.

 OUTPUT:
	Year - Year of equinox in FITS header, numeric scalar
 OPTIONAL OUTPUT:
	Code - Result of header search, scalar
		-1 - EQUINOX or EPOCH keyword not found in header
		0 - EQUINOX found as a numeric value
		1 - EPOCH keyword used for equinox (not recommended)
		2 - EQUINOX found as  'B1950'
		3 - EQUINOX found as  'J2000'

 REVISION HISTORY:                                               
	Written  W. Landsman        STX              March, 1991

(See /usr/local/idl/lib/zastron/astrom/get_equinox.pro)


HASTROM

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	HASTROM
 PURPOSE:
	Perform a linear transformation (with POLY_2D) on an image so that
	its astrometry is identical with that in a reference header.  This
	procedure can be used to align two images.

 CALLING SEQUENCE:
	HASTROM, oldim, oldhd, newim, newhd, refhd, [MISSING = , INTERP = ]
		or
	HASTROM, oldim, oldhd, refhd, [MISSING = , INTERP =, NGRID =   ]

 INPUTS:
	OLDIM - Image array to be manipulated.  If only 3 parameters are
		supplied then OLDIM and OLDHD will be modified to contain 
		the output image array and header
	OLDHD - FITS header array for OLDIM, containing astrometry parameters
	REFHD - Reference header, containing astrometry parameters.  OLDIM
		will be rotated, shifted, and compressed or expanded until
		its astrometry matches that in REFHD.
 OUTPUTS:
	NEWIM - Image array after linear tranformation has been performed.
		The dimensions of NEWIM will be identical to the NAXIS1 and 
		NAXIS2 keywords specified in REFHD.  Regions on the reference 
		image that do not exist in OLDIM can be assigned a value with
		the MISSING keyword.
	NEWHD - Updated FITS image header associated with NEWIM

 OPTIONAL INPUT KEYWORDS:
	MISSING - Set this keyword to a scalar value which will be assigned
		to pixels in the output image which do not correspond to 
		existing imput images.  If not supplied then linear 
		extrapolation is used.   See the IDL manual on POLY_2D.
	INTERP - Scalar, one of 0, 1, or 2 determining type of interpolation
		0 nearest neighbor, 1 (default) bilinear interpolation, 
		2 cubic interpolation (only available in V3.5.0 or later)
	NGRID -  Integer scalar specifying the number of equally spaced grid 
		points on each axis to use to specify the transformation.   
		Default is GRID = 3 (9 total grid points).     The value of
		GRID must always be greater than DEGREE + 1
	DEGREE - Integer Scalar specify the degree of the transformation.
		See the routine POLYWARP for more info.   Default = 1
		(linear transformation).
 NOTES:
	(1) The 3 parameter calling sequence is less demanding on virtual 
		memory.
	(2) The astrometry in OLDHD will be precessed to match the equinox
		given in REFHD.

 EXAMPLE:
	Suppose one has an image array, IM, and an associated FITS header H.
	One desires to warp the image array so that it is aligned with another
	image with a FITS header, HREF.    Both headers contain astrometry info.
	Set pixel values to 0 where there is no overlap between the input and
	reference image, and use linear interpolation (default)

           IDL> hastrom, IM, H, HREF, MISSING = 0

 PROCEDURES USED:
	zparcheck, check_FITS, sxpar, get_EQUINOX, hprecess, extast,
	sxaddpar, sxaddhist, putast

 REVISION HISTORY:
	Written  W. Landsman, STX Co.              Feb, 1989
	Updated to CHECK_FITS                      Dec, 1991
	New astrometry keywords                    Mar, 1994

(See /usr/local/idl/lib/zastron/astrom/hastrom.pro)


HBOXAVE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	HBOXAVE
 PURPOSE:
	Box average an image array using the function BOXAVE and update the
	FITS header array.   This procedure is recommended for integer images 
	when photometric precision is desired, because it performs intermediate 
	steps using REAL*4 arithmetic.   Otherwise, the procedure HREBIN is much
	faster.

 CALLING SEQUENCE:
	HBOXAVE, Oldim, Oldhd, Newim, Hewhd, box
		or
	HBOXAVE, Oldim, Oldhd, box

 INPUTS:
	Oldim - the original image array
	Oldhd - the original image FITS header, string array

 OPTIONAL INPUTS:
	box - the box size to be used, integer scalar.  If omitted, then
		HBOXAVE will prompt for this parameter.

 OPTIONAL OUTPUTS:
	Newim - the image after boxaveraging
	Newhd - header for newim containing updated astrometry info
		If output parameters are not supplied, the program
		will modify the input parameters OLDIM and OLDHD
		to contain the new array and updated header.
 PROCEDURE:
	The parameters BSCALE, NAXIS1, NAXIS2, CRPIX1, and CRPIX2 and
	the CD (or CDELT) parameters are updated for the new FITS header.

 CALLED PROCEDURES:
	CHECK_FITS - Check that the FITS header is appropriate to the image
	BOXAVE - Performs box averaging of an image
	SXPAR, SXADDPAR - Read and write FITS keyword values

 MODIFICATION HISTORY:
	Written, Aug. 1986 W. Landsman, STI Corp.
	IDLV2 changes, sxaddpar format keyword added, J. Isensee, July,1990
	Fix 0.5 pixel offset in new CRPIX computation W. Landsman, Dec, 1991

(See /usr/local/idl/lib/zastron/astrom/hboxave.pro)


HCONGRID

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	HCONGRID
 PURPOSE:
	Expand or contract an image using CONGRID and update the 
	associated FITS header array.

 CALLING SEQUENCE:
	HCONGRID, oldhd                       ;Update FITS header only
	HCONGRID, oldim, oldhd, [ newim, newhd, newx, newy, INTERP=, OUTSIZE =]

 INPUTS:
	OLDIM - the original image array
	OLDHD - the original image FITS header, string array

 OPTIONAL INPUTS:
	NEWX - size of the new image in the X direction
	NEWY - size of the new image in the Y direction
		The OUTSIZE keyword can be used instead of the 
		NEWX, NEWY parameters

 OPTIONAL OUTPUTS:
	NEWIM - the image after expansion or contraction with CONGRID
	NEWHD - header for newim containing updated astrometry info
		If output parameters are not supplied, the program
		will modify the input parameters OLDIM and OLDHD
		to contain the new array and updated header.

 OPTIONAL KEYWORD INPUTS:
	OUTSIZE - Two element integer vector which can be used instead of the
		NEWX and NEWY parameters to specify the output image dimensions
	INTERP   - 0 for nearest neighbor, 1 for bilinear interpolation
		2 for cubic interpolation.   Cubic interpolation requires
		IDL V3.5 or later.
 PROCEDURE:
	Expansion or contraction is done using the CONGRID function.
	neighbor. 
	The parameters BSCALE, NAXIS1, NAXIS2, CRPIX1, and CRPIX2 and
	the CD (or CDELT) parameters are updated for the new header.

 NOTES:
	A FITS header can be supplied as the first parameter without having
	to supply an image array.   The astrometry in the FITS header will be
	updated to be appropriate to the specified image size.

 EXAMPLE:
	Congrid an 512 x 512 image array IM and FITS header H to size 300 x 300
	using cubic interpolation

	IDL> hcongrid, IM ,H, OUT = [300, 300], INTERP = 2

	The variables IM and H will be modified to the new image size.

 MODIFICATION HISTORY:
	Written, Aug. 1986 W. Landsman, STI Corp.
	Added interp keywords, J. Isensee, July, 1990
	Add cubic interpolation W. Landsman HSTX   January 1994

(See /usr/local/idl/lib/zastron/astrom/hcongrid.pro)


HEXTRACT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	HEXTRACT
 PURPOSE:
	Extract a subimage from an array and create a new FITS header with
	updated astrometry for the subarray
 CALLING SEQUENCE:
	HEXTRACT, Oldim, Oldhd, [ Newim, Newhd, x0, x1, y0, y1 ]
		or
	HEXTRACT, Oldim, Oldhd, [x0, x1, y0, y1 ]	 

 INPUTS:
	Oldim - the original image array
	Oldhd - the original image header

 OPTIONAL INPUTS:
	x0, x1, y0, y1 - respectively, first and last X pixel, and first and
	last Y pixel to be extracted from the original image, integer scalars.
	If omitted,  HEXTRACT will prompt for these parameters

 OPTIONAL OUTPUTS:
	Newim - the new subarray extracted from the original image 
	Newhd - header for newim containing updated astrometry info
		If output parameters are not supplied or set equal to
		-1, then the HEXTRACT will modify the input parameters 
		OLDIM and OLDHD to contain the subarray and updated header.

 PROCEDURE:
	The FITS header parameters NAXIS1, NAXIS2, CRPIX1, and CRPIX2 are
	updated for the extracted image.

 EXAMPLE:  
	Read an image from a FITS file 'IMAGE', extract a 512 x 512 subimage 
	with the same origin, and write to a new FITS file 'IMAGENEW'

	IDL> im = READFITS( 'IMAGE', hdr )	;Read FITS files into IDL arrays
	IDL> hextract, im, h, 0, 511, 0, 511	;Extract 512 x 512 subimage
	IDL> writefits, 'IMAGENEW', im ,h	;Write subimage to a FITS file

 PROCEDURES CALLED
	CHECK_FITS, STRN, SXPAR, SXADDPAR, SXADDHIST
 MODIFICATION HISTORY:
	Written, Aug. 1986 W. Landsman, STX Corp.
	Use astrometry structure,   W. Landsman      Jan, 1994

(See /usr/local/idl/lib/zastron/astrom/hextract.pro)


HPRECESS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	HPRECESS
 PURPOSE:
	Precess the astrometry in a FITS header to a new equinox

 CALLING SEQUENCE:
	HPRECESS, HDR, [ yearf ]      

 INPUT-OUTPUT:
	HDR - FITS Header, must contain the CRVAL astrometry keywords,
		and either an EPOCH or EQUINOX keyword.
		HDR will be modified to contain the precessed astrometry

 OPTIONAL INPUT:
	YEARF - Scalar, giving the year of the new (Final) equinox.
		If not supplied, user will be prompted for this value.

 METHOD:
	The CRVAL and CD (or CROTA) keywords are extracted from the header 
	and precessed to the new equinox.  The EPOCH or EQUINOX keyword in 
	the header is  updated.  A HISTORY record is added

 RESTRICTIONS:
	The FK4 reference frame is assumed for both equinoxes.

 PROCEDURES USED:
	ZPARCHECK, GET_EQUINOX, EXTAST, SXADDPAR, SXADDHIST, PRECESS,
	PRECESS_CD, PUTAST
 REVISION HISTORY:                                               
	Written  W. Landsman        STX              July, 1988
	CD matrix precessed -                        February, 1989
	Update EQUINOX keyword when CROTA2 present   November, 1992

(See /usr/local/idl/lib/zastron/astrom/hprecess.pro)


HREBIN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	HREBIN
 PURPOSE:
	Expand or contract a FITS or SDAS image using REBIN and update the 
	header array.  The size of the new image must be an integer factor of 
	the original image size.    User can either overwrite the input array,
	or write to new variables.

 CALLING SEQUENCE:
	hrebin, oldhd        ;Special calling sequence to just update header
	hrebin, oldim, oldhd, [ newim, newhd, newx, newy, OUTSIZE = ,SAMPLE = ]

 INPUTS:
	OLDIM - the original image array
	OLDHD - the original image FITS header, string array

 OPTIONAL INPUTS:
	NEWX - size of the new image in the X direction, integer scalar
	NEWY - size of the new image in the Y direction, integer scalar
		HREBIN will prompt for NEWX and NEWY if not supplied

 OPTIONAL OUTPUTS:
	NEWIM - the image after expansion or contraction with REBIN
	NEWHD - header for newim containing updated astrometry info
		If output parameters are not supplied, the program
		will modify the input parameters OLDIM and OLDHD
		to contain the new array and updated header.

 OPTIONAL INPUT KEYWORDS:
	SAMPLE - Expansion or contraction is done using REBIN which uses 
		bilinear interpolation when magnifying and boxaveraging when 
		minifying.
		If the SAMPLE keyword is supplied and non-zero, then nearest 
		neighbor sampling is used in both cases.   

	OUTSIZE - Two element integer vector which can be used instead of the
		NEWX and NEWY parameters to specify the output image dimensions

 PROCEDURE:
	The parameters BSCALE, NAXIS1, NAXIS2, CRPIX1, and CRPIX2 and the CD 
	(or CDELT) parameters are updated for the new FITS header.

 EXAMPLE:
	Compress a 2048 x 2048 image array IM, with header FITS HDR, to a 
	512 x 512 array.   Overwrite the input variables with the compressed 
	image and header.

	IDL> hrebin, im, hdr, OUT = [512,512]

 PROCEDURES USED:
	SXPAR, SXADDHIST, CHECK_FITS

 MODIFICATION HISTORY:
	Written, December 1990  W. Landsman, ST System Corp.
	Update CD1_1 keywords   W. Landsman   November 1992

(See /usr/local/idl/lib/zastron/astrom/hrebin.pro)


HREVERSE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	HREVERSE
 PURPOSE:
	Reverse an image about either the X or Y axis, and create a new 
	header with updated astrometry for the reversed image.

 CALLING SEQUENCE:
	HREVERSE,oldim,oldhd, [ subs ]   	;Update input image and header
		or
	HREVERSE, oldim, oldhd, newim, newhd, [ subs ]   

 INPUTS:
	OLDIM - the original image array
	OLDHD - the original image header

 OPTIONAL INPUTS:
	SUBS - Subs equals 1 to reverse the order of the X dimension,
		2 to reverse Y order.  If omitted, then HREVERSE will
		prompt for this scalar parameter.

 OPTIONAL OUTPUTS:
	NEWIM - the rotated image, with the same dimensions as Oldim 
	NEWHD - header for newim containing updated astrometry info
		If output parameters are not supplied, the program
		will modify the input parameters OLDIM and OLDHD
		to contain the rotated image and updated header.

 SIDE EFFECTS:
	A right-handed coordinate system is converted into a left-
	handed one, and vice-versa.

 PROCEDURE:
	The User's Library procedure REVERSE is used to reverse the image.
	The CD and CRPIX header parameters are updated for the new header.
	For AIPS type astrometry, the CDELT parameters are also updated.
	A history record is also added to the header

 MODIFICATION HISTORY:
	Written, Aug. 1986 W. Landsman, STI Corp.
	Error modifying CROTA angles corrected     9-23-88
	Added format keyword, J. Isensee, July, 1990

(See /usr/local/idl/lib/zastron/astrom/hreverse.pro)


HROT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	HROT
 PURPOSE:
	Rotate an image (cubic, bilinear or nearest neighbor interpolation) 
	and create a new FITS header with updated astrometry for the rotated 
	image.

 CALLING SEQUENCE:
	HROT, oldim, oldhd, [ newim, newhd, angle, xc, yc, int, 
			MISSING =, INTERP = ]
 INPUTS:
	OLDIM - the original image array                             
	OLDHD - the original FITS image header, string array

 OPTIONAL INPUTS:
	NEWIM - If NEWIM is set to -1, then the old image and header will
		be updated
	ANGLE - Rotation angle degrees counterclockwise
	XC    - X Center of rotation (-1 for center of image)
	YC    - Y Center of rotation (-1 for center of image)
	INT   - 0 for nearest neighbor, 1 for bilinear interpolation
		2 for cubic interpolation.   Cubic interpolation requires
		IDL V3.5 or later.

 OPTIONAL OUTPUTS:
	NEWIM - the rotated image, with the same dimensions as Oldim 
	NEWHD - header for newim containing updated astrometry info
		If output parameters are not supplied, the program
		will modify the input parameters OLDIM and OLDHD
		to contain the rotated image and updated header.

 OPTIONAL INPUT KEYWORD:
	MISSING - Set this keyword to a scalar value which will be assigned
		to pixels in the output image which do not correspond to 
		existing imput images (e.g if one rotates off-center). 
		If not supplied then linear extrapolation is used.

	INTERP - scalar set to either 0 (nearest neighbor interpolation),
		1 (bilinear interpolation), or 2 (cubic interpolation, V3.5
		or later).    Either the INTERP keyword or the int parameter
		can be specified.
 EXAMPLE:
	Rotate an image non-interactively 30 degrees counterclockwise.  Use
	bilinear interpolation, and set missing values to 0.

	IDL>  HROT, im_old, h_old, im_new, h_new, 30, -1, -1, 1, MIS = 0

 RESTRICTIONS:
	Unlike the ROT procedure, HROT cannot be used to magnify or
	or demagnify an image. Use HCONGRID or HREBIN instead.

 PROCEDURE:
	The image array is rotated using the ROT procedure.
	The CD (or CROTA) and CRPIX parameters, if present in the FITS header,
	are updated for the new rotation.
	History records are also added to the header

 PROCEDURES USED:
	CHECK_FITS, GETOPT, ROT, SXADDPAR, EXTAST, GETROT

 MODIFICATION HISTORY:
	Written, Aug. 1986 W. Landsman, ST Systems Corp.
	Added MISSING keyword, W. Landsman March, 1991
	Added cubic interpolation, use astrometry structure   Feb 1994

(See /usr/local/idl/lib/zastron/astrom/hrot.pro)


PUTAST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	PUTAST
 PURPOSE:
	Put astrometry parameters into a given FITS header.

 CALLING SEQUENCE:
	putast, hdr, astr, [EQUINOX =, CD_TYPE = ]
	     or
	putast, hdr, cd,[ crpix, crval], [ EQUINOX =, CD_TYPE = ]

 INPUTS:
	HDR -  FITS header, string array.   HDR will be updated to contain
		the supplied astrometry.
			or
	CD   - 2 x 2 array containing the astrometry parameters CD1_1 CD1_2
								CD2_1 CD2_2
		in units of DEGREES/PIXEL
	CRPIX - 2 element vector giving X and Y coord of reference pixel
		BE SURE THE COORDINATES IN CRPIX ARE GIVEN IN FORTRAN STANDARD
		(E.G. FIRST PIXEL IN IMAGE IS (1,1) )
	CRVAL - 2 element vector giving R.A. and DEC of reference pixel 
		in degrees

 OUTPUTS:
	HDR - FITS header now contains the updated astrometry parameters
		A brief HISTORY record is also added.

 OPTIONAL KEYWORD INPUTS:
	EQUINOX - scalar giving equinox (e.g. 1950) of the reference 
		coordinates 

	CD_TYPE - Scalar, either 0, 1 , or 2 specifying how the CD matrix
		is to be written into the header
		(0) as CD00n00m values 
		(1) convert to rotation and write as a CROTA2 value
		(2) as CDn_m value
		Method 0 is the preferred use suggested
		in the document "Representations of Celestial Coordinates in
		FITS" by Griesen and Calabretta.   If CD_TYPE is not supplied
		PUTAST will try to determined the type of astrometry already
		in the header.   If there is no astrometry in the header then
		the default is CD_TYPE = 0
 NOTES:
	The recommended use of this procedure is to supply an astrometry
	structure.    

 PROMPTS:
	If only a header is supplied, the user will be prompted for a plate 
	scale, the X and Y coordinates of a reference pixel, the RA and
	DEC of the reference pixel, the equinox of the RA and Dec and a 
	rotation angle.

 PROCEDURES USED:
	ZPARCHECK, DATATYPE, SXADDPAR, GETOPT
 REVISION HISTORY
	Written by W. Landsman 9-3-87
	Major rewrite, use new astrometry structure   March, 1994

(See /usr/local/idl/lib/zastron/astrom/putast.pro)


STARAST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	STARAST 
 PURPOSE:
	Compute an exact astrometry solution using the positions and
	coordinates from 2 or 3 reference stars.   If 2 stars are used, then
	the X and Y plate scales are assumed to be identical, and the
	axis are assumed to be orthogonal.   Use of three stars will
	allow a unique determination of each element of the CD matrix.

 CALLING SEQUENCE:
	starast, ra, dec, x, y, cd

 INPUTS:
	RA - 2 or 3 element vector containing the Right Ascension in DEGREES
	DEC- 2 or 3 element vector containing the Declination in DEGREES
	X -  2 or 3 element vector giving the X position of reference stars
	Y -  2 or 3 element vector giving the Y position of reference stars
 OUTPUTS:
	CD - CD (Coordinate Description) matrix (DEGREES/PIXEL) determined 
		from stellar positions and coordinates.  
 EXAMPLE:
        To use STARAST to add astrometry to a FITS header H;

        IDL> starast,ra,dec,x,y,cd 	  ;Determine CD matrix
        IDL> crval = [ra(0),dec(0)] 	  ;Use Star 0 as reference star
        IDL> crpix = [x(0),y(0)] +1      ;Include SDAS pixel offset
        IDL> putast,H,cd,crpix,crval     ;Add parameters to header

 METHOD:
	The CD parameters are determined by solving the linear set of equations
	relating position to local coordinates (l,m)
 REVISION HISTORY:
	Written, W. Landsman             January 1988

(See /usr/local/idl/lib/zastron/astrom/starast.pro)


XY2AD

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	XY2AD

 PURPOSE:
	Compute R.A. and Dec in radians from X and Y and the plate
	solutions in six-parameter format.  A tangent (gnomonic) projection is
	computed directly; other projections are computed using WCSXY2SPH.
	XY2AD is meant to be used internal to other procedures.  For interactive
	purposes use XYAD.

 CALLING SEQUENCE:
	XY2AD, x, y, astr, a, d   

 INPUTS:
	X     - row position in pixels, scalar or vector
	Y     - column position in pixels, scalar or vector
	ASTR - astrometry structure, output from EXTAST procedure containing:
   	 .CD   -  2 x 2 array containing the astrometry parameters CD1_1 CD1_2
		in DEGREES/PIXEL                                   CD2_1 CD2_2
	 .CDELT - 2 element vector giving physical increment at reference pixel
	 .CRPIX - 2 element vector giving X and Y coordinates of reference pixel
		(def = NAXIS/2)
	 .CRVAL - 2 element vector giving R.A. and DEC of reference pixel 
		in DEGREES
	 .CTYPE - 2 element vector giving projection types 
	 .LONGPOLE - scalar longitude of north pole (default = 180) 
        .PROJP1 - Scalar parameter needed in some projections
	 .PROJP2 - Scalar parameter needed in some projections

 OUTPUT:
	A - R.A. in DEGREES, same number of elements as X and Y
	D - Dec. in DEGREES, same number of elements as X and Y

 RESTRICTIONS:
	Note that all angles must be in radians, including CD and CRVAL
	Also note that the CRPIX keyword assumes an SDAS-FORTRAN type
	array beginning at (1,1), while X and Y give the IDL position
	beginning at (0,0).
	No parameter checking is performed.

 REVISION HISTORY:
	Written by R. Cornett, SASC Tech., 4/7/86
	Converted to IDL by B. Boothman, SASC Tech., 4/21/86

(See /usr/local/idl/lib/zastron/astrom/xy2ad.pro)


XYAD

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	XYAD
 PURPOSE:
	Use astrometry in a FITS image header to compute R.A. and Dec in decimal
	degrees from X and Y.  

 CALLING SEQUENCE:
	XYAD, HDR		;Prompt for X and Y positions
	XYAD, HDR, X, Y, A, D

 INPUTS:
	HDR - FITS Image header containing astrometry info

 OPTIONAL INPUTS:
	X     - row position in pixels, scalar or vector
	Y     - column position in pixels, scalar or vector

	X and Y should be in IDL convention, (first pixel is (0,0)).

 OPTIONAL OUTPUT:
	A - Right ascension in decimal DEGREES, same number of elements as
		X and Y
	D - Declination in decimal DEGREES

 NOTES:
	If less than 5 parameters are supplied, or /PRINT is set, then
	then RA and Dec is printed in both decimal and sexigesimal format

	If this procedure is to be used repeatedly with the same header,
	then it would be faster to use XY2AD.

 REVISION HISTORY:
	W. Landsman                 STX          January,1988

(See /usr/local/idl/lib/zastron/astrom/xyad.pro)


XYXY

[Previous Routine] [List of Routines]
 NAME:
	XYXY
 PURPOSE:
	To use a pair of headers to convert X/Y positions from one frame
	to another.
 CALLING SEQUENCE:
	xyxy, hdra, hdrb, xa, ya, [ xb, yb ]
 INPUTS:
	hdra - The header containing the plate solution describing the
	       frame of reference being converted FROM.
	hdra - The header containing the plate solution describing the
	       frame of reference being converted TO.
	xa   - A scalar or vector containing the x coordinate(s) to convert.
	ya   - A scalar or vector containing the y coordinate(s) to convert.
	       Must have the same number of elements as 'xa'.
 OUTPUTS:
	xb   - The converted x coordinate(s).  If this parameter is not
	       specified, it is returned through 'xa'.
	yb   - The converted y coordinate(s).  If this parameter is not
	       specified, it is returned through 'ya'.
 PROCEDURE:
	The MOUSSE procedures 'xyad' and 'adxy' are used to perform the 
       conversion.     The equinoxes of each header are checked with
       "get_equinox" to make sure that they are identical, and "precess"
       is used if they are not
 MODIFICATION HISTORY:
	Written by Michael R. Greason, Hughes-STX, 13 April 1992.
	Updated to use ASTROMETRY structures.  J.D.Offenberg, HSTX, Jan 1993

(See /usr/local/idl/lib/zastron/astrom/xyxy.pro)