function [Hswash Hinundation scaling hurricanetrain profile] = calcRegime(crsection, i, param, Hm0, ngridp)
%CALCREGIME  derive the scale-factor for down or up scaling hurricane Katrina to the wanted Sallenger hurricane.
%
%   More detailed description goes here.
%
%   Syntax:
%   [Hswash Hinundation scaling hurricanetrain profile] = calcRegime(crsection, i, param, Hm0, ngridp)
%
%   Input:
%   crsection      = name of the input-profile
%   i              = number of hurricane in the hurricanetrain
%   param          = additional scale-factor
%   Hm0            = Waves of the hurricane to be scaled (waves of Katrina)
%   ngridp         = number of x-gridpoints
%
%   Output:
%   Hswash         = threshold value Swash - Overwash
%   Hinundation    = threshold value Overwash - Inundation
%   scaling        = factor which is being used to scale down/up Katrina
%   hurricanetrain = regime of each hurricane in the hurricane train
%   profile        = profile wich belongs to the threshold values
%
%   Example
%   calcRegime
%
%   See also 

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2010 Deltares/TU Delft
%       Kees Pruis
%
%       kees.pruis@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, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://OpenEarth.nl">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: 05 Nov 2010
% Created with Matlab version: 7.7.0.471 (R2008b)

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


%% Derive the new waveheigt according to the Sallenger regimes
% Beta=0.0035 golfsteilheid=0.016
% eta_mean according to the founded relation = (H-3.72)/0.56
    %bepalen van het initiele profiel en de daarbij behorende Sallenger
    %waarde
	fid = fopen(crsection);
        for j=1:196
            profile.scan(j)=textscan(fid,'%f32',ngridp,'delimiter','');
        end
        D_low=max(profile.scan{1,2});
        profile.initial=profile.scan{1,2};
	fclose(fid);
    
% Treshold values
Hswash=(4*(D_low-0.45))/((4*0.83*(0.0035/sqrt(0.016))+0.8)+0.5);
Hinundation=(0.56*(D_low-0.45)+3.72)/(0.56*(-0.02*(0.0035/sqrt(0.016))+0.14)+1);

[hurricanetrain]=getHurricanetrain();

hurricaneregime=hurricanetrain.intensity{i,1};

RegSwash = strcmpi(hurricaneregime,'swash');
RegOverwash = strcmpi(hurricaneregime,'Overwash');
RegInundation = strcmpi(hurricaneregime,'inundation');


if RegSwash==1
%     H uniform verdeeld swash
    H = 0 + (Hswash-0).*rand(1,1);
end

if RegOverwash==1
%     H uniform verdeeld overwash
    H = Hswash + (Hinundation-Hswash).*rand(1,1);
end

if RegInundation==1
%     H uniform verdeeld inundation
    H = Hinundation + (6-Hinundation).*rand(1,1);
end

% verhouding bepalen tussen de maximale golfhoogte van het betreffende
% regime en de maximale golfhoogte van Katrina
scaling=param*(max(Hm0)/H);