function []= Mflat_output(rname)

%MFLAT_OUTPUT  Mflat_output plots output generated by Mflat.m 
%
%   Syntax:
%   varargout = Mflat_output(varargin)
%
%   Input:
%   varargin = runfile name
%
%   Output:
%   varargout = -
%
%   See also runMflat.m Mflat.m balanceM.m waveparamsM.m

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2019 IHE 
%       mvw
%
%       m.vanderwegn@un-ihe.org
%
%       IHE Delft Institute for Water Education,
%       PO Box 3015, 2601 DA Delft
%       The Netherlands
%
%   This library is free software: you can redistribute it and/or modify
%   it under the terms of the GNU General Public License as published by
%   the Free Software Foundation, either version 3 of the License, or
%   (at your option) any later version.
%
%   This library is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%   GNU General Public License for more details.
%
%   You should have received a copy of the GNU General Public License
%   along with this library.  If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://www.OpenEarth.eu">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute
% your own tools.

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% Created: 15 Jul 2019
% Created with Matlab version: 9.4.0.813654 (R2018a)

% $Id: $
% $Date: $
% $Author: Mick van der Wegen $
% $Revision: $
% $HeadURL: $
% $Keywords: mudflat morphodynamics$

load([ rname 'input.mat'], 'input')
load([ rname 'output.mat'], 'output');

hxt=output.hxt;
zbxt=output.zbxt;
eroxt=output.eroxt;
depoxt=output.depoxt;
sedavt=output.sedavt;
cxt=output.cxt;
uxt=output.uxt;
vxt=output.vxt;
tauxt=output.tauxt;
tauw_xt=output.tauw_xt;
tauc_xt=output.tauc_xt;
hrmsxt=output.hrmsxt;
courantxt=output.courantxt;
corfacxt=output.corfacxt;
fwxt=output.fwxt;

etamin=-input.etamp*1.1; 
etamax=-input.etamp*1.1;
vmin=min(min(vxt));
vmax=max(max(vxt));
ptime=[1:size(zbxt,2)].*input.outint./60;% in hour
x=[1:size(zbxt,1)].*input.dx;
Dif=input.Dif;
dt=input.dt;
dx=input.dx;
nrtides=input.nrtides;
T=input.T;
MF=input.MF;
outputint=input.outint;
XX=input.XX;

yymin=0;
yymax=ptime(end);

