OPT = struct(...
    'id', 0,...
    'irun', 2,...
    'maindir', fullfile(fileparts(which(mfilename)), '..', 'simulations'),...
    'models', {{'xbeach'}},...'durosplus' 'durosta' 
    'variables', {{'WL' 'Hsig' 'Tp' 'D50'}},...
    'WL', 5,...
    'Hsig', 9,...
    'Tp', 12,...
    'D50', 225e-6,...
    'factor', .75:.125:1.25,...
    'duration', 5*3600,...
    'morfac', 5);

% define cross-shore profile
[x z] = SimpleProfile('zmin', -20);

inputcell = cell(1, length(OPT.variables)*2);
for i = 1:length(OPT.variables)
    inputcell{i*2-1} = OPT.variables{i};
    inputcell{i*2} = OPT.(OPT.variables{i});
end

%%
for imodel = 1:length(OPT.models)
    model = OPT.models{imodel};
    for ivar = 1:length(OPT.variables)
        variable = OPT.variables{ivar};
        for ifactor = 1:length(OPT.factor)
            fac = OPT.factor(ifactor);
            rundir = fullfile(OPT.maindir, sprintf('%08i', OPT.id), model, sprintf('run%02i', OPT.irun), variable);
            varid = false(size(inputcell));
            varid(1:2:end) = strcmp(inputcell(1:2:end), variable);
            varid = varid | [false varid(1:end-1)];
            mkpath(rundir)
            des_runmodel(...
                'model', model,...
                inputcell{~varid},...
                variable, OPT.(variable)*fac,...
                'x', x,...
                'z', z,...
                'rundir', rundir,...
                'variable', variable,...
                'ifactor', ifactor,...
                'duration', OPT.duration,...
                'morfac', OPT.morfac);
        end
    end
end
