close all; clear all;

name = 'base';

%% get input data from Martijn

% bathymetry
z = load('..\one_wind_cond\h_init.dat');

dx = 5;
x = [0:1:size(z,1)-1]*dx;
y = [0:1:size(z,2)-1]*dx;

[x,y] = meshgrid(x,y);

% figure; surf(x,y,z); shading flat; colorbar;

% tidal data
tide = [0 0; 0 0;];

%% other input
duration = 5*3600+1800;
tstart = 1800;


%% setup XBeach model

xb_setpref('grid_finalise', {'zmin',-20,'noff',3,'slope',1/70});

xb2dh = xb_generate_model( 'bathy',{'x',x,'y',y,'z',z,...
                           'xgrid',{'dxmin',5,'wl',5,'ppwl',12}, ...
                           'ygrid',{'dymin',20,'dymax',30,'area_size',0.7},...
                           'finalise',{'seaward_extend',}}, ...
                           'waves',{'Hm0',4,'Tp',8,'s',20,'gammajsp',3.3,'mainang',270,'duration',duration},...
                           'wavegrid',{'nbins',1},...
                           'tide',{'time',[0 duration],'front',tide(:,1),'back',tide(:,2)},...
                           'settings',{'front','abs_2d','back','wall',...
                                       'random',0,...
                                       'morfac',10,'mortstart',tstart,...'
                                       'wetslp',0.15,'dryslp',1,...
                                       'D50',0.0002,'D90',0.0003,...
                                       'C',55,...
                                       'tstart',0,'tstop',duration',...
                                       'outputformat','netcdf',...
                                       'tintg',120,'globalvars',{'zb','zs','u','v','H','Fx','Fy','ceqsg','ccg','Susg','Svsg','sedero','dzav'}, ...
                                       'tintm',duration-tstart,'meanvars',{'zs','u','v','H','ceqsg','ccg','Susg','Svsg'}},...
                           'write', true, ...
                           'path', name ...
                           );

%% check model

xb_peel(xb2dh);                
xgr = xfile.data.value;
ygr = yfile.data.value;
dep = depfile.data.value;

figure; surf(xgr,ygr,dep); colorbar; 