% Make Hurrywave model
clear variables
close all
clc
warning off

% Settings
destout = '.\';

% Get inp values -> simple grid
inp            = hurrywave_initialize_input;

% Grid
inp.x0         = 0.0;
inp.y0         = 0.0;
inp.dx         = 50.0;
inp.dy         = 50.0;
inp.mmax       = 50;
inp.nmax       = 20;
inp.rotation   = 0;
inp.indexfile  = 'hurrywave.ind';
inp.mskfile    = 'hurrywave.msk';
inp.depfile    = 'hurrywave.dep';

inp.crs_name       = 'cs'; % only used for netcdf output
inp.crs_type       = 'projected'; % must be projected or geographic

% Time
inp.tref           = datenum(2018,10,7,0,0,0);
inp.tstart         = datenum(2018,10,7,0,0,0);
inp.tstop          = datenum(2018,10,8,0,0,0);
inp.dt             = 5;
inp.dtmapout       = 3600;
inp.dthisout       = 600;

[xg,yg,xz,yz]  = hurrywave_make_grid(inp.x0,inp.y0,inp.dx,inp.dy,inp.mmax,inp.nmax,inp.rotation);

% Interpolate
slope=1/50;
zz              = slope*yz - max(max(yz))*slope;     

% Make msk
msk               = ones(size(xz));
msk(zz > 0)       = 0;
zz=min(zz,-0.5);
zz=max(zz,-20);

% Add a sand bar
zz(8:12,20:30)=max(zz(8:12,20:30),-1);

% Set open boundary wherever depth exceeds 8 m
zzz=zz(:,1);
j1=find(zzz>-8,1,'first');
msk(1,:)=2;
msk(1:j1,1)=2;
msk(1:j1,end)=2;

hurrywave_write_binary_inputs(zz,msk,[destout inp.indexfile],[destout inp.depfile],[destout inp.mskfile]);

% Boundary conditions (these are not generated by this script!)
inp.bndfile        = 'hurrywave.bnd';
inp.bhsfile        = 'hurrywave.bhs';
inp.btpfile        = 'hurrywave.btp';
inp.bwdfile        = 'hurrywave.bwd';
inp.bdsfile        = 'hurrywave.bds';

%% Get wind
hurrywave_write_input([destout 'hurrywave.inp'],inp);

figure; pcolor(xz,yz,zz); shading flat;axis equal;colorbar;

