1 |
function [htel,hccw,hcw]=tellipse(xc,yc,u,phi_u,v,phi_v,per,skip,sc,part_flag) |
---|
2 |
%TELLIPSE plot ellipses from amp/phase specification of a vel field |
---|
3 |
% [htel,hccw,hcw]=tellipse(xc,yc,ua,up,va,vp,per,skip,sc,flag) |
---|
4 |
% |
---|
5 |
% TELLIPSE requires the following arguments: |
---|
6 |
% x - ellipse x-coordinate centers, usually node x's; |
---|
7 |
% y - ellipse y-coordinate centers, usually node y's; |
---|
8 |
% ua - east (u) component amplitudes |
---|
9 |
% up - east (u) component phases (degrees) |
---|
10 |
% va - north (v) component amplitudes |
---|
11 |
% vp - north (v) component phases (degrees) |
---|
12 |
% per - period of field in hours |
---|
13 |
% |
---|
14 |
% TELLIPSE allows the following optional arguments: |
---|
15 |
% skip - number of nodes to skip in subsampling field |
---|
16 |
% sc - scaling factor to use if per is 0. |
---|
17 |
% flag - flag for particle-excursion interpretation (0|1) |
---|
18 |
% |
---|
19 |
% NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
---|
20 |
% IF THE SCALING FACTOR NEEDS TO BE SPECIFIED, SKIP |
---|
21 |
% MUST ALSO BE SPECIFIED. IF FLAG IS SPECIFIED, |
---|
22 |
% SC AND SKIP MUST BE SPECIFIED, BOTH OF WHICH CAN BE SET |
---|
23 |
% TO 1. |
---|
24 |
% |
---|
25 |
% TELLIPSE scales the ellipses to 10% of the x-axis length |
---|
26 |
% if sc=1; this is the default. If sc=.5, the ellipse |
---|
27 |
% magnitudes are scaled to 5% of the x-axis length, |
---|
28 |
% in the same manner as VECPLOT. |
---|
29 |
% |
---|
30 |
% TELLIPSE expects the input phases to be in degrees and |
---|
31 |
% attemps to determine the units of the phaselag by computing |
---|
32 |
% the range of the phaselag columns in the input matrix. |
---|
33 |
% If this range is within [0,2*pi], TELLIPSE reports this as |
---|
34 |
% a potential problem. It does NOT abort due to the possibility |
---|
35 |
% of the phaselags correctly being in degrees and still having |
---|
36 |
% a range within [0,2*pi]. |
---|
37 |
% |
---|
38 |
% NOTES: 1) TELLIPSE plots CCW ellipses in blue and CW ellipses |
---|
39 |
% in red. |
---|
40 |
% 2) TELLIPSE requires atleast 2 points and vectors. |
---|
41 |
% |
---|
42 |
% Call as: [htel,hccw,hcw]=tellipse(x,y,ua,up,va,vp,per,skip,sc,flag); |
---|
43 |
% |
---|
44 |
% Written by : Brian O. Blanton |
---|
45 |
% |
---|
46 |
|
---|
47 |
% DEFINE ERROR STRINGS |
---|
48 |
err1=['Not enough input arguments; type "help tellipse"']; |
---|
49 |
err2=['You must specify both "skip" and "sc" if period is 0']; |
---|
50 |
err3=['Too many input arguments; type "help tellipse"']; |
---|
51 |
err4=['Length of x,y,u,v must be the same']; |
---|
52 |
err5=['Length of x,y,phi_u,phi_v must be the same']; |
---|
53 |
err6=['Length of x,y,u,v must be greater than 1']; |
---|
54 |
err7=['Particle excursion flag (arg 10) must be 0 or 1']; |
---|
55 |
warn1=str2mat([' Phases in input to TELLIPSE span'],... |
---|
56 |
[' less that 2*pi degrees and appear'],... |
---|
57 |
[' to be in radians. If the resulting '],... |
---|
58 |
[' plot looks wierd, this may be the'],... |
---|
59 |
[' problem.']); |
---|
60 |
|
---|
61 |
% Argument check |
---|
62 |
if nargin <7 |
---|
63 |
error(err1); |
---|
64 |
elseif nargin ==7 |
---|
65 |
if per==0 |
---|
66 |
error(err2); |
---|
67 |
end |
---|
68 |
sc=1; |
---|
69 |
skip=0; |
---|
70 |
elseif nargin ==8 |
---|
71 |
sc=1;part_flag=0; |
---|
72 |
elseif nargin==9 |
---|
73 |
part_flag=0; |
---|
74 |
elseif nargin==10 |
---|
75 |
if(part_flag~=0&part_flag~=1) |
---|
76 |
error(err7); |
---|
77 |
end |
---|
78 |
elseif nargin >10 |
---|
79 |
error(err3); |
---|
80 |
end |
---|
81 |
real_per=per; |
---|
82 |
real_freq=2*pi/real_per; |
---|
83 |
|
---|
84 |
curfig=gcf; |
---|
85 |
|
---|
86 |
%columnate input |
---|
87 |
xc=xc(:); |
---|
88 |
yc=yc(:); |
---|
89 |
u=u(:); |
---|
90 |
v=v(:); |
---|
91 |
phi_u=phi_u(:); |
---|
92 |
phi_v=phi_v(:); |
---|
93 |
deg_to_rad=pi/180; |
---|
94 |
|
---|
95 |
% check input vector lengths |
---|
96 |
if length(xc)~=length(yc) | length(xc)~=length(u) | length(xc)~=length(v) |
---|
97 |
error(err4); |
---|
98 |
end |
---|
99 |
if length(xc)~=length(phi_u) | length(xc)~=length(phi_v) |
---|
100 |
error(err5); |
---|
101 |
end |
---|
102 |
if length(xc)==1 |
---|
103 |
error(err6); |
---|
104 |
end |
---|
105 |
|
---|
106 |
|
---|
107 |
% compute range of phases |
---|
108 |
pharangeu=range(phi_u); |
---|
109 |
pharangev=range(phi_v); |
---|
110 |
if pharangeu<=2*pi | pharangev<=2*pi |
---|
111 |
% hwarn=warndlg(warn1,'WARNING!!'); |
---|
112 |
% pause(3) |
---|
113 |
end |
---|
114 |
|
---|
115 |
figure(curfig) |
---|
116 |
|
---|
117 |
% convert input phases to radians |
---|
118 |
phi_u=phi_u*deg_to_rad; |
---|
119 |
phi_v=phi_v*deg_to_rad; |
---|
120 |
|
---|
121 |
% subsample if skip !=0 |
---|
122 |
if skip~=0 |
---|
123 |
xc=xc(1:skip+1:length(xc)); |
---|
124 |
yc=yc(1:skip+1:length(yc)); |
---|
125 |
u=u(1:skip+1:length(u)); |
---|
126 |
v=v(1:skip+1:length(v)); |
---|
127 |
phi_u=phi_u(1:skip+1:length(phi_u)); |
---|
128 |
phi_v=phi_v(1:skip+1:length(phi_v)); |
---|
129 |
end |
---|
130 |
|
---|
131 |
% get ranges of x,y coordinates |
---|
132 |
xrangedata=range(xc); |
---|
133 |
yrangedata=range(yc); |
---|
134 |
|
---|
135 |
% if particle excursion mode, convert period to seconds and |
---|
136 |
% compute drogue excursion ellipse magnitudes. |
---|
137 |
if part_flag==1 |
---|
138 |
per=real_per*3600; |
---|
139 |
freq=2*pi/per; |
---|
140 |
% scale amplitudes to represent particle excursions and center one |
---|
141 |
% particle's excursion at node |
---|
142 |
us=u/freq; |
---|
143 |
vs=v/freq; |
---|
144 |
magscale=NaN; |
---|
145 |
vecscale=NaN; |
---|
146 |
else |
---|
147 |
per=0.; |
---|
148 |
scale=(10*sc)/100; |
---|
149 |
% Scale Velocity amplitude data to domain scale |
---|
150 |
magscale=max(max(abs(u)),max(abs(v))); |
---|
151 |
% magscale=max(sqrt(u.*u+v.*v)); |
---|
152 |
% scale by max vector size |
---|
153 |
us=u/magscale; |
---|
154 |
vs=v/magscale; |
---|
155 |
|
---|
156 |
%scale by range of x values |
---|
157 |
us=us*xrangedata; |
---|
158 |
vs=vs*xrangedata; |
---|
159 |
|
---|
160 |
%scale to 'scale' percent of x range |
---|
161 |
us=us*scale; |
---|
162 |
vs=vs*scale; |
---|
163 |
vecscale=xrangedata*scale; |
---|
164 |
end |
---|
165 |
|
---|
166 |
% COMPUTE TIDAL ELLIPSE PARAMETERS FROM AMP-PHASE INFORMATION |
---|
167 |
% NOTATION AS PER : Atlas of Tidal Elevation and Current |
---|
168 |
% Observations on the Northeast |
---|
169 |
% American Continental Shelf |
---|
170 |
% and Slope |
---|
171 |
% |
---|
172 |
% By: John A. Moody, Bradford Butman, |
---|
173 |
% Robert C. Beardsley, Wendell S. Brown, |
---|
174 |
% Peter Daifuku, James D. Irish, |
---|
175 |
% Dennis A Mayer, Harold O. Mofjeld, |
---|
176 |
% Brian Petrie, Steven Ramp, Peter Smith, |
---|
177 |
% and W. R. Wright |
---|
178 |
% |
---|
179 |
% U.S. Geological Survey Bulletin 1611 |
---|
180 |
% |
---|
181 |
A1=us.*cos(phi_u); |
---|
182 |
B1=us.*sin(phi_u); |
---|
183 |
A2=vs.*cos(phi_v); |
---|
184 |
B2=vs.*sin(phi_v); |
---|
185 |
Uplus =0.5*sqrt((A1+B2).*(A1+B2)+(A2-B1).*(A2-B1)); |
---|
186 |
Uminus=0.5*sqrt((A1-B2).*(A1-B2)+(A2+B1).*(A2+B1)); |
---|
187 |
|
---|
188 |
% Compute major and minor axis components |
---|
189 |
UMAJOR=Uplus+Uminus; |
---|
190 |
UMINOR=Uplus-Uminus; |
---|
191 |
|
---|
192 |
% Compute phase; not needed at this time |
---|
193 |
numer= 2*(A1.*B1) + 2*(A2.*B2); |
---|
194 |
denom= A1.*A1 - B2.*B2 + A2.*A2 - B1.*B1; |
---|
195 |
PHASE=0.5*atan2(numer,denom); |
---|
196 |
|
---|
197 |
% Compute orientation |
---|
198 |
numer= 2*(A1.*A2 + B1.*B2); |
---|
199 |
denom= A1.*A1 + B1.*B1 - (A2.*A2 + B2.*B2); |
---|
200 |
ORIEN=0.5*atan2(numer,denom); |
---|
201 |
|
---|
202 |
%if nargout==3 |
---|
203 |
% htel=UMAJOR; |
---|
204 |
% umi =UMINOR; |
---|
205 |
% ori =ORIEN; |
---|
206 |
% return |
---|
207 |
%end |
---|
208 |
|
---|
209 |
|
---|
210 |
% Get list of CCW- and CW-rotating ellipses |
---|
211 |
% If UMINOR is >0, rotation is CCW |
---|
212 |
% If UMINOR is <=0, rotation is CW |
---|
213 |
ccw=find(UMINOR>0); |
---|
214 |
cw=find(UMINOR<=0); |
---|
215 |
|
---|
216 |
% PLOT ELLIPSES |
---|
217 |
% SEND CCW TIDAL ELLIPSES TO ELLIPSE ROUTINE WITH COLOR blue |
---|
218 |
hccw=ellipse_east(xc(ccw),yc(ccw),UMAJOR(ccw),UMINOR(ccw),ORIEN(ccw),'b'); |
---|
219 |
set(hccw,'UserData','ellipse'); |
---|
220 |
set(hccw,'Tag','ellipse-ccw'); |
---|
221 |
% SEND CW TIDAL ELLIPSES TO ELLIPSE ROUTINE WITH COLOR red |
---|
222 |
hcw=ellipse_east(xc(cw),yc(cw),UMAJOR(cw),UMINOR(cw),ORIEN(cw),'r'); |
---|
223 |
set(hcw,'UserData','ellipse'); |
---|
224 |
set(hcw,'Tag','ellipse-cw'); |
---|
225 |
|
---|
226 |
% PLOT Phase Lines |
---|
227 |
% COMPUTE direction of flow and the speed for CCW ellipses at t=0. |
---|
228 |
time=0.; |
---|
229 |
omegat=time*real_freq; |
---|
230 |
numer=vs(ccw).*cos(omegat-phi_v(ccw)); |
---|
231 |
denom=us(ccw).*cos(omegat-phi_u(ccw)); |
---|
232 |
theta=atan2(numer,denom); |
---|
233 |
q=sqrt(us(ccw).*us(ccw).*cos(-phi_u(ccw)).*cos(-phi_u(ccw))+... |
---|
234 |
vs(ccw).*vs(ccw).*cos(-phi_v(ccw)).*cos(-phi_v(ccw))); |
---|
235 |
xf=xc(ccw)+q.*cos(theta); |
---|
236 |
yf=yc(ccw)+q.*sin(theta); |
---|
237 |
xp=[xc(ccw) xf NaN*ones(size(xc(ccw)))]'; |
---|
238 |
yp=[yc(ccw) yf NaN*ones(size(yc(ccw)))]'; |
---|
239 |
xp=xp(:); |
---|
240 |
yp=yp(:); |
---|
241 |
hplccw=line(xp,yp,'Color','b'); |
---|
242 |
set(hplccw,'Tag','ellipse-ccw'); |
---|
243 |
|
---|
244 |
% COMPUTE direction of flow and the speed for CW ellipses at t=0. |
---|
245 |
numer=vs(cw).*cos(omegat-phi_v(cw)); |
---|
246 |
denom=us(cw).*cos(omegat-phi_u(cw)); |
---|
247 |
theta=atan2(numer,denom); |
---|
248 |
q=sqrt(us(cw).*us(cw).*cos(-phi_u(cw)).*cos(-phi_u(cw))+... |
---|
249 |
vs(cw).*vs(cw).*cos(-phi_v(cw)).*cos(-phi_v(cw))); |
---|
250 |
xf=xc(cw)+q.*cos(theta); |
---|
251 |
yf=yc(cw)+q.*sin(theta); |
---|
252 |
xp=[xc(cw) xf NaN*ones(size(xc(cw)))]'; |
---|
253 |
yp=[yc(cw) yf NaN*ones(size(yc(cw)))]'; |
---|
254 |
xp=xp(:); |
---|
255 |
yp=yp(:); |
---|
256 |
hplcw=line(xp,yp,'Color','r'); |
---|
257 |
set(hplcw,'Tag','ellipse-cw'); |
---|
258 |
|
---|
259 |
hccw=[hccw hplccw]; |
---|
260 |
hcw=[hcw hplcw]; |
---|
261 |
|
---|
262 |
|
---|
263 |
% CREATE DATA OBJECT THAT CONTAINS THE TIDAL ELLIPSE PARAMETERS; |
---|
264 |
% THIS OBJECT WILL BE PLOTTED AT THE ORIGIN BUT AS INVISIBLE. THIS |
---|
265 |
% ALLOWS US TO FILL THE 'UserData' PARAMETER WITH ELLIPSE DATA |
---|
266 |
% EVEN THOUGH THE OBJECT IS "NOT THERE". THE HANDLE TO THIS "ZERO" |
---|
267 |
% OBJECT WILL BE RETURNED EVEN THOUGH IT DOES NOT REFERENCE THE ELLIPSE |
---|
268 |
% OBJECTS ON SCREEN. |
---|
269 |
% |
---|
270 |
% The columns of the 'UserData' block are filled with the following: |
---|
271 |
% 1: ellipse x-coordinate centers |
---|
272 |
% 2: ellipse y-coordinate centers |
---|
273 |
% 3: major axis magnitudes |
---|
274 |
% 4: minor axis magnitudes |
---|
275 |
% 5: ellipse orientation |
---|
276 |
% |
---|
277 |
% At the bottom of this matrix is an extra line so that the period of |
---|
278 |
% the ellipses can be encoded in 'UserData'. The first 4 entries are |
---|
279 |
% 'NaN'; the last is the period in hours. This means that the columns |
---|
280 |
% contain one more record than the number of ellipse centers. |
---|
281 |
htel=line(0,0,'Visible','off'); |
---|
282 |
set(htel,'Tag','ellipse data'); |
---|
283 |
UD_matrix=[xc yc UMAJOR UMINOR ORIEN;xrangedata magscale vecscale per real_per]; |
---|
284 |
set(htel,'UserData',UD_matrix); |
---|
285 |
|
---|
286 |
return |
---|
287 |
% |
---|
288 |
%LabSig Brian O. Blanton |
---|
289 |
% Department in Marine Sciences |
---|
290 |
% 12-7 Venable Hall |
---|
291 |
% CB# 3300 |
---|
292 |
% University of North Carolina |
---|
293 |
% Chapel Hill, NC |
---|
294 |
% 27599-3300 |
---|
295 |
% |
---|
296 |
% brian_blanton@unc.edu |
---|
297 |
% |
---|