pro hxrs_response, edges_out=edges_out, edges_in=edges_in, area=area, drm=drm, dfile=dfile, $
    flux=flux, em_flux=em_flux, gain=gain, newflux=newflux, con_factors=con_factors, $
    un_con=un_con, error=error
;stop
error = 1 ;assume an error

if n_elements(area) eq 0 then area=4.91 ;cm^2

if n_elements(edges_out) eq 0 then edges_hxrs, edges_out

;NOMINAL FRACTIONAL UNCERTAINTY IN CONVERSION FACTORS
un_con = make_array(8,/float,value=0.05)

; Call resp_calc to get all quantities of interest
nflux=500
elo=10.
ehi=1000.
detector='NAI'
d=0.45
z=[13]
gmcm=.263
func='fwhm'
func_par=[1,00,.41,0]

; Get the drm defined on edges_in energies for both input and output sides
if n_elements(drm) eq 0 then begin
    resp_calc,detector,area,func,func_par,d,z,gmcm,nflux,elo,ehi,eloss_mat,pls_ht_mat,edges_in,tmp_drm

    ; interpolate the drm onto the final bins
    drm = x_eout_drm( in_drm=tmp_drm, in_e_out=edges_in, out_e_out=edges_out, nsub=20)
endif else resp_calc,detector,area,func,func_par,d,z,gmcm,nflux,elo,ehi,eloss_mat,pls_ht_mat,edges_in

; midpoint energies of energy-loss matrix
edge_products, eloss_mat, mean=em_matrix, width=ww_matrix

;SET THE DEFAULT INPUT FLUX ENERGIES
;the input matrix energies are the defaults for the input flux
;if em_flux isn't defined it is assumed to be on inmatrix energy mid-points
checkvar,em_flux, em_matrix

;!!!!!!!!!!!!!!!!!!!!!!
;IF A PHOTON FLUX HAS BEEN INPUT, APPLY THE RESPONSE MATRIX AND COMPUTE
;CONVERSION FACTORS. IF NOT, THEN JUST RETURN THE RESPONSE MATRIX.

if n_elements(flux) ne 0 then begin

    ;IF THE EM_FLUX ARE DIFFERENT FROM THE EM_MATRIX, INTERPOLATE FLUX TO EM_MATRIX
    wdiff = where(em_matrix - em_flux ne 0.0, ndiff)
    if total(abs(em_matrix-em_flux)) ne 0. then flux2 = interpol( flux, em_flux, em_matrix) else $
        flux2 = flux

    ;FROM PHOTON/CM2/SEC/KEV TO PHOTON/CM2/SEC
    phot_per_bin = flux2 * ww_matrix

    ;CALCULATE THE COUNT RATE IN THE 10 HXRS CHANNELS
    cnts_per_kevcm2 = drm#phot_per_bin

    ;EXPRESS IN UNITS OF COUNTS/CM2/SEC/KEV TO GET CONVERSION FACTORS

    newflux = interpol(flux,em_flux,emedges)
    con_factors = cnts_per_kevcm2 / newflux
endif

error = 0   ;success!
ERROR_RETURN:
return
end