function [katrina steepness Hm0] = getKatrina(varargin)
%GETKATRINA  Gather the data of hurricane Katrina
%
%   More detailed description goes here.
%
%   Syntax:
%   [katrina steepness Hm0] = getKatrina(())
%
%   Input:
%   varargin  = propertyName, propertyValue pairs:
%           surgefile:      surge-file hurricane
%           spectrumfile:   list with jonswapspectrums
%           outputpath:     path for the output-files
%
%   Output:
%   katrina   = hurricane data
%   steepness = wave-steepness
%   Hm0       = Hm0 of the hurricane
%
%   Example
%   getKatrina
%
%   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: $

%%
OPT = struct(...
    'surgefile', fullfile(fileparts(which(mfilename)), '..', 'InputData','KatrinaData', 'surge_edit.dat'),...
    'spectrumfile', fullfile(fileparts(which(mfilename)), '..', 'InputData', 'KatrinaData','jonswaplist_mf10.txt'),...
    'outputpath', fullfile(fileparts(which(mfilename)), '..', 'InputData'));

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

%% Surge katrina
fid = fopen(OPT.surgefile,'r');
    katrina.surge.surge_scan = textscan(fid, '%f32 %f32 %f32 %f32 %f32');
    katrina.surge.time=katrina.surge.surge_scan{1,1};
    katrina.surge.surge1=katrina.surge.surge_scan{1,2};
    katrina.surge.surge2=katrina.surge.surge_scan{1,3};
    katrina.surge.surge3=katrina.surge.surge_scan{1,4};
    katrina.surge.surge4=katrina.surge.surge_scan{1,5};
    katrina.surge.min1=min(katrina.surge.surge1);
    katrina.surge.min2=min(katrina.surge.surge2);
    katrina.surge.min3=min(katrina.surge.surge3);
    katrina.surge.min4=min(katrina.surge.surge4);
    katrina.surge.max1=max(katrina.surge.surge1);
    katrina.surge.max2=max(katrina.surge.surge2);
    katrina.surge.max3=max(katrina.surge.surge3);
    katrina.surge.max4=max(katrina.surge.surge4);
    katrina.surge.mean=sum(katrina.surge.surge1)/length(katrina.surge.surge1);
fclose(fid);


% %% input parameters Katrina
fid= fopen(OPT.spectrumfile);
    katrina.input.scan= textscan(fid, '%f32 %f32 %s','HeaderLines',1);
    katrina.input.time=katrina.input.scan{1,1};
    katrina.input.dt=katrina.input.time(1,1);
    katrina.input.files.list=katrina.input.scan{1,3};
fclose(fid);


%% open all the .inp files listed in katrina.input.files and read the Hm0 and fp values

for j=1:length(katrina.input.files.list)
    %read all the values
    fname=fullfile(fileparts(OPT.spectrumfile),katrina.input.files.list{j});
    fid=fopen (fname);
        katrina.input.files.scan= textscan(fid, '%s %s %f32');
        katrina.input.files.values.all=katrina.input.files.scan{1,3};
        katrina.input.files.values.Hm0=katrina.input.files.values.all(1,1);
        katrina.input.files.values.fp=katrina.input.files.values.all(2,1);
    fclose(fid);
    %collect all the values
    name{j}=['Hm0_jonswap_',num2str(j,'%02i')];
    Hm0(j)=katrina.input.files.values.Hm0;
    fp(j)=katrina.input.files.values.fp;
    period(j)=1/fp(j);
    wavelength(j)=(9.81*(period(j))^2)/(2*pi);
    steepness(j)=Hm0(j)/wavelength(j);
end

% dlmwrite(fullfile(OPT.outputpath,['Hm0_Run_',num2str(1,'%02i'),'.txt']),Hm0','precision','%.10f','delimiter','');