You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.1 KiB
Matlab

% SBEACH toolbox - fsbeach_setupmodel
% Written by Joshua Simmons 11/2017
% Note this code is specifically written to align with (and borrows code
% from) the XBeach matlab toolbox so as to make the use of both models
% streamlined.
% Syntax:
% OPT = fsbeach_setupmodel(varargin)
%
% Input:
% varargin = bathy: cell array of name/value pairs of bathymetry
% settings supplied to fsbeach_genbathy
% waves: cell array of name/value pairs of waves
% settings supplied to fsbeach_genwaves
% tide: cell array of name/value pairs of tide
% settings supplied to fsbeach_gentide
% settings: cell array of name/value pairs of model
% settings supplied to fsbeach_writecfg
% path: destination directory of model setup, if
% written to disk
%
% Output:
% OPT = options
function out = fsbeach_setupmodel(varargin)
OPT = struct( ...
'bathy', {{}}, ...
'waves', {{}}, ...
'tide', {{}}, ...
'settings', {{}}, ...
'path', [pwd '\temp\'], ...
'name', 'sbeach_test' ...
);
OPT = setproperty(OPT, varargin{:});
%check we are ready to write!
if ~isdir(OPT.path)
mkdir(OPT.path)
else
%delete any old SBEACH files
delete(fullfile(OPT.path,'*.PRI'));
delete(fullfile(OPT.path,'*.WAV'));
delete(fullfile(OPT.path,'*.ANG'));
delete(fullfile(OPT.path,'*.ELV'));
delete(fullfile(OPT.path,'*.HDB'));
delete(fullfile(OPT.path,'*.CFG'));
delete(fullfile(OPT.path,'*.AsSupplied'));
delete(fullfile(OPT.path,'*.LOG'));
delete(fullfile(OPT.path,'*.PRC'));
delete(fullfile(OPT.path,'*.RPTNew'));
delete(fullfile(OPT.path,'*.XVR'));
end
%%% Initial settings
%get defaults
settingsOPT = fsbeach_getdefaults();
%apply any setttings as needed
settingsOPT = setproperty(settingsOPT, OPT.settings);
%%% Bathy
%print to file
bathy = fsbeach_genbathy(OPT.path,OPT.name,settingsOPT,OPT.bathy{:});
%%% Waves
%print to file
waves = fsbeach_genwaves(OPT.path,OPT.name,OPT.waves{:});
%%% Tide
%print to file
if isempty(OPT.tide) && ~any(strcmp(OPT.settings,'IELEV'))
error('Please supply tide or use the IELEV setting to supply constant WL.')
elseif ~isempty(OPT.tide)
tide = fsbeach_gentide(OPT.path,OPT.name,OPT.tide{:});
%check timeseries data
fsbeach_checktsdata(waves,tide);
else
tide = NaN; % no tide supplied
end
%%% Final settings
% get standard settings from bathy, waves and tides
settingsOPT = fsbeach_getstdsettings(bathy, waves, tide, settingsOPT);
%write the configuration file
fsbeach_writecfg(OPT.path,OPT.name,settingsOPT);
%%% Output
%structure out
out.bathy = bathy;
out.waves = waves;
out.tides = tide;
out.settings = settingsOPT;
out.path = [OPT.path OPT.name];
end