disp('diurnal_tst');
%************************  diurnal averages  ***********
clear

close all

load d:\temp\flux\dewrad
clear gd raind hnd ud hsd hld tsd tsgd jdd latd lond tad taud uxd uyd qsd qad

jj0=floor(jdq(1));%integer first day
jjm=ceil(jdq(length(jdq)));%integer last day
mx=jjm-jj0;jj=0;%number of days

jd0=floor(jdq);%integerized time series
jdf=jdq-jd0;%local time


dd=0:2:24;
dd=dd/24;  %Convert hr to decimal
jj=find(jd0>=stdt & jd0<=endt);

%
% For AMMA 2007 JD 123 abd 1/2 or JD 124, teh PSP and PIR are bad
%Loop through and and put in "0" for these periods DEW 5/20/2007
lj = length(jdq);
for p = 1:lj
    rsnew(p,1) = rs(p,1);
        if jdq(p,1) < 124.6
                rsct = p;
            rsnew(p,1) = 0;
        end
end
%rss = rs(rsct:lj,1)
%jdr = jdf(rsct:lj,1)
for i=1:12
    ii=find(jdf(jj)>=dd(i) & jdf(jj)<dd(i+1) & ~isnan(hsb(jj)));
    nn(i)=length(ii)
    jdd(i)=mean(jdf(jj(ii)));

   
    % DEW 5/20/2007
    rsd(i)=mean(rs(jj(ii)));
    rld(i)=mean(rl(jj(ii)));
    rnld(i)=mean(rlnet(jj(ii)));
    rsn(i)=mean(rsnew(jj(ii)));
    
    %%%%%%%%%%%%%%

end;

jdd1=jdd*24;

tit = ('AMMA 2007')

figure
plot(jdq,rs)
hold
plot(jdq,rsnew,'r.')

figure;
plot(jdd1,.95*rsd,'-o',jdd1,.95*rsclrd,'-',[0 24],[0 0 ]);
set(gca,'fontsize',14);
xlabel('Local Time of Day (hr)');
ylabel('Solar Heat Flux(W/m^-^2)');
ylim([-10000 1200])
title(tit)
set(gca,'fontsize',8);
legend('Measured','Modeled','location','Southeast')
%print_buffer = ['F:\AMMA_2007\RHB\flux\Processed_Images\AMMA07_FLUX_diurnal_Solarflux.jpg'];
%print('-djpeg90 ', print_buffer);

figure;
plot(jdd1,.95*rsn,'-o',jdd1,.95*rsclrd,'-');   %,[0 24],[0 0 ]);
set(gca,'fontsize',14);
xlabel('Local Time of Day (hr)');
ylabel('Solar Heat Flux(W/m^-^2)');
ylim([0 1200])
%title(tit)
set(gca,'fontsize',8);
legend('Measured New','Modeled','location','Northeast')


