clear all
close all
clc

load('zw_data');
load('wind_data')

maand = 1:12;
jj = 0;

for i = 1:length(zw_data.naam)
    for j = 1:length(maand)
        jj = jj + 1;
        clear ind1 dum1 dum2 dum3 dum4 dum5 sdate edate jaar
        dum1 = [zw_data.t{i}];
        dum2 = [zw_data.zw{i}];
        %%%
        dum3 = [wind_data.t{i}];
        dum4 = [wind_data.V{i}];        
        dum5 = [wind_data.theta{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);
        ind2 = find(dum3 >= sdate & dum3 < edate);
        data.naam(jj) = zw_data.naam(i);
        data.begin(jj) = {sdate};
        data.einde(jj) = {edate};
        data.jaar(jj) = {jaar};
        data.maand(jj) = {num2str(maand(j),'%02.0f')};
        data.dag(jj) = {dum1(ind1)};
        data.zw(jj) = {dum2(ind1)};
        data.dag2(jj) = {dum3(ind2)};
        data.V(jj) = {dum4(ind2)};
        data.theta(jj) = {dum5(ind2)};        
    end
end

%Stormen
clear ind
i = 23%10, 11, 13, 13, 14, 21, 23, 23

Vdum = data.V{i};
Thetadum = data.theta{i};
[dum ind] = find(Vdum >= 17.2);
ind*10/60/24
jj1 = 4;%1, 2, 1, 7, 1, 1, 1, 4
jj2 = 9;%3, 9, 6, 10, 2, 4, 3, 9
ind2a = round(ind(jj1)/3)
ind2b = round(ind(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 = wind_data.theta{2};
V = wind_data.V{2};

figure
wind_rose(Angle,V,'lablegend','V_{wind} (m/s)')
hold on
title('Marollegat')
saveas(gcf,'windroos.eps','psc2')


% 
% for i = 1:0.5*length(data.naam)
%     figure
%     subplot(3,1,1)
%     plot(data.dag{i},data.zw{i},'k-')
%     hold on
%     grid on
%     plot(data.dag{i+24},data.zw{i+24},'r-')
%     %xlabel('dag')
%     ylabel('z_w (m NAP)')
%     xData = data.begin{i}:2:data.einde{i};        
%     set(gca,'XTick',xData);
%     datetick('x','dd','keepticks')
%     ylim([-3 3])
%     set(gca,'ytick',[-3:1.5:3])        
%     title(['Getij- en windcondities, ',datestr(data.begin{i},'mmmm yyyy')]);
% 
%     subplot(3,1,2)
%     plot(data.dag2{i},data.V{i},'k-')
%     hold on
%     grid on
%     plot(data.dag2{i+24},data.V{i+24},'r-')
%     %xlabel('dag')
%     ylabel('V_{wind} (m/s)')
%     xData = data.begin{i}:2:data.einde{i};        
%     set(gca,'XTick',xData);
%     datetick('x','dd','keepticks')
%     ylim([0 25])
%     set(gca,'ytick',[0:5:25])    
%     %title(['Getij- en windcondities, ',datestr(data.begin{i},'mmm-yyyy')]);    
% 
%     subplot(3,1,3)
%     plot(data.dag2{i},data.theta{i},'k-')
%     hold on
%     grid on
%     plot(data.dag2{i+24},data.theta{i+24},'r-')
%     xlabel('dag')
%     ylabel('\theta_{wind} (^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\getij-wind_',datestr(data.begin{i},'yyyy-mm'),'.eps'],'psc2')
%     saveas(gcf,['PNG\getij-wind_',datestr(data.begin{i},'yyyy-mm'),'.png'])
% end
% close all
