clear

%%% sediment concentration
C=load('D:\Projects\Z4573_Eems-Dollard\data\meetpaal\rsl90w44_49.txt');
[rij,kol]=size(C);
C2(1:rij,1:kol-5)=NaN;
count=0;
for tims=1:rij;
    count=count+1;
    yearday=num2str(C(tims,1));
    year=str2num(['19' yearday(1:2)]);
    datenum_yearday=doy2date(str2num(yearday(3:5)),year);
    hourmin=num2str(C(tims,2));
    if length(hourmin)==3
        hourmin=['0' hourmin];
    end
    if length(hourmin)==2
        hourmin=['00' hourmin];
    end
    if length(hourmin)==1
        hourmin=['000' hourmin];
    end
    hour=str2num(hourmin(1:2));
    min=str2num(hourmin(3:4));
    datenum_total=datenum_yearday+datenum(0,0,0,hour,min,0);
   % datestr(datenum_total)
   C2(count,1)=datenum_total;
   C2(count,2:end)=C(count,7:end);
    %pause
end
f=find(C2(:,2)==32767);
C2(f,:)=[];
C2(:,1)=C2(:,1)+1;% compensatie voor foutje ergens Julian day correctie

% figure
% plot(C2(:,1),C2(:,2),'color',[0 0 0]),hold on
% 
% plot(C2(:,1),C2(:,3),'color',[0 .25 1]),hold on
% plot(C2(:,1),C2(:,4),'color',[0 .5 1]),hold on
% plot(C2(:,1),C2(:,5),'color',[0 .75 1]),hold on



U=load('D:\Projects\Z4573_Eems-Dollard\data\meetpaal\rst90w44_49.txt');
[rij,kol]=size(U);
U2(1:rij,1:kol-1)=NaN;
count=0;
for tims=1:rij;
    count=count+1;
    yearday=num2str(U(tims,1));
    year=str2num(['19' yearday(1:2)]);
    datenum_yearday=doy2date(str2num(yearday(3:5)),year);
    hourmin=num2str(U(tims,2));
    if length(hourmin)==3
        hourmin=['0' hourmin];
    end
    if length(hourmin)==2
        hourmin=['00' hourmin];
    end
    if length(hourmin)==1
        hourmin=['000' hourmin];
    end
    hour=str2num(hourmin(1:2));
    min=str2num(hourmin(3:4));
    datenum_total=datenum_yearday+datenum(0,0,0,hour,min,0);
   % datestr(datenum_total)
   U2(count,1)=datenum_total;
   U2(count,2:end)=U(count,3:end);
    %pause
end
f=find(U2(:,2)==32767);
U2(f,:)=[];
U2(:,1)=U2(:,1)+1;% compensatie voor foutje ergens Julian day correctie
% figure
% plot(U2(:,1),U2(:,2),'color',[0 0 0]),hold on
% 
% plot(U2(:,1),U2(:,4),'color',[0 .25 1]),hold on
% plot(U2(:,1),U2(:,6),'color',[0 .5 1]),hold on





 H_oe=load('P:\mcdata\OpenEarthRawData\rijkswaterstaat\waterbase\cache\sea_surface_height\id1-DELFZL-179805240000-200907100000.txt.mat');
 t_oe=H_oe.data.datenum';
 h_oe=H_oe.data.sea_surface_height';
 
f1=find(t_oe==datenum(1990, 1,1,0,0,0));
f2=find(t_oe==datenum(1990, 12,31,23,50,0));

h=h_oe(f1:f2);
t=t_oe(f1:f2);
 [TIDESTRUC,h_out]=T_TIDE(h,'interval',1/6);


%%%%%% plot results
T0=round(C2(1,1));
Tend=C2(end,1);
C2(:,2:end)=C2(:,2:end)/1000;
for tims=T0:7:Tend;
    figure
    set(gcf,'PaperUnits','centimeters','PaperOrientation','landscape','papertype','A4','paperposition',[1 1 27 19])
    set(gcf,'renderer','zbuffer')
    axes('position',[.1 .7 .8 .27])
    plot(t,h,'--r'),hold on
    plot(t,h_out,'k','linewidth',1),hold on
    
    %plot(H(:,1),H(:,2)/100);
    set(gca,'xlim',[tims (tims+7)],'xtick',[tims:1:(tims+7)],'xticklabel',[],'ylim',[-2 3],'ytick',[-2:1:3])
    ylabel('H Delfzijl [m +NAP]')
    %datetick('x','mm/dd','keepticks','keeplimits')
    %xlabel('days 1990')
    grid on
    
    axes('position',[.1 .4 .8 .27])
plot(U2(:,1),U2(:,2),'color',[0 0 0]),hold on
plot(U2(:,1),U2(:,4),'color',[0 .25 1]),hold on
plot(U2(:,1),U2(:,6),'color',[0 .5 1]),hold on
    set(gca,'xlim',[tims (tims+7)],'xtick',[tims:1:(tims+7)],'ylim',[0 1.2],'xticklabel',[])
    ylabel('U [m/s]')
    grid on

    %datetick('x','mm/dd','keepticks','keeplimits')
    axes('position',[.1 .1 .8 .27])
    plot(C2(:,1),C2(:,2),'color',[0 0 0]),hold on

plot(C2(:,1),C2(:,3),'color',[0 .25 1]),hold on
plot(C2(:,1),C2(:,4),'color',[0 .5 1]),hold on
plot(C2(:,1),C2(:,5),'color',[0 .75 1]),hold on

    set(gca,'xlim',[tims (tims+7)],'xtick',[tims:1:(tims+7)],'ylim',[0 0.6])
        datetick('x','mm/dd','keepticks','keeplimits')
ylabel('C [g/l]')
grid on
    xlabel('month/day 1990')

FileOut=['FGpole_T_' datestr(tims,30)]
    eval(['print ' FileOut ' -dpng'])
end











%save 'D:\Projects\Z4573_Eems-Dollard\plot\eems_water levels_Koos' H;

% figure
% plot(H(:,1),H(:,2))
% datetick('x')
% 
%         


