; ==============================================
  pro calc_ratall,alb,ssa,cva,sza,ratall
; ==============================================
; Calculate RATALL indicator for a single pixel
; ----------------------------------------------

; Screen for negative albedo values first

neg= where(alb lt 0.,complement=pos)
if(neg[0] ne -1) then begin  
  if(n_elements(neg) eq n_elements(alb)) then begin  ; all negative points
     ratall=0.
     return
  endif else begin
     alb=alb(pos)
     ssa=ssa(pos)
     cva=cva(pos)
     sza=sza(pos)
  endelse
endif

; Check to see if there's anything here to work with.

ifor = where(ssa le 90.,n_for)
iback = where(ssa gt 90.,n_back)

if(n_for eq 0 or n_back eq 0) then begin
   ratall=0.
   return
endif

dat=alb*1.e-6
alt=sza_alt(sza)

mu1 = cos(cva / !radeg)
oomu2=chap(alt,sza,5) ;Z and H are arbitrary, as scale height ratio has not yet been calculated
mufac = mu1 * (1. / mu1 + oomu2)
rp=rayleigh_phase(ssa)
data_y = alog(mu1 * dat / rp)
data_x = alog(mufac / mu1)

fit = linfit(data_x, data_y)
line=fit[0]+data_x*fit[1]
rat=data_y/line

ratall = (total(rat[ifor])/float(n_for)) / (total(rat[iback])/float(n_back))

return
end
