%The routine provide the output of ZPLee's QAA vs. 4 algorithm as published
%in:
%Lee et al., 2002,  Appl. Opt., 41, 5755-5772 and Lee et al., 2007, JGR.
%Assume input to be Rrs.
function [b_bp, a_phi, a_dg]=QAA4_MODIS(Rrs,a_w,bb_w)

g0=0.08945;
g1=0.1247;
a1=-1.191987001
a2=-1.230224187
a3=-0.36196048

wl=[412 440 490 530 550 670];

rrs=Rrs./(0.52+1.7*Rrs);
u=(-g0+sqrt(g0^2+4*g1*rrs))./(2*g1);
eta=2.2*(1-1.2*exp(-0.9*rrs(2)/rrs(5)));
Rrs_640=0.01*Rrs(5)+1.4*Rrs(6)-0.0005*Rrs(6)/Rrs(3);
chi=log10((Rrs(2)+Rrs(3))/(Rrs(5)+2*Rrs_640^2/Rrs(3)));
a_550=a_w(5)+10^(a1+a2*chi+a3*chi^2);
b_bp_550=u(5)*a_550/(1-u(5))-bb_w(5);
b_bp=b_bp_550*(550./wl).^eta;
a=(1-u').*(bb_w'+b_bp)./u';
S_adg=0.015;
xsi=exp(S_adg*(440-410));
zeta=0.71+0.06/(0.8+rrs(2)/rrs(5));
adg_440=((a(1)-zeta*a(2))-(a_w(1)-zeta*a_w(2)))/(xsi-zeta);
a_dg=adg_440*exp(-S_adg*(wl-440));
a_phi=a-a_w'-a_dg;

    