Pro Plot_are, x,modres,relres,en_xax,st_en,wmod,wrel,pl_iter, $
              rmod_amp,res,ct_mod,ct_rel,pl_range,do_color,xmax,$
              ped_are

; Program to plot Angular Response versus Energy for the 
; proposed HEISPEC Instrument
;
; Written by Eric Carzon, Hughes/STX
; June 1994
;
; 15-apr-1997, RAS, removed unwanted old lines of code

srmod_amp = strtrim(string(fix(rmod_amp)),2)
;c2mt = '!c with < '+srmod_amp+'% reduction in modulation amplitude'
mtitle = ' Angular Coverage vs. Photon Energy '   ;+c2mt
ytitle = ' Angular Coverage (arc seconds) '
xtitle = ' Energy (keV) '
yohx = fltarr(7,2)
yohy =fltarr(7,2)
hxisx = fltarr(2,2)
hxisy = fltarr(2,2)

for i = 0,6 do yohx(i,0:1) = [14.,93.]
yohy1 = [7.9,9.,10.5,12.6,15.75,21.,63.]
for i=0,6 do yohy(i,0:1) = [yohy1(i),yohy1(i)]
yotick = [14.,23.,33.,53.,93.]
yoticy = [63.,63.,63.,63.,63.]
hiny = [30., 30.]
hinx = [17.,40.]
hxisx(0,0:1) = [3.5,30.]
hxisx(1,0:1) = [3.5,30.]
hxisy(0,0:1) = [8.,8.]
hxisy(1,0:1) = [372.,372.]
hxtick = [3.5,5.5,8.,12.,16.,22.,30.]
hxticy = [372.,372.,372.,372.,372.,372.,372.]
usersym,[0,0],[0,2]
atick = findgen(9999)+1
btick = fltarr(9999)
for i=0,9998 do btick(i) = max(res)


linecolors
if (do_color ne 2) then orange = 4 else orange = 202
if (do_color ne 2) then red = 2 else red = 90
if (do_color ne 2) then blue = 11 else blue = 120
if (do_color ne 2) then green = 8 else green = 50
if (do_color ne 2) then pink = 3 else pink = 99
if (do_color ne 2) then purple = 13 else purple = 185
if (do_color ne 2) then olive = 6 else olive = 78

if (pl_iter eq 1) then begin


  plot_oo,[.1,.1],[.1,.1],xtitle=xtitle,ytitle=ytitle,title=mtitle,$
          yrange=[1,1000.],xrange=[1,xmax],charthick=4,charsize=1.5,$
          xmargin=[10,10],ymargin=[7,4]


  fillx= [3.5,3.5,30.,30.]
  filly=[8.0,372.,372.,8.0]
  !p.linestyle = 1
  polyfill,fillx,filly,/data,/line_fill,orientation=45,color=orange
  polyfill,fillx,filly,/data,/line_fill,orientation=-45,color=orange
  !p.linestyle = 0


  usersym,[0,0],[0,-2]
  xyouts,color=purple,/data,3.6,680.,'Yohkoh/SXT',charthick=3,charsize=1.3
  oplot,[1,3],[993,993],thick=9,color=purple
  oplot,[1,3],[993,993],psym=8,thick=3,color=purple
  fillx= [1,3,3,1]
  filly=[2.45,2.45,1000,1000]
  !p.linestyle=1
  polyfill,fillx,filly,/data,/line_fill,orientation=90,color=purple
  polyfill,fillx,filly,/data,/line_fill,orientation=180,color=purple
  !p.linestyle=0
  usersym,[0,0],[0,2]

  xyouts,color=red,/data,250,150,'HESI/HEISPEC',charthick=3,charsize=1.3

  xyouts,color=blue,/data,110,62,'Yohkoh/HXT',charthick=3,charsize=1.3
  for i=0,6 do  oplot,yohx(i,*),yohy(i,*),thick=7,color=blue
  oplot,yotick,yoticy,psym=8,thick=3,color=blue

  xyouts,color=green,/data,45,29.5,'Hinotori',charthick=3,charsize=1.3
  oplot,hinx,hiny,thick=7,color=green
  oplot,hinx,hiny,thick=3,color=green,psym=8

  xyouts,color=orange,/data,35,371.,'SMM/HXIS',charthick=3,charsize=1.3
  for i=1,1 do oplot,hxisx(i,0:1),hxisy(i,0:1),thick=7,color=orange
  oplot,hxtick,hxticy,psym=8,thick=3,color=orange

  if (ped_are eq 2) then begin
      ftime = .05
      edxmax = 10000
      xmark = [xmax,xmax]
      En_all = findgen(9908)+10.
      elec_dist = (ftime*(1.-(511./(En_all+511.))^2.)^.5)/.00484
      xyouts,/data,1200.,15.,'Electron distance!ctravelled in 50 ms',$
      charsize=1.2,charthick=2
      oplot,En_all,elec_dist,thick=8	;,color=olive
  endif

      xyouts,/data,1000.,6.,'High Resolution!c Spectroscopy',color=red,$
      charsize=1.3,charthick=3
      
