You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.9 KiB
Matlab

7 years ago
% Written by Joshua Simmons 11/02/2015 and updated 20/01/2016
% to convert from fielddata storage struct to SBEACH compatible format.
clear
clc
%% Settings
%profiledata locations
basedatapath = 'D:\7 Erosion Models\a_nb_model_comparison\input_data\';
setupoutputpath = 'D:\7 Erosion Models\a_nb_model_comparison\sbeach\model_setup\setup_folders\';
infooutpath = 'D:\7 Erosion Models\a_nb_model_comparison\sbeach\model_setup\setup_info\';
%meta
site = 'monavale';
% stormid = '2007';
% stormid = '2011';
% stormid = '2014';
stormid = '2015';
%write file to
writetofile = 1; %boolean 1 = write to file, 0 = just SBEACHout.
% other parameters;
sbts = 5; %time step length minutes
%% Code - format the data
%load profile data - account for different data names - lin/poly
pfdata = load([basedatapath 'morphology\processed\morphology_' site '_' stormid '.mat']);
fns1 = fieldnames(pfdata);
pfdata = pfdata.(fns1{1});
%load wavedata
wavedata = load([basedatapath 'fielddata\wave\processed\wavedata_' site '_' stormid '.mat']);
fns2 = fieldnames(wavedata);
wavedata = wavedata.(fns2{1});
%load tidedata
tidedata = load([basedatapath 'fielddata\tide\processed\tidedata_' site '_' stormid '.mat']);
fns3 = fieldnames(tidedata);
tidedata = tidedata.(fns3{1});
% load the profileinfo file
profileinfo = load([infooutpath 'profileinfo_' site '.mat']);
fns2 = fieldnames(profileinfo);
profileinfo = profileinfo.(fns2{1});
%check for dimension match
if length(pfdata.data) ~= length(wavedata.ns.data)
error('Wave data information does not match the morphology data')
end
%check start time
if tidedata.time(1) ~= wavedata.os.datenums(1)
error('Start times for wave and tide data dont match')
end
if tidedata.time(end) ~= wavedata.os.datenums(end)
error('End times for wave and tide data dont match. Make sure start/end times are hourly (for wave data).')
end
%check and allocate time parameters;
sbtidetime = round((tidedata.time - tidedata.time(1))*24*60);
%check time steps
diffsbtidetime = diff(sbtidetime);
if any(diffsbtidetime~=diffsbtidetime(1))
error('Inconsistent time steps in tide data');
end
%now check the wave data lines up (os only required the rest if copied)
sbwavetime = round((wavedata.os.datenums - wavedata.os.datenums(1))*24*60);
diffsbwavetime = diff(sbwavetime);
if any(diffsbwavetime~=diffsbwavetime(1))
error('Inconsistent time steps in wave data');
end
%get the depth contour
sbdepth = wavedata.ns.contour(1:2);
%do the modelling
for ii = 1:length(pfdata.data)
if ~isnan(pfdata.data(ii).initial.x)
pfid = ['PF' num2str(ii)];
%get profile info
prifile = [pfdata.data(ii).initial.x pfdata.data(ii).initial.z]; %initial pf
%angle of pf from true north
pfangle = profileinfo.data(ii).TN; %angle from true north
%create the other information required for files
% for .WAV and .ANG file - wave height/period and angle files
wavfile = [wavedata.ns.data(ii).Hsig wavedata.ns.data(ii).Tp1];
angfile = -1*(wavedata.ns.data(ii).Wdir-pfangle); %correct to SBEACH wave angle convention as per report 3 pg 19
wavets = sbwavetime(2)-sbwavetime(1); %wave time step minutes
% for .ELV file - water elevation file
elvfile = tidedata.tide;
tidets = sbtidetime(2)-sbtidetime(1); %tide time step
totaltimewav = sbwavetime(end);
totaltimetide = sbtidetime(end);
if totaltimewav - totaltimetide ~= 0
disp('Warning: difference between wave and tide total times')
end
totaltime = totaltimetide;
totalmodeltimesteps = totaltime/sbts;
disp([pfid ':'])
disp(['A.10 - Total Time steps: ' num2str(totalmodeltimesteps)])
disp(['B.6 - DTWAV: ' num2str(wavets)])
disp(['B.11 - DTANG: ' num2str(wavets)])
disp(['B.12 - DMEAS: ' sbdepth])
disp(['B.20 - DTELEV: ' num2str(tidets)])
outpath = [setupoutputpath 'sb_' site '_' stormid '_' pfid '\'];
cfginfo.NDT = totalmodeltimesteps;
cfginfo.DT = sbts;
cfginfo.DXC = pfdata.data(ii).initial.x(2)-pfdata.data(ii).initial.x(1);
cfginfo.NDX = length(pfdata.data(ii).initial.x)-1;
[cfginfo.XSTART,~] = min(pfdata.data(ii).initial.x);
cfginfo.DTWAV = wavets;
cfginfo.DTANG = wavets;
cfginfo.DMEAS = str2double(sbdepth);
cfginfo.DTELEV = tidets;
%write to files
if writetofile
if ~exist(outpath, 'dir')
mkdir(outpath)
else
delete([outpath '\*'])
end
writetofilepri(prifile, outpath, [site '_' stormid '_' pfid])
writetofilewav(wavfile, outpath, [site '_' stormid '_' pfid])
writetofileang(angfile, outpath, [site '_' stormid '_' pfid])
writetofileelv(elvfile, outpath, [site '_' stormid '_' pfid])
save([infooutpath 'cfginfo_' site '_' stormid '_' pfid '.mat'],'cfginfo')
end
end
end