clear all
close all
clc

load('wr_data')

maand = 1:12;
jj = 0;

for i = 1:length(wr_data.naam)
    for j = 1:length(maand)
        jj = jj + 1;
        clear ind1 dum1 dum2 dum3 dum4 dum5 sdate edate jaar
        dum1 = [wr_data.t{i}];
        dum2 = [wr_data.Hs{i}];
        %%%
        dum3 = [wr_data.Tp{i}];
        dum4 = [wr_data.Ts{i}];        
        dum5 = [wr_data.angle{i}];        
        %%%
        jaar = datestr(dum1(1),'yyyy'); 
        sdate = datenum(['01-',num2str(maand(j),'%02.0f'),'-',jaar],'dd-mm-yyyy');
        if maand(j)~= 12
            edate = datenum(['01-',num2str(maand(j+1),'%02.0f'),'-',jaar],'dd-mm-yyyy');
        else
            edate = datenum(['31-',num2str(maand(j),'%02.0f'),'-',jaar],'dd-mm-yyyy')+1;
        end
        ind1 = find(dum1 >= sdate & dum1 < edate);
        data.naam(jj) = wr_data.naam(i);
        data.begin(jj) = {sdate};
        data.einde(jj) = {edate};
        data.jaar(jj) = {jaar};
        data.maand(jj) = {num2str(maand(j),'%02.0f')};
        if ~isempty(ind1)
            data.dag(jj) = {dum1(ind1)};
            data.Hs(jj) = {dum2(ind1)};
            data.Tp(jj) = {dum3(ind1)};
            data.Ts(jj) = {dum4(ind1)};        
            data.angle(jj) = {dum5(ind1)};
        else
            data.dag(jj) = {NaN};
            data.Hs(jj) = {NaN};
            data.Tp(jj) = {NaN};
            data.Ts(jj) = {NaN};              
            data.angle(jj) = {NaN};            
        end
    end
end


%0.4236    0.6042    0.6111

% %Stormen
% clear ind
% i = 23;%10, 11, 13, 13, 14, 21, 23, 23
% 
% jj1 = 838;%20, 979, 890, 1084, 456, 116, 665, 838
% jj2 = 841;%29, 1001, 892, 1093, 457, 124, 666, 841
% 
% Hdum = data.Hs{i};
% Thetadum = data.angle{i};
% Tsdum = data.Ts{i};
% H = nanmean(Hdum(jj1:jj2))
% Ts = nanmean(Tsdum(jj1:jj2))
% Theta = nanmean(Thetadum(jj1:jj2))

% [dum ind] = find(Vdum >= 17.2);
% ind*10/60/24
% 
% jj1 = 1;
% jj2 = 3;
%V = Vdum(ind(jj1) : ind(jj2));
% Theta = Thetadum(ind(jj1) : ind(jj2));
% T = (ind(jj2) - ind(jj1))*10/60
% Thetamean = nanmean(Theta)
% Vmean = nanmean(V)

Angle = wr_data.angle{2};
Hs = wr_data.Hs{2};

figure
wind_rose(Angle,Hs,'lablegend','H_{1/3} (m)')
hold on
title('Waverider')
saveas(gcf,'golfroos.eps','psc2')
%print(h, '-dpsc2', 'golfroos');


length(find(Angle >= 90 & Angle <=180))
length(find(Angle >= 180 & Angle <=270))
length(find(Angle >= 270 & Angle <=360))

% for i = 1:length(data.naam)
%     figure
%     subplot(3,1,1)
%     plot(data.dag{i},data.Hs{i},'k-')
%     hold on
%     grid on
%     %plot(data.dag{i+24},data.Hs{i+24},'r-')
%     %xlabel('dag')
%     ylabel('H_{1/3} (m)')
%     xData = data.begin{i}:2:data.einde{i};        
%     set(gca,'XTick',xData);
%     datetick('x','dd','keepticks')
%     ylim([0 1.5])
%     set(gca,'ytick',[0:0.5:1.5])        
%     title(['Waverider, ',datestr(data.begin{i},'mmmm yyyy')]);
% 
%     subplot(3,1,2)
%     plot(data.dag{i},data.Ts{i},'k-')
%     hold on
%     grid on    
%     %xlabel('dag')
%     ylabel('T_{1/3} (s)')
%     xData = data.begin{i}:2:data.einde{i};        
%     set(gca,'XTick',xData);
%     datetick('x','dd','keepticks')
%     ylim([0 10])
%     set(gca,'ytick',[0:2.5:10])    
%     %title(['Getij- en windcondities, ',datestr(data.begin{i},'mmm-yyyy')]);    
% 
%     subplot(3,1,3)
%     plot(data.dag{i},data.angle{i},'k-')
%     hold on
%     grid on    
%     xlabel('dag')
%     ylabel('\theta_{golf} (^oN)')
%     xData = data.begin{i}:2:data.einde{i};        
%     set(gca,'XTick',xData);
%     datetick('x','dd','keepticks')
%     ylim([0 360])
%     set(gca,'ytick',[0:90:360])  
% %     %title(['Getij- en windcondities, ',datestr(data.begin{i},'mmm-yyyy')]);     
%     saveas(gcf,['EPS\wr_',datestr(data.begin{i},'yyyy-mm'),'.eps'],'psc2')
%     saveas(gcf,['PNG\wr_',datestr(data.begin{i},'yyyy-mm'),'.png'])
% end
% close all
