function des_runmodel(varargin)

OPT = struct(varargin{:});

switch OPT.model
    case 'durosplus'
        DuneErosionSettings('set',...
            'AdditionalErosion', false,...
            'BoundaryProfile', false,...
            'DuneBreachCalculation', false,...
            'TP12slimiter', false);
        result = DUROS(...
            'xInitial', OPT.x,...
            'zInitial', OPT.z,...
            'WL_t', OPT.WL,...
            'Hsig_t', OPT.Hsig,...
            'Tp_t', OPT.Tp,...
            'D50', OPT.D50);
        save(fullfile(OPT.rundir, sprintf('%s%i.mat', OPT.variable, OPT.ifactor)), 'result')
    case 'durosta'
        durostaref = fullfile(tempdir, 'durosta.mat');
        if ~exist(durostaref, 'file')
        [x ix] = sort(max(OPT.x) - OPT.x);
        z = OPT.z(ix);
        
        [xgr zgr dx] = DUROSTA_makegrid(x, z, OPT.WL);
        D = CreateDurostaVar(...
            'WL', 5,...
            'Hs', 9,...
            'Tp', 12,...
            'Tstop', OPT.duration/3600,...
            'DSED', 225e-6,...
            'Grid', [xgr' dx'],...
            'xInitial', x,...
            'zInitial', z);
            save(durostaref, 'D')
        end
        load(durostaref)

        switch OPT.variable
            case 'WL'
                D.Input.WL = OPT.WL;
            case 'Hsig'
                D.Input.Hs = OPT.Hsig;
            case 'Tp'
                D.Input.Tp = OPT.Tp;
            case 'D50'
                D.settings.Params.DSED = OPT.D50;
        end

        exefile = 'D:\cornelisdenheijer\ProgramFiles\unibestDE\uni-de.exe';
        filename = fullfile(OPT.rundir, sprintf('%s%i', OPT.variable, OPT.ifactor), sprintf('%s%i.inp', OPT.variable, OPT.ifactor));
        mkpath(fileparts(filename))
        DUROSTA_Inp_File(D, filename);
        [runflag runtime msg] = DUROSTA_Run(filename, exefile, 'quiet');
    case 'xbeach'
        xbref = fullfile(tempdir, 'xb.mat');
        if ~exist(xbref, 'file')
            [x_xb ix] = sort(-OPT.x);
            z_xbgrid = OPT.z(ix);
            
            zsea = min(floor([min(5) - max(12)/.55 -20]));
            xb_setpref('grid_finalise', {'zmin', zsea})
            
            xb = xb_generate_model(...
                'bathy', {'x', x_xb, 'z', z_xbgrid, 'xgrid', {'dxmin', 2}, 'finalise', {'seaward_extend'}, 'superfast', true},...
                'tide', {'front' 5},...
                'waves', {...
                'type', 'jonswap',...
                'Hm0', 9,...
                'Tp', 12},...
                'settings', {...
                'morfac', OPT.morfac,...
                'posdwn', -1,...
                'tintg', 100,...
                'tstop', ceil(OPT.duration/OPT.morfac)*OPT.morfac,...
                'D50', 225e-6,...
                'D90', 225e-6*1.5,...
                'random' 0,...
                'avalanching', 0,...
                'outputformat', 'netcdf',...
                'globalvars', {'H' 'zs' 'zb' 'dzav'},...
                });
            xb = xb_del(xb, 'swtable');
            wl = xb_bc_extractwl(xb);
            xb = xb_set_start_time(xb, 'waterlevel', wl);
            save(xbref, 'xb')
        end
        load(xbref)
        switch OPT.variable
            case 'WL'
                xb = xb_set(xb, 'zs0', OPT.WL);
            case 'Hsig'
                xb = xb_set(xb, 'bcfile.Hm0', OPT.Hsig);
            case 'Tp'
                xb = xb_set(xb, 'bcfile.Tp', OPT.Tp);
            case 'D50'
                xb = xb_set(xb, 'D50', OPT.D50, 'D90', 1.5 * OPT.D50);
        end
        filename = fullfile(OPT.rundir, sprintf('%s%i', OPT.variable, OPT.ifactor), 'params.txt');
        mkpath(fileparts(filename))
        xb_write_input(filename, xb);
        
        % write sh script
        fid = fopen(fullfile(fileparts(filename), sprintf('%s%i.sh', OPT.variable, OPT.ifactor)), 'w');
        fprintf(fid, '#!/bin/sh\n. /opt/sge/InitSGE\n. ~/.bashrc\n/u/heijer/sources/XBeach/xbeach\n');
        fclose(fid);
end