function XB = XBeach_1D(varargin)
%XBEACH_1D  generate XB-structure for cross-shore XBeach calculation
%
%
%
% syntax:
% XB = XBeach_1D('calcdir', calcdir...
%           'xInitial', xInitial,...
%           'zInitial', zInitial,...
%           'D50', D50,...
%           'WL_t', WL_t,...
%           'Hsig_t', Hsig_t,...
%           'Tp_t', Tp_t,...
%           'T', T,...
%           'morfac', morfac,...
%           'morstart', morstart)
%
% input:
%
% output:
%
% See also

%   --------------------------------------------------------------------
%   Copyright (C) 2008 Deltares
%       C.(Kees) den Heijer
%
%       Kees.denHeijer@deltares.nl	
%
%       Deltares
%       P.O. Box 177
%       2600 MH Delft
%       The Netherlands
%
%   This library is free software; you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation; either
%   version 2.1 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
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library; if not, write to the Free Software
%   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
%   USA
%   or http://www.gnu.org/licenses/licenses.html, http://www.gnu.org/, http://www.fsf.org/
%   --------------------------------------------------------------------

% $Id$
% $Date$
% $Author$
% $Revision$
% $HeadURL$
% $Keywords:

%%
OPT = struct(...
    'calcdir', pwd,...
    'xInitial', [],...
    'zInitial', [],...
    'D50', 225e-6,...
    'WL_t', 5,...
    'Hsig_t', 9,...
    'Tp_t', 12,...
    'T', 18000,...
    'morfac', 1,...
    'morstart', 300);

OPT = setproperty(OPT, varargin{:});

XB = CreateEmptyXBeachVar(...
    'xInitial', OPT.xInitial,...
    'zInitial', OPT.zInitial,...
    'dx', 5,...
    'dy', 5,...
    'ny', 2,...
    'zs0', OPT.WL_t,...
    'depfile', 'bath.dep',...
    'tstart', 0,...
    'tint', 0,...
    'tstop', OPT.T+OPT.morstart,...
    'morstart', OPT.morstart,...
    'nonh', [],...
    'tideloc', 0,...
    'eps', 1e-4,...
    'bcfile', 'boundarylist.lst',...
    'dir0', [],...
    'instat', 4,...
    'hmin', .5,...
    'rt', [],...
    'swtable', 'RF_table.txt',...
...    'dthc', [],...
    'rt', [],...
    'D50', OPT.D50,...
    'D90', 1.5*OPT.D50,...
    'hswitch', .3,...
    'dryslp', 5,...
    'OutVars', {'dims','zb'});

if ~strcmp(varargin, 'D90')
    XB.settings.SedInput.D90 = XB.settings.SedInput.D50 * 1.5;
end

%%
[XB.Input.xInitial, XB.Input.zInitial] = checkCrossShoreProfile(XB.Input.xInitial, XB.Input.zInitial,...
    'poslndwrd', 1,...
    'x_origin', 'seaside');
XB.settings.Grid.nx = length(min(XB.Input.xInitial):XB.settings.Grid.dx:max(XB.Input.xInitial))-1;
% XB.settings.SedInput.morstart = XB.settings.Flow.tint;

if ~exist(OPT.calcdir)
   mkdir(OPT.calcdir); 
end

fid = fopen(fullfile(OPT.calcdir, XB.settings.Waves.bcfile)  , 'w');
fprintf(fid, 'FILELIST\n%g   0.5   jonswap.inp', XB.settings.Flow.tstop);
fclose(fid);

fid = fopen(fullfile(OPT.calcdir, 'jonswap.inp'), 'w');
fprintf(fid, 'Hm0       = %g\nfp        = %g\nmainang   = 270\ngammajsp  = 1\ns         = 10000\nfnyq      = 1', OPT.Hsig_t, 1/OPT.Tp_t);
fclose(fid);