figure;
subplot(131);
plot(hxt(1,:)+zbxt(1,:),ptime);% in hour
title('water level (m)');xlabel('x (m)');ylabel('time (mins)');
ylim([yymin yymax]);
subplot(132);
pcolor(x,ptime,vxt');% in hour
title('along velocity (m/s)');xlabel('x (m)');ylabel('time (mins)');
shading interp;
caxis([-1 1]);
colormap jet;
colorbar('east');ylim([yymin yymax]);
subplot(133);
pcolor(x,ptime,uxt');% in hour
title('across velocity (m/s)');xlabel('x (m)');ylabel('time (mins)');
shading interp;
caxis([-0.05 0.05]);
colormap jet;
colorbar('east');ylim([yymin yymax]);
% print ([rname, 'wl uv' ], '-dtiff', '-r300')

figure;
subplot(133);
pcolor(x,ptime,hxt');% in hour
title('water depth (m)');xlabel('x (m)');ylabel('time (mins)');
shading interp;
colormap jet;
colorbar('east');ylim([yymin yymax]);

figure;
subplot(131);
pcolor(x,ptime,cxt');% in hour
title('concentration (g/l)');xlabel('x (m)');ylabel('time (mins)');
shading interp;
caxis([0 1]);
colormap jet;
colorbar('east');ylim([yymin yymax]);
subplot(132);
pcolor(x,ptime,-eroxt');% in hour
shading interp;
colormap jet;
colorbar('east');ylim([yymin yymax]);
title('erosion (m)');xlabel('x (m)');ylabel('time (mins)');
subplot(133);
pcolor(x,ptime,depoxt');% in hour
title('deposition (m)');xlabel('x (m)');ylabel('time (mins)');
shading interp;
colormap jet;
colorbar('east');ylim([yymin yymax]);
% print ([rname, 'erodep' ], '-dtiff', '-r300')

for it=1:size(zbxt,2)
    zbxtini(:,it)=zbxt(:,1);
end
figure;
subplot(131);
pcolor(x,ptime,zbxt');% in hour
title('bed level (m)');xlabel('x (m)');ylabel('time (mins)');
shading interp;
caxis([-20 2]);
colormap jet;
colorbar('east');ylim([yymin yymax]);
subplot(132);
pcolor(x,ptime,zbxt'-zbxtini');% in hour
title('bed level change incl MF (m)');xlabel('x (m)');ylabel('time (mins)');
shading interp;
colormap jet;
colorbar('east');ylim([yymin yymax]);
subplot(133);
pcolor(x,ptime,sedavt');% in hour
title('sed availability incl MF (m)');xlabel('x (m)');ylabel('time (mins)');
shading interp;
colormap jet;
colorbar('east');ylim([yymin yymax]);
% print ([rname, 'bed level change' ], '-dtiff', '-r300');

figure;
subplot(211);
plot(x,zbxt(:,1));hold on;
plot(x,zbxt(:,round(end/4)));hold on;
plot(x,zbxt(:,round(end/2)));hold on;
plot(x,zbxt(:,round(end/4*3)));hold on;
plot(x,zbxt(:,end));hold on;% in hour
title('bed level (m)');xlabel('x (m)');ylabel('time (mins)');
time=nrtides*MF*T/3600/24/365;
ylim([-5 2]);
xlim([0 XX]);
legend('initial',[num2str(round(time/4,2)), ' year'],[num2str(round(time/2,2)), ' year'],[num2str(round(time/4*3,2)), ' year'],[num2str(round(time,2)), ' year'],'location','southeast')
subplot(212);
plot(x,zbxt(:,1));hold on;
plot(x,zbxt(:,(end-round(6*T/outputint/6)))','b-',x,zbxt(:,(end-round(5*T/outputint/6)))','b-.',x,zbxt(:,(end-round(4*T/outputint/6)))','b:',x,...
    zbxt(:,(end-round(3*T/outputint/6)))','r-',x,zbxt(:,(end-round(2*T/outputint/6)))','r-.',x,zbxt(:,end-round(1*T/outputint/6))','r:')
set(gca,'fontsize',11,'fontweight','bold')
legend('initial','Hw','Hw+2','Hw+4','Hw+6','Hw+8','Hw+10');
title ('bed level during tide');
xlabel('Cross-shore distance (m)');
xlim([0 XX]);
% print ([rname, 'bed level' ], '-dtiff', '-r300')

tmin=-2;tmax=2;
figure;
subplot(131);
pcolor(x,ptime,tauw_xt');% in hour
title('tau wave (N/m^2)');xlabel('x (m)');ylabel('time (mins)');
caxis([tmin tmax]);
colormap jet;
colorbar('east');
shading interp;ylim([yymin yymax]);
subplot(132);
pcolor(x,ptime,tauc_xt');% in hour
title('tau current (N/m^2)');xlabel('x (m)');ylabel('time (mins)');
caxis([tmin tmax]);
colormap jet;
colorbar('east');
shading interp;ylim([yymin yymax]);
subplot(133);
pcolor(x,ptime,tauxt');% in hour
title('tottau (N/m^2)');xlabel('x (m)');ylabel('time (mins)');
caxis([tmin tmax]);
colormap jet;
colorbar('east');
shading interp;ylim([yymin yymax]);
% print ([rname, 'Hrms' ], '-dtiff', '-r300')

figure;
subplot(132);
pcolor(x,ptime,hrmsxt');% in hour
title('Hrms (m)');xlabel('x (m)');ylabel('time (mins)');
colormap jet;
colorbar('east');
shading interp;ylim([yymin yymax]);
subplot(133);
pcolor(x,ptime,fwxt');% in hour
title('fw(m)');xlabel('x (m)');ylabel('time (mins)');
colormap jet;
colorbar('east');
shading interp;ylim([yymin yymax]);
% print ([rname, 'Hrms' ], '-dtiff', '-r300')

figure;
subplot(311);
plot(x,vxt(:,(end-round(6*T/outputint/6)))','b-',x,vxt(:,(end-round(5*T/outputint/6)))','b-.',x,vxt(:,(end-round(4*T/outputint/6)))','b:',x,...
    vxt(:,(end-round(3*T/outputint/6)))','r-',x,vxt(:,(end-round(2*T/outputint/6)))','r-.',x,vxt(:,end-round(1*T/outputint/6))','r:')
set(gca,'fontsize',11,'fontweight','bold')
legend('Hw','Hw+2','Hw+4','Hw+6','Hw+8','Hw+10');
title ('Longshore tidal velocity profiles');
xlabel('Cross-shore distance (m)');
ylabel('Longshore velocity (m/s)');
xlim([0 XX]);
subplot(312);
plot(x,uxt(:,(end-round(6*T/outputint/6)))','b-',x,uxt(:,(end-round(5*T/outputint/6)))','b-.',x,uxt(:,(end-round(4*T/outputint/6)))','b:',x,...
    uxt(:,(end-round(3*T/outputint/6)))','r-',x,uxt(:,(end-round(2*T/outputint/6)))','r-.',x,uxt(:,end-round(1*T/outputint/6))','r:')
set(gca,'fontsize',11,'fontweight','bold')
legend('Hw','Hw+2','Hw+4','Hw+6','Hw+8','Hw+10');
title ('Cross shore tidal velocity profiles');
xlabel('Cross-shore distance (m)');
ylabel('Cross-shore velocity (m/s)');
xlim([0 XX]);
subplot(313);
plot(x,tauxt(:,(end-round(6*T/outputint/6)))','b-',x,tauxt(:,(end-round(5*T/outputint/6)))','b-.',x,tauxt(:,(end-round(4*T/outputint/6)))','b:',...
    x,tauxt(:,(end-round(3*T/outputint/6)))','r-',x,tauxt(:,(end-round(2*T/outputint/6)))','r-.',x,tauxt(:,end-round(1*T/outputint/6))','r:')
set(gca,'fontsize',11,'fontweight','bold')
legend('Hw','Hw+2','Hw+4','Hw+6','Hw+8','Hw+10');
title ('Shear stress (N/m^2)');
xlabel('Cross-shore distance (m)');
ylabel('Shear stress (N/m^2)');
xlim([0 XX]);

figure;
subplot(311);
plot(x,hxt(:,(end-round(6*T/outputint/6)))','b-',x,hxt(:,(end-round(5*T/outputint/6)))','b-.',x,hxt(:,(end-round(4*T/outputint/6)))','b:',x,...
    hxt(:,(end-round(3*T/outputint/6)))','r-',x,hxt(:,(end-round(2*T/outputint/6)))','r-.',x,hxt(:,end-round(1*T/outputint/6))','r:')
hold on;
set(gca,'fontsize',11,'fontweight','bold')
legend('Hw','Hw+2','Hw+4','Hw+6','Hw+8','Hw+10');
ylim([0 35]);
title ('water depth profiles');
xlabel('Cross-shore distance (m)');
ylabel('Waterdepth (m)');
subplot(312);
plot(x,cxt(:,(end-round(6*T/outputint/6)))','b-',x,cxt(:,(end-round(5*T/outputint/6)))','b-.',x,cxt(:,(end-round(4*T/outputint/6)))','b:',x,...
    cxt(:,(end-round(3*T/outputint/6)))','r-',x,cxt(:,(end-round(2*T/outputint/6)))','r-.',x,cxt(:,end-round(1*T/outputint/6))','r:')
set(gca,'fontsize',11,'fontweight','bold')
legend('Hw','Hw+2','Hw+4','Hw+6','Hw+8','Hw+10');
title ('concentration profiles');
xlabel('Cross-shore distance (m)');
ylabel('Concentration (g/l)');
subplot(313);
plot(x,hrmsxt(:,(end-round(6*T/outputint/6)))','b-',x,hrmsxt(:,(end-round(5*T/outputint/6)))','b-.',x,hrmsxt(:,(end-round(4*T/outputint/6)))','b:',x,...
    hrmsxt(:,(end-round(3*T/outputint/6)))','r-',x,hrmsxt(:,(end-round(2*T/outputint/6)))','r-.',x,hrmsxt(:,end-round(1*T/outputint/6))','r:')
set(gca,'fontsize',11,'fontweight','bold')
legend('Hw','Hw+2','Hw+4','Hw+6','Hw+8','Hw+10');
title ('waveheight profiles');
xlabel('Cross-shore distance (m)');
ylabel('Wave height (m)');

