pro fluxcal,rate,chan,add,flux,dopp=dopp,drift=drift,total=total,xtemp=xtemp

;-- some constants

 sqpi=sqrt(!pi) & clight=3.e5 
 conv=2.0*sqrt(alog(2.0))
 if n_elements(xtemp) eq 0 then xtemp=17.

;-- get rate

 if n_elements(rate) eq 0 then begin
  repeat begin
   rate='' & read,'* enter FCS line counts per second: ',rate
  endrep until (rate ne '')
  rate=float(rate)
 endif

;-- get channel 
  
 if n_elements(chan) eq 0 then begin
  repeat begin
   chan='' & read,'* enter FCS channel no [1-7]: ',chan & chan=fix(chan)
  endrep until ((chan le 7) and (chan ge 1))
 endif

;-- get address
  
 if n_elements(add) eq 0 then begin
  add='' & read,'* enter FCS XTAL address of observation [def=6563]: ',add
  if add eq '' then add=6563. else add=float(add)
 endif 

;-- get FCS detector parameters

 fcs_par,chan,add,disp,drock,darea,dref,dwave,xtemp=xtemp

;-- detector quantum efficiency (DQE)

 dqe=darea*dref         

;-- integrate Voigt function

 if keyword_set(total) then inten=rate else begin

  if n_elements(drift) eq 0 then begin
   drift=0.
   message,/info,'count rate is assumed to be at line peak'
  endif

  if n_elements(dopp) eq 0 then begin
   dopp='' & read,'* enter total line doppler width [def = 50 km/s]: ',dopp
   if dopp eq '' then dopp=50. else dopp=float(dopp)
  endif

  doppb=dwave*dopp/clight/disp   ;-- Doppler width in address units

  ddrift=replicate(drift/doppb,1) & aa=drock/conv/doppb/4./!pi
  z=voigt(aa,ddrift) 
  inten=sqpi*rate*doppb/z(0) 
 endelse 

;-- total FLUX (photons cm-2 s-1)

 flux=inten/dqe 

 if (n_params(0) eq 0) then $
  print,'* line flux (ph cm-2 s-1) = '+string(flux,'(g10.2)')

 return & end