function result = example_ADIS_XBeach_cluster(varargin)
%% Read Settings

OPT = struct(...
    'MinAppr', 50, ...
    'MaxErosionPoint',  -351, ...
    'StartUp', 'AxialPoints', ...
    'Method', 'ADIS', ...
    'SaveDir', 'p:\11205758-029-boizandkust\02_Stap1p2a_ontwikkelenProbMethode_ADIS\4_modelRunDir\testRun\', ...
    'seed', 34);

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

%% run Directional Sampling Object-Oriented

% construct stochastic variables
StochVars(3,1) = RandomVariable;
 
% waterlevel h
StochVars(1,1).Name                     = 'Ph';
StochVars(1,1).Distribution             = @norm_inv;
StochVars(1,1).DistributionParameters   = {0 1}; % Values independent of location

% waterlevel Hm0
StochVars(2,1).Name                     = 'PHm0';
StochVars(2,1).Distribution             = @norm_inv;
StochVars(2,1).DistributionParameters   = {0 0.6}; % Values independent of location

% waterlevel Tp
StochVars(3,1).Name                     = 'PTp';
StochVars(3,1).Distribution             = @norm_inv;
StochVars(3,1).DistributionParameters   = {0 1}; % Values independent of location

load('info.mat')

% construct limit state
LSF                                 = LimitState;
LSF.Name                            = 'XBeachLimitState';
LSF.LimitStateFunction              = @XBeachLimitStateFunction;
LSF.LimitStateFunctionChecker       = XBeachLimitStateFunctionChecker;
LSF.RandomVariables                 = StochVars;
LSF.ResponseSurface                 = AdaptiveResponseSurface;
LSF.ResponseSurface.NoCrossTerms    = false;
LSF.LimitStateFunctionAdditionalVariables = { ...
    'JarkusID',         4000760,            ...
    'MaxErosionPoint',  OPT.MaxErosionPoint,...
    'ModelSetupDir',    'p:/11205758-029-boizandkust/02_Stap1p2a_ontwikkelenProbMethode_ADIS/4_modelRunDir/Terschelling_4000760/', ...
    'ModelRunDir',      'p:/11205758-029-boizandkust/02_Stap1p2a_ontwikkelenProbMethode_ADIS/4_modelRunDir/testRun/', ...
    'RunRemote',        true, ...
    'sshUser',          sshUser, ...
    'sshPassword',      sshPassword ...
    };
%     'Station1',         'Eierlandse Gat',   ...
%     'Station2',         'Steunpunt Waddenzee', ...

%     'ModelRunDir',      'p:\11205758-029-boizandkust\02_Stap1p2a_ontwikkelenProbMethode_ADIS\4_modelRunDir\', ...


% construct line searcher 
LineSearcher            = LineSearch;
LineSearcher.MaxErrorZ  = 1;
LineSearcher.RelativeZCriterium = false;

switch OPT.Method
    case 'ADIS'
        % construct ADIS object
        ADIS_obj        = AdaptiveDirectionalImportanceSampling(LSF,LineSearcher,0.95,0.2,OPT.seed);
        ADIS_obj.MinNrApproximatedPoints = OPT.MinAppr;
    case 'DS'
        ADIS_obj        = DirectionalSampling(LSF,LineSearcher,0.95,0.2,OPT.seed);
end

if strcmp(OPT.Method,'ADIS')
    if strcmp(OPT.StartUp,'AxialSearch')
        ADIS_obj.StartUpMethods = StartUpAxialSearch;
    elseif strcmp(OPT.StartUp,'AxialPoints')
        ADIS_obj.StartUpMethods = StartUpAxialPoints;
        ADIS_obj.StartUpMethods.BetaOffset = 4;
    end
end

% calculate Pf
ADIS_obj.CalculatePf;

% save results
result.OO_ADIS.DS_object    = ADIS_obj;
result.OO_ADIS.Output.P_f   = ADIS_obj.Pf;
result.OO_ADIS.Output.Beta  = norm_inv(1-ADIS_obj.Pf, 0, 1);
result.OO_ADIS.Output.Calc  = ADIS_obj.LimitState.NumberExactEvaluations;

save(fullfile(OPT.SaveDir,['result_XBeach_4000760_Terschelling_sd_' num2str(OPT.seed) '_cr_' num2str(OPT.MaxErosionPoint) '_' date]),'result')