function [regime]=scaleKatrina(katrina,i,scaling,steepness,Hm0,modeltrain_number,varargin)


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{:});

%% Create a new jonswap.txt file and new jonswap input files
outputdir = fullfile(OPT.outputpath,['Modeltrain_number_',num2str(modeltrain_number,'%02i')],['Storm_',num2str(i,'%02i')]);
mkdir(outputdir);
copyfile(OPT.spectrumfile,fullfile(outputdir,['jonswaplist_storm_',num2str(i,'%02i'),'.txt']));
copyfile(OPT.surgefile,fullfile(outputdir,['Scaled_Surge_Storm_',num2str(i,'%02i'),'.dat']));

%% Create the new jonswap input files
% filenames={zeros(length(katrina.input.files.list))};
for j= 1:length(katrina.input.files.list)
    copyfile(fullfile(OPT.spectrumfile,'..',['jonswap' num2str(j,'%02i') '.inp']),fullfile(outputdir,['Storm_',num2str(i,'%02i'),'_jonswap' num2str(j,'%02i') '.inp']));
    filenames{j}= ['Storm_',num2str(i,'%02i'),'_jonswap' num2str(j,'%02i') '.inp'];
end
regime.input.files.list=filenames';


for j=1:length(katrina.input.files.list)
    H_new(j)=Hm0(j)/scaling;
    L_new(j)=H_new(j)/steepness(j);
    Tp_new(j)=sqrt((2*pi*L_new(j))/9.81);
    
    fid = fopen(fullfile(outputdir,[regime.input.files.list{j}]),'r');
    regime.input.files.scan= textscan(fid, '%s %s %f32');
    regime.input.files.values.all=regime.input.files.scan{1,3};
    regime.input.files.values.all(1,1)=H_new(j);
    regime.input.files.values.all(2,1)=1/(Tp_new(j));
    fclose(fid);
    
    fid = fopen(fullfile(outputdir,[regime.input.files.list{j}]),'w');
    fprintf(fid,'%6s%f\n','Hm0 = ',regime.input.files.values.all(1));
    fprintf(fid,'%5s%f\n','fp = ',regime.input.files.values.all(2));
    fprintf(fid,'%9s%f\n','mainang = ',regime.input.files.values.all(3));
    fprintf(fid,'%4s%f\n','s = ',regime.input.files.values.all(4));
    fclose(fid);
end


fid = fopen(fullfile(outputdir,['jonswaplist_storm_',num2str(i,'%02i'),'.txt']),'r');
regime.input.files.scan = textscan(fid, '%f32 %f32 %s','HeaderLines',1);
regime.input.files.scan{1,3} = regime.input.files.list;
fclose(fid);
fid = fopen(fullfile(outputdir,['jonswaplist_storm_',num2str(i,'%02i'),'.txt']),'wt');
fprintf(fid,'%8s\n','FILELIST');
for j=1:length(katrina.input.files.list)
    fprintf(fid,'%5u%4.1f%34s\n',1800,1.0,['Storm_',num2str(i,'%02i'),'_jonswap' num2str(j,'%02i') '.inp']);
end
fclose(fid);

fid = fopen(fullfile(outputdir,['jonswaplist_storm_',num2str(i,'%02i'),'.txt']),'wt');
fprintf(fid,'%8s\n','FILELIST');
for j=1:length(katrina.input.files.list)
    fprintf(fid,'%5u%4.1f%34s\n',1800,1.0,['Storm_',num2str(i,'%02i'),'_jonswap' num2str(j,'%02i') '.inp']);
end
fclose(fid);

%% Create the new surge file
%first we derive a max surge for the regime according to the derived relation

for j=1:length(katrina.input.files.list)
    if H_new(j)>=4
        regime.surge_relation(j)=((H_new(j)-3.72)/0.56);
    else
        regime.surge_relation(j)=((0.5/4)*H_new(j));%(katrina.surge.surge1(end));
    end
end

scaling_surge1=(katrina.surge.max1/max(regime.surge_relation));
scaling_surge2=(katrina.surge.max2/max(regime.surge_relation));
scaling_surge3=(katrina.surge.max3/max(regime.surge_relation));
scaling_surge4=(katrina.surge.max4/max(regime.surge_relation));

regime.surge.scaled1=katrina.surge.surge1/scaling_surge1;
regime.surge.scaled2=katrina.surge.surge2/scaling_surge2;
regime.surge.scaled3=katrina.surge.surge3/scaling_surge3;
regime.surge.scaled4=katrina.surge.surge4/scaling_surge4;


fid = fopen(fullfile(outputdir,['Scaled_Surge_Storm_',num2str(i,'%02i'),'.dat']),'w');
for j=1:length(katrina.input.files.list)+1
    fprintf(fid,'%f32 %f32 %f32 %f32 %f32\n',katrina.surge.time(j),regime.surge.scaled1(j),regime.surge.scaled2(j),regime.surge.scaled3(j),regime.surge.scaled4(j));
end
fclose(fid);
regime.waves=H_new;


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