-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomputewaveclimate_CKD.m
279 lines (212 loc) · 10.2 KB
/
computewaveclimate_CKD.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
function computewaveclimate(inputFolder_rose,outputFolder_qsdif,plot_on)
% this version computes CERC, Kamphius, and Deigaard formulas of Qs
% this is the "deigaard look up table"
load DeigLook
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(inputFolder_rose)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', inputFolder_rose);
uiwait(warndlg(errorMessage));
return;
end
if ~isdir(outputFolder_qsdif)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', outputFolder_qsdif);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
infilePattern_rose = fullfile(inputFolder_rose, '*.mat'); % Change to whatever pattern you need.
input_files_rose = dir(infilePattern_rose);
for runs = 1 : length(input_files_rose)
runs
tic;
baseFileName_rose = input_files_rose(runs).name;
fullFileName_rose = fullfile(inputFolder_rose, baseFileName_rose);
%fprintf(1, 'Now reading %s\n', fullFileName);
load(fullFileName_rose);
[pathstr_rose,filename_rose,ext_rose] = fileparts(fullFileName_rose)
savename = [outputFolder_qsdif filename_rose '_qsdif.mat'];
% variables
%ShoreOrient = 72;
%ShelfOrient = 72; % for backrefraction computations - should backrefract compard to shelf, not shore orientation
% Then, ewith deep variables, bring the wves back in.
%cutang = 72; %angle to cut data around - don't go past 180
orients = 0; % shoreline orientation of normal to data array
orientdel = 5;
orientend = 180;
calcangles = (orientend - orients)/orientdel + 1
shornt = 0 % degrees (clockwise = positive) difference between location and array
g= 9.81; % That's gravity, holmes
pi = 3.1415; % ref. Archimedes (-232)
degtorad = pi/180; % convert radians to degrees
depth = 200; % m - depth @ WIS station - not really used here
binsize = 7.5; % um, size of the bins
binnumber = 360/binsize;
binarray = -180+binsize/2:binsize:180-binsize/2;
plotbinarray = -90:2*binsize:90;
% load data
% DO OUTFILE NAME, FOO
ldata = length(HInV);
%ff = zeros(ldata,5);
k = 0;
EnergyFluxarray = zeros(calcangles,360/binsize);
ShAngs = zeros(calcangles, 1);
QsRaws = zeros(calcangles,6);
Qss = zeros(calcangles, 6);
QssGross = zeros(calcangles, 6);
ASTs = zeros(calcangles,6,binnumber);
Diffs = zeros(calcangles, 6, binnumber);
Gammas = zeros(calcangles, 6);
TrueDiffs = zeros(calcangles, 6);
% where loop will start
for ShAng = orients:orientdel:orientend
[runs ShAng]
k = k+1;
% zero some stuff
ShAng;
EnergyFlux = zeros(1,360/binsize);
AST = zeros(6,360/binsize);
ASTSum = zeros(6,1);
Diff = zeros(6,360/binsize);
DiffSum = zeros(6,1);
Bad = 0; % bad data points
NotRef = 0;
for j = 1:ldata
H = HDeepV(j);
Ang = (mod(AngleDeepV(j)-ShAng+180,360)-180);
T = TIn(j);
if ((abs(Ang)<90))
for i = 1:binnumber
if ((((i-1)*binsize)-180 < Ang) && (Ang < i * binsize-180))
asign = sign(Ang);
Angle = abs(Ang);
% add up contribution to energy flux
HTscale = (H^(12/5)) * (T^(1/5));
EnergyFlux(i) = EnergyFlux(i) + HTscale;
% CERC formula
qs = -asign * HTscale * (cos(Angle*degtorad)^(1.2)) * (sin(Angle*degtorad));
AST(1,i) = AST(1,i) + qs;
ASTSum(1) = ASTSum(1) + abs(qs);
rc = -HTscale * (6/5 * ((sin(Angle*degtorad)^2) * (cos(Angle*degtorad)^(.2))) - cos(Angle*degtorad)^2.2 );
Diff(1,i) = Diff(1,i) + rc;
DiffSum(1) = DiffSum(1) + abs(rc);
% Kamphuis
HTscale = (H^1.84) * (T ^ 1.82);
qs = -asign * HTscale * (cos(Angle*degtorad)^0.92) * (sin(Angle*degtorad)^0.6);
AST(2,i) = AST(2,i) + qs;
ASTSum(2) = ASTSum(2) + abs(qs);
% reduce the importance of infinite answers
AngleKamp = Angle;
if (AngleKamp < 1)
AngleKamp = 1;
end
t1 = 0.92 * (sin(AngleKamp*degtorad)^1.6) * (cos(AngleKamp*degtorad)^-0.08);
t2 = 0.6 * (sin(AngleKamp*degtorad)^-0.4) * (cos(AngleKamp*degtorad)^1.6);
rc = (T ^ 1.82) * (H ^ 1.84) * (t2 - t1);
Diff(2,i) = Diff(2,i) + rc;
DiffSum(2) = DiffSum(2) + abs(rc);
% Deigaard
HTscale = (H^3.8) * (T^-0.5);
qs = -asign * HTscale * interp1(DeigASTAngles,DeigAST,Angle);
AST(3,i) = AST(3,i) + qs;
ASTSum(3) = ASTSum(3) + abs(qs);
rc = HTscale * interp1(DeigDiffAngles, DeigLookDiff, Angle);
Diff(3,i) = Diff(3,i) + rc;
DiffSum(3) = DiffSum(3) + abs(rc);
end
end
end
H = HInV(j);
Ang = (mod(AngleInV(j)-ShAng+180,360)-180);
if ((abs(Ang)<90))
for i = 1:binnumber
if ((((i-1)*binsize)-180 < Ang) && (Ang < i * binsize-180))
asign = sign(Ang);
Angle = abs(Ang);
% add up contribution to energy flux
HTscale = (H^(12/5)) * (T^(1/5));
EnergyFlux(i) = EnergyFlux(i) + HTscale;
% CERC formula
qs = -asign * HTscale * (cos(Angle*degtorad)^(1.2)) * (sin(Angle*degtorad));
AST(4,i) = AST(4,i) + qs;
ASTSum(4) = ASTSum(4) + abs(qs);
rc = -HTscale * (6/5 * ((sin(Angle*degtorad)^2) * (cos(Angle*degtorad)^(.2))) - cos(Angle*degtorad)^2.2 );
Diff(4,i) = Diff(4,i) + rc;
DiffSum(4) = DiffSum(4) + abs(rc);
% Kamphuis
HTscale = (H^1.84) * (T ^ 1.82);
qs = -asign * HTscale * (cos(Angle*degtorad)^0.92) * (sin(Angle*degtorad)^0.6);
AST(5,i) = AST(5,i) + qs;
ASTSum(5) = ASTSum(5) + abs(qs);
% reduce the importance of infinite answers
AngleKamp = Angle;
if (AngleKamp < 1)
AngleKamp = 1;
end
t1 = 0.92 * (sin(AngleKamp*degtorad)^1.6) * (cos(AngleKamp*degtorad)^-0.08);
t2 = 0.6 * (sin(AngleKamp*degtorad)^-0.4) * (cos(AngleKamp*degtorad)^1.6);
rc = (T ^ 1.82) * (H ^ 1.84) * (t2 - t1);
Diff(5,i) = Diff(5,i) + rc;
DiffSum(5) = DiffSum(5) + abs(rc);
% Deigaard
HTscale = (H^3.8) * (T^-0.5);
qs = -asign * HTscale * interp1(DeigASTAngles,DeigAST,Angle);
AST(6,i) = AST(6,i) + qs;
ASTSum(6) = ASTSum(6) + abs(qs);
rc = HTscale * interp1(DeigDiffAngles, DeigLookDiff, Angle);
Diff(6,i) = Diff(6,i) + rc;
DiffSum(6) = DiffSum(6) + abs(rc);
end
end
end
if mod(j,1000) == 0
j;
end
end
Qs = sum(AST,2) ./ ASTSum;
QsRaw = sum(AST,2);
Gamma = sum(Diff,2) ./ DiffSum;
TrueDiff = sum(Diff,2);
% QsNB = sum(ASTNB)/ASTSumNB;
% QsGrossNB = ASTSum;
% DiffNB = sum(RateContNB)/RateSumNB;
QsRaws(k,:) = QsRaw;
ShAngs(k) = ShAng;
Qss(k,:) = Qs;
QssGross(k,:) = ASTSum;
Gammas(k,:) = Gamma;
TrueDiffs(k,:) = TrueDiff;
ASTs(k,:,:) = AST(:,:);
Diffs(k,:,:) = Diff(:,:);
EnergyFluxarray(k,:) = EnergyFlux(:)';
end
highangle = (abs(binarray) > 45);
if plot_on
figure()
plot(ShAngs,Qss(:,1),'g','linewidth',1.5)
hold on
plot(ShAngs,Qss(:,2),'r','linewidth',1.5)
plot(ShAngs,Qss(:,3),'b','linewidth',1.5)
%XLim([-90 90])
%set(gca,'xtick',[plotbinarray])
line(ShAngs,zeros(calcangles,1),'color','k')
title(['Qs ', filename]);
legend('CERC','Kamp', 'Deig')
hold off
figure()
plot(ShAngs,Gammas(:,1),'g','linewidth',1.5)
hold on
plot(ShAngs,Gammas(:,2),'r','linewidth',1.5)
plot(ShAngs,Gammas(:,3),'b','linewidth',1.5)
%XLim([-90 90])
%set(gca,'xtick',[plotbinarray])
line(ShAngs,zeros(calcangles,1),'color','k')
title(['Diffs ', filename]);
legend('CERC','Kamp', 'Deig')
hold off
end
clear AngleDeepV HInV HDeepV AngleInV TIn
save(savename)
time_run = zeros(length(input_files_rose),1);
time_run(runs) = toc./60 %time each run takes in minutes
end
end