pro fefit,f,lowlim,uplim,xy
@fe55setup

!psym=3 
!ytitle='DN'

if (xy eq 0) then fsub=f(*,0:ydepth) else fsub=f(bls:bls+xdepth,*)
a=feline(fsub,lowlim,uplim,xy)

!mtitle='Fe55 exposure (first '+strtrim(string(upto),2)+$
        ', every '+strtrim(string(dotskip),2)+'.)'

if xy eq 0 then begin
  x=findgen(clips+bls)
  y=a(bls:clips+bls-1)
  x=x(bls:clips+bls-1)
  w= y gt 0.
  !xtitle='Column'
  plot,indgen(n_elements(a)),f(1:*,0),yrange=[-50,200]
  for i=1,upto,dotskip do oplot,f(1:*,i)
endif else begin
  x=findgen(clipp)
  y=a(0:clipp-1)
  w= y gt 0.
  !xtitle='Row'
  plot,indgen(n_elements(a)),f(bls,*),yrange=[-50,200]
  for i=bls,upto+bls-1,dotskip do oplot,f(i,*)
endelse

c=fltarr(2)
c(0)=uplim(0)
c(1)=0.99995

yfit=curvefit(x,y,w,c,sigc)
;yfit=curvefit(x,y,w,c,sigc)
;yfit=curvefit(x,y,w,c,sigc)

oplot,x,yfit

!mtitle='Fit of single events line'
plot,indgen(n_elements(y)),y 
oplot,x,yfit

;c(1)=1.+c(1)/c(0)
xyouts,/normal,.6,.9-xy*.5,'CTE = '+strtrim(string(c(1)),2)+$
 ' +/- '+strtrim(string(sigc(1)),2)

;xyouts,100,0,'Considered range: '+$
;  strtrim(string(lowlim),2)+' - '+strtrim(string(uplim),2)

!noeras=0
!psym=0

end
