;+
; NAME:   hxrs_fits2drm
;
;
; PURPOSE:  read a HXRS drm from a FITS file into a Spex-compatible form
;
;
; CATEGORY: SPEX, spectral analysis
;
;
; CALLING SEQUENCE:
;	examples
;
;	hxrs_fits2drm, file=file, sfile=scatter_file, edges_out=edges_out, $
;		edges_in=edges_in, area=area, drm=drm
;
;
; INPUTS:
;	file - name of FITS file to read
;	sfile - dummy input for spex compatibility
;
;
; OUTPUTS:
;	edges_out - energy edges of detector channels
;	edges_in - input energy bins
;	area - HXRS instrument area, cm^2.
;	drm - response matrix.  Dimensioned number of detector channels by
;		number of input energies.
;
;
; SIDE EFFECTS:
;	none
;
;
; RESTRICTIONS:
;	drm elements are assumed to have dimensions of counts/cm^2 per photon/cm^2.  The drm
;   elements will be divided by detector channel energy width (counts/cm^2/keV per photon/cm^2)
;	before being output.
;
;
; PROCEDURE:
;	none
;
;
; CALLS:
;	mrdfits
;
;
; WRITTEN:
;	Paul Bilodeau, NASA/GSFC LASP - RITSS, June 23,2000
;
;
; MODIFICATION HISTORY:
;-


PRO hxrs_fits2drm, file=file, sfile=scatter_file, edges_out=edges_out, $
	edges_in=edges_in, area=area, drm=drm

; HXRS area, cm^2
area=4.91

; read the response matrix extension
redist=mrdfits(file,1,h1)
drm=redist.matrix
n_in=n_elements(redist)
edges_in=fltarr(2,n_in)
edges_in[0,*]=redist[*].energ_lo
edges_in[1,*]=redist[*].energ_hi

; read the energy bounds extension
ebounds=mrdfits(file,2,h2)
n_out=n_elements(ebounds)
edges_out=fltarr(2,n_out)
edges_out[0,*]=ebounds[*].e_min
edges_out[1,*]=ebounds[*].e_max

; Divide the drm entries by the channel energy widths for spex compatibility
d_light=reform(edges_out[1,*]-edges_out[0,*])
for i=0, n_out-1 do drm[i,*]=drm[i,*]/d_light[i]

END