function Fn = calc_fn(sdn, lat, lon, lambda)
% CALC_FN   - Calculate solar normalizing factor for water-leaving radiance
%
% Use as: Fn = calc_fn(sdn, lat, lon, lambda)
%
% Inputs: sdn    = GMT Date in matlab's date format (see DATENUM)
%         lat    = Decimal degrees latitude of the mooring (+N -S)
%         lon    = Decimal degrees longitude of the mooring (-W +E)
%         lambda = wavelength of measurement (nm)
%
% Output: Fn = normalizing factor such that Lwn = Lw/Fn

% Brian Schlining
% 15 Mar 2000

[r c] = size(lat);
if r == 1 & c == 1 & length(sdn) > 1
   lat = ones(size(sdn))* lat;   
end

[r c] = size(lon);
if r == 1 & c == 1 & length(sdn) > 1
   lon = ones(size(sdn))* lon;   
end


DayOfYear = date2jul(sdn);
[Year Month Day Hour Minute Second] = datevec(sdn);

Zenith = solarzenith(sdn, lat, lon);

Tr     = tauray1_(lambda);                         % Tau Raleigh
for i = 1:length(sdn)
   Toz    = tauozon_(0.034, [lat(i) -lon(i) DayOfYear(i)]);    % Tau Ozone   
end

t      = exp(-(Tr/2 + Toz)./cos(deg2rad(Zenith))); % Diffuse Atmospheric attenuation
Rho    = fresnel_(Zenith);                         % Fresnel reflectance
r      = 1./(1 + 0.0167*cos(deg2rad((DayOfYear - 3))/365));  % Earth-Sun distance

Fn = t.*(1-Rho).*cos(deg2rad(Zenith))./r.^2;