;******************************************************************************
;Make a plot illustrating the different quantities involved in
;calculating synthetic photometry for Spitzer.
;******************************************************************************

pro spitzer_synthphot_example

;Open and set up output postscript file.
set_plot, 'PS'

device, filename = 'spitzer_synthphot_example.ps', $
        /color, /cmyk, /inches, xoffset = 0.1, yoffset = 0.5, $
        xsize = 9, ysize = 5

!p.font = 0

device, /times

loadct, 12, /silent

plotsym, 0, 1, /fill 

;Draw the plot window.
xrange = [6.,10]

yrange = [0.2, 2.]

plot, xrange, yrange, thick = 5, xtit = textoidl('Wavelength (\mum)'), $
      ytit = textoidl('Relative f_{\nu}'), /ylog, xrange = xrange, $
      /xstyle, yrange = yrange, /ystyle, xthick = 5, ythick = 5, $
      /nodata

;Overplot the 8 micron filter curve as a thick grey line.
readcol, 'irac_tr4_2004-08-09.dat', filter_w, filter_t, format = '(d, d)', /silent

lambda_eff = 7.872 ;Define the effective wavelength of the filter.

norm = 1.0 / max(filter_t)

oplot, filter_w, filter_t * norm, color = 225, thick = 10

;Overplot the starburst spectrum as a thick black line.
readcol, 'starburst_average.txt', wave_sb, flux_sb, /silent

oplot, wave_sb, flux_sb, thick = 5

xyouts, 9.4, 0.4, 'Starburst'
 
;Figure out the color correction.
color_correction = spitzer_synthphot(wave_sb, flux_sb, filter_w, filter_t, 'IRAC', /colorcorr)

;Indicate fnu(lambda_eff) on the plot as a blue point.
linterp, wave_sb, flux_sb, lambda_eff, fnu_lambdaeff

plots, lambda_eff, fnu_lambdaeff, psym = 8, color = 100

plotsym, 0, 1, /fill

xyouts, lambda_eff + 0.1, fnu_lambdaeff - 0.02, $
        textoidl('f_{\nu}(\lambda_{eff})'), align = 0, color = 100

;Calculate fnu_Spitzer
fnu_Spitzer = color_correction * fnu_lambdaeff

;Draw a flat spectrum (the reference spectrum)
c = 2.99792458d8 * 1d6 ; microns/sec
lambda = varray(min(filter_w), max(filter_w), 1000.)
nu = c / lambda
normref = 0.079737993 / 2.7145456e-15
oplot, lambda, normref / nu, thick = 5, linestyle = 1
xyouts, 6.4, 0.65, textoidl(' \nu S_{\nu} = constant'), orient = 7.

;Indicate fnu_Spitzer
plots, lambda_eff, fnu_Spitzer, psym = 8, color = 200
xyouts, lambda_eff, fnu_Spitzer + 0.03, textoidl('f_{\nu}^{Spitzer}'), align = 0.5, color = 200

;Close output postscript file.
device, /close

end
