;+
; NAME:
;       plotfis
; PURPOSE:
;      plot images or spectra from FIS files
; CALLING SEQUENCE:
;      plotfis,x,y,img=img,bin=bin,/nobkg,/cont,/flux
; INPUTS:
;       none - prompts for FIS image filename
; OPTIONAL OUTPUTS:
;       x =  wavelength array
;       y =  spectrum array (counts per sec per address bin)
; KEYWORDS:
;       img = structure with image parameters
;       /flux  = flux calibrate count rate spectrum
;       /nobkg = do not subtract background from data
;       /cont  = plot image as contour
;        bin   = value by which to rebin image or spectrum 
;                (e.g. bin=2 to double bin)
; MODIFICATION HISTORY:     
;      DMZ (ARC) Mar'92
;-

pro plotfis,x,y,img=img,bin=bin,nobkg=nobkg,cont=cont,flux=flux,$
        plabels=plabels

common fis_stuff,fileheader,sdb,idb,roadmap,fname

common last_type,ptype
if n_elements(ptype) eq 0 then ptype='I'
hard=0 
if keyword_set(flux) then wave=1 else wave=0

forever=0
repeat begin

;-- read data

 if not hard then begin
  print,'* plot images [I] or spectra [S] - def = '+ptype
  btype='' & read,'---> ',btype
  if btype ne '' then ptype=strupcase(strmid(btype,0,1))
  if ptype eq 'I' then begin
   rdfis,img,chnum,nobkg=nobkg 
  endif else begin
   xtitle='ADDRESS' & ytitle='COUNTS PER SEC PER ADDRESS'
   getfis,file & rd_sdb,sdb,spcnum,chnum
   rdfis_spec,sdb(spcnum),chnum,x,y,step,plabels=plabels,flux=flux,wave=wave
   if wave then xtitle='ANGSTROM'
   if keyword_set(flux) then ytitle='PH CM-2 S-1 A-1'
  endelse
 endif

;-- plot data
 
 if ptype eq 'I' then plotmap,img,hard=hard,bin=bin,grid=10,cont=cont else begin
  if hard then set_hard
  plotspec,x,y,bin=bin,xtitle=xtitle,ytitle=ytitle,psym=10,$
          title='CHAN: '+string(fix(chnum),'(i1)')+' '+plabels(0)
  if hard then set_hard,plabels,/send
 endelse

;-- hard copy?

 if not hard then begin
  hard='' & read,'* hard copy [def=N]? ',hard
  hard=strupcase(strmid(hard,0,1))
  if hard eq 'Y' then hard=1 else hard=0
 endif else hard=0

 if not hard then begin
  again='' & read,'* another plot [def=N]? ',again
  again=strupcase(strmid(again,0,1))
  if again ne 'Y' then forever=1
 endif

endrep until forever

return & end