% epic01_Rscldar_5  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
%
close all
clear
load samos

iv = 1.5;   % est of total col water vapor for Seattle on JD 354

jjx = 1;
qrat=4.;
latd = 47.65; % Seattle
lond = -122.4;
k1 = .05;                  %aerosol optical depth, band 1
k2 = .05;                  %aerosol optical depth, band 2
oz = 0.2;                  %column ozone
%%%%%% DEW 12262007

Rhvais = samos(:,5);
Tvais = samos(:,2);
p = mean(samos(:,11));
jdys = samos(:,1);
qvais=Rhvais./100.*qsea(Tvais);
%%%%
%function y=qsea(x)
%es=6.112.*exp(17.502.*x./(x+241.0))*.98*(1.0007+3.46e-6*1010);
%y=es*622./(1010.0-.378*es);
%%%%
%QA_mean=[QA_mean qvais];
%qa=QA_mean(1:jjx);


watvap(1:length(jdys),1)=iv;
%ii=find(isnan(iv));
%watvap(ii)=qa(ii)/qrat;%total column water vapor

jdx=floor(jdys+.5/60/24); %julian day in bin centers for 10-min aves


tutc=(jdys+5/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(latd,lond,jdx,tutc,watvap,p,k1,k2,oz);
Rscl=sw;
%plot(jdy,Rscl,jdy,rs,'o');xlabel('Julian Day (1999)');ylabel('Downward Solar Flux (W/m^2)');
%ss=stdt;axis([ss endt 0 1200]);

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

plot(jdys,Rscl)
        hold
        plot(samos(:,1),samos(:,16),'g')
        title('USCGC Healy')
        ylabel('SW (W/m2')
        xlabel('Year Day (UTC)')
        legend('Clear','Healy')
        mmin = min(samos(:,16));
        mmax = max(samos(:,16));
        ylim([min(mmin)-25 max((mmax)+ 25)]);
