waveriderraw=load('D:\Desktop\Data\CRUISES\HiWinGS_2013\flux_data\Riegl_corrected\waverider\WR.rawtimeseriesHs_vf.mat');

if ddd==288
    waverider=load('D:\Desktop\Data\CRUISES\HiWinGS_2013\flux_data\Riegl_corrected\waverider\WR.stats2.mat');
    WR_doy=waveriderraw.RDT.R288.doy;WR_Hs=waveriderraw.RDT.R288.h;
    WR_f=waverider.stats2.f;WR_S=waverider.stats2.S;WR_doyS=waverider.stats2.doy;
elseif ddd==292
    waverider=load('D:\Desktop\Data\CRUISES\HiWinGS_2013\flux_data\Riegl_corrected\waverider\WR.stats3.mat');
    WR_doy=waveriderraw.RDT.R292.doy;WR_Hs=waveriderraw.RDT.R292.h;
    WR_f=waverider.stats3.f;WR_S=waverider.stats3.S;WR_doyS=waverider.stats3.doy;
end       


ii=find(WR_doy>=doy_all(1) & WR_doy<=doy_all(end));

figure;plot(WR_doy(ii),WR_Hs(ii))
Hs_raw=load(['D:\Desktop\Data\CRUISES\HiWinGS_2013\flux_data\Riegl_corrected\Riegl_waveplineinterpolatedtoheave_minusriegldplusheave_vcfrp\Wavecorrected_',jd hr,'.prn']);
dref=Hs_raw(:,1)+Hs_raw(:,2)/24+Hs_raw(:,3)/3600/24;
Hs=Hs_raw(:,end);
hold on;plot(dref,Hs,'g')

[SHsR,FHsR]=psd2(detrend(Hs),length(Hs),10,hamming(length(Hs)));[SHs1,FHs1]=specsmoo(SHsR,10); 
[SHsWR,FHsWR]=psd2(detrend(WR_Hs(ii)),length(WR_Hs(ii)),1.28,hamming(length(WR_Hs(ii))));[SHs2,FHs2]=specsmoo(SHsWR,1.28); 
figure;loglog(FHsR,FHsR.*SHsR,'--',FHsWR,FHsWR.*SHsWR,'g--')
hold on;loglog(FHs1,FHs1.*SHs1,FHs2,FHs2.*SHs2,'g','LineWidth',2);

% waverider=load('D:\Desktop\Data\CRUISES\HiWinGS_2013\flux_data\Riegl_corrected\waverider\WR.stats2.mat');
ii=find(WR_doyS>=doy_all(1) & WR_doyS<=doy_all(end));
hold on;loglog(WR_f(:,1),WR_f(:,1).*nanmedianx(WR_S(:,ii)')','k','LineWidth',2);

legend('Riegl raw','WR raw','Riegl smoothed','WR smoothed','WR matt median')
xlabel('Frequency (Hz)');ylabel('f*Sw(f)  (m^2)')
grid
title(sprintf('Wave Height PSD (%03i/%03i)',ddd,hhh))


[HsR,Tz,Te,Tpc]=Wavestatsfromspectra(SHsR,FHsR,diff(FHsR(1:2)));
[HsWR,Tz,Te,Tpc]=Wavestatsfromspectra(SHsWR,FHsWR,diff(FHsWR(1:2)));
[HsWRmatt,Tz,Te,Tpc]=Wavestatsfromspectra(nanmedianx(WR_S(:,ii)')',WR_f(:,1),diff(WR_f(1:2,1)));

[HsR HsWR HsWRmatt]



%look at 10min
Hs_raw=reshape(Hs,6000,6);
[SHs,FHs]=psd2(detrend(Hs_raw(:,lu)),length(Hs_raw(:,lu)),10,hamming(length(Hs_raw(:,lu))));[SHs2,FHs2]=specsmoo(SHs,10); 
loglog(Spectro_freq2(ll,:),Spectro_freq2(ll,:).*Spectro_Hs2(ll,:),'k');hold on



figure;semilogx(FHsR,4*sqrt(diff(FHsR(1:2)).*cumsum(SHsR)),'--',FHsWR,4*sqrt(diff(FHsWR(1:2)).*cumsum(SHsWR)),'g--')
hold on;semilogx(FHs1,4*sqrt(cumsum(([0 diff(FHs1)]).*SHs1)),FHs2,4*sqrt(cumsum(([0 diff(FHs2)]).*SHs2)),'g','LineWidth',2);
ii=find(WR_doyS>=doy_all(1) & WR_doyS<=doy_all(end));
hold on;semilogx(WR_f(:,1),4*sqrt(diff(WR_f(1:2,1)).*cumsum(nanmedianx(WR_S(:,ii)')')),'k','LineWidth',2);

legend('Riegl raw','WR raw','Riegl smoothed','WR smoothed','WR matt median')
xlabel('Frequency (Hz)');ylabel('f*Sw(f)  (m^2)')
grid
title(sprintf('Wave Height PSD (%03i/%03i)',ddd,hhh))

a=cumsum(SHs);a(end).*diff(FHs(1:2))