
PRO eis_dens_slice, dens, xpix=xpix, ypix=ypix, _extra=_extra, coldepth=coldepth, $
                    arcsec=arcsec

;+
; NAME
;
;      EIS_DENS_SLICE
;
; PROJECT
;
;      Hinode/EIS
;
; EXPLANATION
;
;      Takes the density structure produced by eis_density and allows
;      the user to plot a slice through the 2D data array, showing the
;      density values and errors.
;
; INPUTS
;
;      DENS     A structure containing density information as output
;               by the routine eis_density.pro.
;
; OPTIONAL INPUTS
;
;      XPIX     Specifies the X-pixel for which density slice is
;               required. 
;
;      YPIX     Specifies the Y-pixel for which density slice is
;               required. 
;
;      All of the optional inputs and keywords of the IDL plot command
;      are also allowed (xtitle=, charsize=, /xsty, etc.)
;
; KEYWORDS
;
;      COLDEPTH  If set, then the column depth is plotted instead of
;                the density.
;
;      ARCSEC    If /COLDEPTH is set, then /ARCSEC plots the column
;                depth in arcsec.
;
; OUTPUTS
;
;      Plots the density slice to a graphics window. Error bars are
;      assigned to each density value.
;
; HISTORY
;
;      Ver.1, 18-Mar-2010, Peter Young
;      Ver.2, 11-Aug-2010, Peter Young
;        added /COLDEPTH keyword
;      Ver.3, 6-May-2011, Peter Young
;        now plots error bars on coldepth
;      Ver.4, 8-Oct-2014, Peter Young
;        added /arcsec option.
;-

IF n_params() LT 1 THEN BEGIN
  print,'Use:  IDL> eis_dens_slice, dens [, xpix=, ypix= ]'
  return
ENDIF 

IF n_elements(xpix) EQ 0 AND n_elements(ypix) EQ 0 THEN BEGIN
  print,'%EIS_DENS_SLICE: please specify either an X-pixel or a Y-pixel using one of the '
  print,'                 XPIX= or YPIX= keywords.'
  return
ENDIF 

IF n_elements(xpix) NE 0 THEN BEGIN
  dd=reform(dens.ldens[xpix,*])
  du=reform(dens.hi[xpix,*])
  dl=reform(dens.lo[xpix,*])
  cd=reform(dens.coldepth[xpix,*])
  cde=reform(dens.coldepth_err[xpix,*])
  xtit='Y-pixel number'
ENDIF ELSE BEGIN
  dd=reform(dens.ldens[*,ypix])
  du=reform(dens.hi[*,ypix])
  dl=reform(dens.lo[*,ypix])
  cd=reform(dens.coldepth[*,ypix])
  cde=reform(dens.coldepth_err[*,ypix])
 ;
  xtit='X-pixel number'
ENDELSE 


siz=size(dd)
n=siz[1]

IF keyword_set(coldepth) THEN BEGIN
  IF keyword_set(arcsec) THEN BEGIN
    cd=cd*dens.arcsec
    cde=cde*dens.arcsec
    ytitle='Column depth / arcsec'
  ENDIF ELSE BEGIN
    ytitle='Column depth / cm'
  ENDELSE 
 ;
  ploterr,findgen(n),cd,cde,/xsty, $
       ytit=ytitle, $
       xtit=xtit,_extra=_extra,psym=1
ENDIF ELSE BEGIN
  mindl=min(dl[where(dl NE dens.missing)])
  maxdu=max(du[where(du NE dens.missing)])
  yrange=[mindl,maxdu]
  plot,/nodata,[0,n],yrange,/xsty,/ynozero, $
       ytit='Log!d10!n ( Density / cm!u-3!n )', $
       xtit=xtit,_extra=_extra
 ;
  FOR i=0,n-1 DO BEGIN
    plots,i,dd[i],psym=1
    oplot,[i,i],[dl[i],du[i]]
  ENDFOR
ENDELSE 


END
