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.
105 lines
4.3 KiB
Matlab
105 lines
4.3 KiB
Matlab
7 years ago
|
function nswaves = fmikeos2ns(oswaves, LookUps, site, contour, location)
|
||
|
% Written by Joshua Simmons (WRL) 03/11/2014
|
||
|
% to transform waves from offshore (OS) to nearshore (NS) using MIKE21 model
|
||
|
% oswaves - OS wave data - oswaves.Hsig(Significant wave height)/
|
||
|
% oswaves.Tp1(Peak period)/oswaves.Wdir(Incident wave direction)
|
||
|
% LookUps - MIKE21 wave model output in file "OEH_ARC_PointOutput.mat"
|
||
|
% site - embayment of interest - i.e. 'Narrabeen'
|
||
|
% contour - 10 or 15 (m) contour for NS output
|
||
|
% location - either pure S co-ord (see Mitchell Harley's xyz2spz
|
||
|
% transformation) or location.E and location.N - refers to output
|
||
|
% location for NS waves (gets nearest MIKE21 point)
|
||
|
%
|
||
|
%V1.1 - updated by Joshua Simmons 21/01/2015 to patch Wamberal/Wanda
|
||
|
%error.
|
||
|
|
||
|
%find site and contour indices
|
||
|
siteidx = getnameidx(LookUps(:,2), site);
|
||
|
|
||
|
%apply fix for Wamberal and Wanda
|
||
|
% from TM on 21/01/2015: "I've found an error in the .mat file for the
|
||
|
% look-up tables; in the pdf I say that all output for all locations runs
|
||
|
% north to south - for Wamberal and Wanda it seems I've output them south to north.
|
||
|
% So if you are using output from these two sites, if you haven't realised already,
|
||
|
% alongshore gradients will look inverted."
|
||
|
for aa = 1:2;
|
||
|
LookUps{6,1}{aa,1} = flipud(LookUps{6,1}{aa,1}); LookUps{6,1}{aa,1}(:,1) = flipud(LookUps{6,1}{aa,1}(:,1));
|
||
|
LookUps{7,1}{aa,1} = flipud(LookUps{7,1}{aa,1}); LookUps{7,1}{aa,1}(:,1) = flipud(LookUps{7,1}{aa,1}(:,1));
|
||
|
end
|
||
|
|
||
|
if contour == 10
|
||
|
contouridx = 1;
|
||
|
elseif contour == 15;
|
||
|
contouridx = 2;
|
||
|
else
|
||
|
error('Contour information not available, select either 10 or 15m contour')
|
||
|
end
|
||
|
|
||
|
%extract scenarios for easy lookup
|
||
|
scenariosidx = getnameidx(LookUps(:,2), 'Offshore Wave Scenarios');
|
||
|
scenarios = LookUps{scenariosidx,1};
|
||
|
|
||
|
%get nearest location available for output
|
||
|
Eouts = LookUps{siteidx,1}{contouridx,1}(:,2);
|
||
|
Nouts = LookUps{siteidx,1}{contouridx,1}(:,3);
|
||
|
|
||
|
if strcmp(site,'Narrabeen')
|
||
|
%compares closes alongshore spacing (s) for log-spiral narrabeen
|
||
|
xyz_data.x = cell2mat(Eouts);
|
||
|
xyz_data.y = cell2mat(Nouts);
|
||
|
xyz_data.z = zeros(size(Eouts));
|
||
|
spz = xyz2spz(xyz_data,'NARRA');
|
||
|
[~,locationidx] = min(abs(location-spz.s));
|
||
|
else
|
||
|
%gets nearest output point
|
||
|
dists = sqrt((location.E-cell2mat(Eouts)).^2+(location.N-cell2mat(Nouts)).^2);
|
||
|
[~,locationidx] = min(abs(dists));
|
||
|
end
|
||
|
|
||
|
fcount = 1;
|
||
|
%loop through oswaves and lookup nswaves
|
||
|
for ii = 1:length(oswaves.Hsig)
|
||
|
tmpHs = oswaves.Hsig(ii);
|
||
|
tmpTp = oswaves.Tp1(ii);
|
||
|
tmpWdir = oswaves.Wdir(ii);
|
||
|
|
||
|
%find closest scenario match
|
||
|
[~,Hsidx] = min(abs(tmpHs-scenarios(:,1)));
|
||
|
tmpHsround = scenarios(Hsidx,1);
|
||
|
[~,Tpidx] = min(abs(tmpTp-scenarios(:,2)));
|
||
|
tmpTpround = scenarios(Tpidx,2);
|
||
|
[~,Wdiridx] = min(abs(tmpWdir-scenarios(:,3)));
|
||
|
tmpWdirround = scenarios(Wdiridx,3);
|
||
|
|
||
|
iter1ind = find(scenarios(:,3) == tmpWdirround);
|
||
|
iter2ind = find(scenarios(iter1ind,2) == tmpTpround);
|
||
|
iter3ind = find(scenarios(iter1ind(iter2ind),1) == tmpHsround);
|
||
|
|
||
|
iter4ind = iter1ind(iter2ind(iter3ind));
|
||
|
|
||
|
%now get ns lookup information if available
|
||
|
if isempty(iter4ind)
|
||
|
%get the closest wave height to scenario chosen
|
||
|
[~,iter3ind] = min(abs(tmpHs-scenarios(iter1ind(iter2ind),1)));
|
||
|
iter4ind = iter1ind(iter2ind(iter3ind));
|
||
|
diffHs = scenarios(iter4ind,1)-tmpHs;
|
||
|
disp(['No match found for oswaves(' num2str(ii) ') wave height off by ' num2str(diffHs) 'm']);
|
||
|
end
|
||
|
|
||
|
nstmp = LookUps{siteidx,1}{contouridx,1}{locationidx,4}(iter4ind,:);
|
||
|
%store the values from the lookup table
|
||
|
nswaves.Hsig(ii,1) = nstmp(1);
|
||
|
nswaves.Hmax(ii,1) = nstmp(2);
|
||
|
nswaves.Tp1(ii,1) = nstmp(3);
|
||
|
nswaves.T01(ii,1) = nstmp(4);
|
||
|
nswaves.Wdir(ii,1) = nstmp(5);
|
||
|
nswaves.power(ii,1) = nstmp(6);
|
||
|
end
|
||
|
try
|
||
|
nswaves.date = oswaves.date;
|
||
|
nswaves.time = oswaves.time;
|
||
|
nswaves.datenums = oswaves.datenums;
|
||
|
catch
|
||
|
nswaves.datenums = oswaves.datenums;
|
||
|
end
|
||
|
end
|