function [stochast, Lambda1] = profile_fluctuation_stochast(varargin)
%PROFILE_FLUCTUATION_STOCHAST  One line description goes here.
%
%   More detailed description goes here.
%
%   Syntax:
%   varargout = profile_fluctuation_stochast(varargin)
%
%   Input: For <keyword,value> pairs call profile_fluctuation_stochast() without arguments.
%   varargin  =
%
%   Output:
%   varargout =
%
%   Example
%   profile_fluctuation_stochast
%
%   See also

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2014 Deltares
%       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 General Public License as published by
%   the Free Software Foundation, either version 3 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 General Public License for more details.
%
%   You should have received a copy of the GNU General Public License
%   along with this library.  If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://www.OpenEarth.eu">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute
% your own tools.

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% Created: 10 Mar 2014
% Created with Matlab version: 8.1.0.604 (R2013a)

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

%%
OPT = struct(...
    'id',       7003800,        ...
    'station1', 'Den Helder',   ...
    'station2', 'IJmuiden',     ...
    'year',     2013,           ...
    'ProfileVariation', true,   ...
    'VariationVolumeMean',  0,      ...
    'VariationVolumeSTD',   100,    ...
    'jarkus_url',   jarkus_url, ...
    'grainsize_url', 'http://opendap.deltares.nl:8080/thredds/dodsC/opendap/rijkswaterstaat/grainsize_vtv/grainsize_vtv.nc');

% overwrite defaults with user arguments
OPT = setproperty(OPT, varargin);

%% code
tr = jarkus_transects(...
    'url', OPT.jarkus_url,...
    'output', {'id'});

%% grainsize
[meanD50, sigmaD50] = rws_grainsize2jarkus(...
    'output', {'meanD50' 'sigmaD50'},...
    'jarkus_url', OPT.jarkus_url,...
    'grainsize_url', OPT.grainsize_url);

idx = tr.id == OPT.id;
[meanD50, sigmaD50] = deal(meanD50(idx), sigmaD50(idx));

%% wave height
Lambda1 = getLambda_2Stations('Station1',OPT.station1, 'Station2', OPT.station2,...
    'JarkusId', OPT.id);

if OPT.ProfileVariation
    %% volume fluctuation
    [lmda, zta] = deal(logn_moments2lambda(5, 2), logn_moments2zeta(5, 2));
    
    %% stochast structure
    stochast = struct(...
        'Name', {
            'D50'...
            'Ph'...
            'PHs'...
            'PTp'...
            'volumefluct'...
            'fluctlevel'...
            'StormDurationFactor' ...
            'ModelAccuracyFactor' ...
        },...
        'Distr', {
            @norm_inv...
            @unif_inv...
            @norm_inv...
            @norm_inv...
            @norm_inv...
            @logn_inv...
            @norm_inv...
            @norm_inv...
        },...
        'Params', {
            {meanD50 sigmaD50}...
            {0 1}...
            {0 0.6}...
            {0 1}...
            {OPT.VariationVolumeMean OPT.VariationVolumeSTD}...
            {lmda zta}...
            {0 0.10}...
            {0 0.15}...
        } ...
        );
else
    stochast = struct(...
    'Name', {
        'D50'...
        'Ph'...
        'PHs'...
        'PTp'...
        'StormDurationFactor' ...
        'ModelAccuracyFactor' ...
        },...
    'Distr', {
        @norm_inv...
        @unif_inv...
        @norm_inv...
        @norm_inv...
        @norm_inv...
        @norm_inv...
        },...
    'Params', {
        {meanD50 sigmaD50}...
        {0 1}...
        {0 0.6}...
        {0 1}...
        {0 0.10}...
        {0 0.15}...
        } ...
    );
end