endif 

  if (wmod(0) eq -1 or rmod_amp gt 95.) then begin
        ;print,'setting energy to 2.0'
        cfirst = 2.0 
        dfirst = res(pl_iter-1)
  endif else begin
        cfirst = (en_xax(st_en(wmod)) > 2.0)
        dfirst = modres
  endelse
  if (wrel(0) eq -1 or rmod_amp gt 95. or pl_iter eq 8) then begin
        if (rmod_amp lt 70.) then clast = 10000.
        dlast = res(pl_iter-1)
  endif else begin
        clast = x(wrel(0),0)*1000.
        dlast = relres
  endelse

  c = [cfirst,clast]
  d = [dfirst,dlast]

  if (wmod(0) ne -1 and rmod_amp lt 95.) then begin
     wmod_breakup = where((wmod - shift(wmod,1)) gt 1,ct_breakup)
     if (wmod_breakup(0) eq -1) then goto, continue_oplot


     if (rmod_amp gt 20 or pl_iter eq 2) then oplot, $
      [2.0,en_xax(st_en(wmod(0)))],[modres(0),modres(1)],color=red,thick=3 else $
      oplot,[en_xax(st_en(wmod(0))),en_xax(st_en(wmod(wmod_breakup(0))))],$
        [modres(0),modres(0)],color=red,thick=3

     if (ct_breakup gt 2) then oplot,[en_xax(st_en(wmod(wmod_breakup(0)))),$
          en_xax(st_en(wmod(wmod_breakup(1))))],$
          [modres(0),modres(0)],color=red,thick=3
     if (rmod_amp gt 20 and ct_breakup eq 2) then $
        oplot,[en_xax(st_en(wmod(0))),en_xax(st_en(wmod(wmod_breakup(0))))],$
         [modres(0),modres(0)],color=red,thick=3

     oplot,[en_xax(st_en(wmod(wmod_breakup(ct_breakup-1)))),clast(0)],$
        [d(0),d(0)],color=red,thick=3
     goto,heispec_ticks_test
  endif

continue_oplot: 
  ;print,'plotting heispec energy line #',pl_iter
  oplot,c,d,color=red,thick=3
 
heispec_ticks_test:
  if (pl_iter eq (pl_range(1)+1)) then begin
     oplot,atick(0:max(clast)-2),btick(0:max(clast)-2),psym=8,color=red
     plot_oo,/noerase,[.1,.1],[.1,.1],xtitle=xtitle,ytitle=ytitle,title=mtitle,$
          yrange=[1,1000.],xrange=[1,xmax],charthick=4,charsize=1.5,$
          xmargin=[10,10],ymargin=[7,4]

  endif

return
end
