FUNCTION DICal_RotCalImg, img, inst, calHdr

;;-----------------------------------------------------------------------------
;; PURPOSE:
;;	Rotates the calibration image so that it lines up with the image from
;;	the spacecraft. 
;;
;; CALLING SEQUENCE:
;;	RESULT = DICal_RotCalImg(img, inst)
;;
;; REQUIRED INPUTS:
;;	img - The calibration image to rotate
;;	inst - String specifying the instrument for this image
;;	calHdr - The FITS header for the calibration file. Must contain the 
;;		MSNCONFG keyword or an error will be thrown.
;;
;; OUTPUTS:
;;	RETURN -the calibration image after it has been rotated so that it lines
;;		up with the image from the spacecraft
;;
;; OPTIONAL INPUT KEYWORDS:
;;
;; EXAMPLE:
;;      IDL> imgOut = DICal_RotCalImg(img, inst, calHdr)
;;
;; PROCEDURES USED (i.e. called directly!):
;;
;; MODIFICATION HISTORY:
;;   2005-01-27  M. Desnoyer    Created
;;   2005-02-24  M. Desnoyer    Added need to differentiate between calibrations
;;				from ground and flight.
;;
;;-----------------------------------------------------------------------------

;; Determine if the calibration was done on the ground
msncnfg = sxpar(calHdr,'MSNCONFG',count=c)

IF c EQ 0 THEN message, 'Cannot determine source of calibration file'

;; Only perform rotations if the calibration file was ground based
IF strtrim(msncnfg,2) ne 'GROUNDCAL' THEN return, img

;; Set up the mapping from instrument name to the rotation needed
rotStruct = {rotmap, inst:'', rot:0}
rotMap = [{rotmap,	'HRIIR',	0}, $
	{rotmap,	'HRIVIS',	0}, $
	{rotmap,	'MRIVIS',	5}, $
	{rotmap,	'ITSVIS',	5} $
]

RETURN, rotate(img, rotMap[where(strtrim(inst,2) EQ rotMap.inst)].rot)

END