% DYNAMO_2011_Rscldar  computes clear sky solar for ETL data
% jdy is julian day (decimal) at the start of average interval
% lat and lon are decimal latitude and longitude
% iv is column water vapor in cm
%   if no data is available for iv, put in NaN and select a ratio of iv to
%   near-surface water vapor mixing ratio, qrat.  Typical tropical value is
%   4.5
% calls SolarRadiance

qrat = 4.0;  % set ratio of column wat vap to surface value
p = nanmean1(press);  % pressure (mb)
% Specify aerosol amounts, these can be adjusted to fit peak noon values on
% clear day
k1 = .03;  % aerosol optical depth, band 1
k2 = .03;  % aerosol optical depth, band 2
%

oz = 0.2;  % column ozone
watvap = iv;
ii = find(isnan(iv));
watvap(ii) = qa(ii)/qrat;  % total column water vapor
jdx = floor(jdy+min_set/2/60/24);  % julian day in bin centers for aves of duration min_set

tutc = (jdy+min_set/60/24-jdx)*24;  % 0:1:23;  % hour of the day
[n m] = size(tutc);
clear sw sz saz dirs sky;
[sw,sz,saz,dirs,sky] = SolarRadiancex(Lat,Lon,jdx,tutc,watvap,p,k1,k2,oz);
Rscl = sw;

figure; plot(jdy,Rscl,jdy,rs,'o'); xlabel('Day-Of-Year (2014)');
ylabel('Downward Solar Flux (W/m^2)');
axis([stjd jdy(end) -5 1200]);

% sw = downward shortwave (W/m^2)
% sz = zenith angle
% saz = azimuth angle
% dirs is direct solar
% sky is diffuse solar
