NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/matlab_cen/tellipse_cen.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 %
2 % TELLIPSE plot ellipses from amp/phase specification of a velocity field
3 %
4 % htel=tellipse(xc,yc,ua,up,va,vp,per,skip,sc)
5 %
6 %          TELLIPSE requires the following arguments:
7 %              xc   - ellipse x-coordinate centers, usually node x's;
8 %              yc   - ellipse y-coordinate centers, usually node y's;
9 %              ua   - east (u) component amplitudes         
10 %              up   - east (u) component phases (degrees)       
11 %              va   - north (v) component amplitudes         
12 %              vp   - north (v) component phases (degrees)       
13 %              per  - period of field in hours
14 %
15 %          TELLIPSE allows the following optional arguments:
16 %              skip - number of nodes to skip in subsampling field
17 %              sc   - scaling factor to use if per is 0.
18 %
19 %          If per is input as 0, TELLIPSE scales the ellipses to
20 %          10% of the x-axis length if sc=1, 5% of the x-axis length
21 %          if sc=.5, etc., in the same manner as VECPLOT.  In this case,
22 %          you must specify both "skip" and "sc". 
23 %
24 %          If per is input as non-zero, TELLIPSE plots ellipses as
25 %          particle excursions from the ellipse center. Scaling
26 %          factor sc is ingored. 
27 %
28 %          TELLIPSE expects the input phases to be in degrees and
29 %          attemps to determine the units of the phaselag by computing
30 %          the range of the phaselag columns in the input matrix.
31 %          If this range is within [0,2*pi], TELLIPSE reports this as
32 %          a potential problem.  It does NOT abort due to the possibility
33 %          of the phaselags correctly being in degrees and still having
34 %          a range within [0,2*pi].
35 %
36 %          NOTES: 1) TELLIPSE plots CCW ellipses in red and CW ellipses
37 %                    in yellow.
38 %                 2) TELLIPSE requires atleast 2 points and vectors.
39 %
40 % Call as: htel=tellipse(xc,yc,ua,up,va,vp,per,skip,sc);
41 %
42 % Written by : Brian O. Blanton
43 %
44 function  [UMAJOR,UMINOR,ORIEN,PHASE]=tellipse_cen(xc,yc,u,phi_u,v,phi_v,per,skip,sc)
45
46 % DEFINE ERROR STRINGS
47 err1=['Not enough input arguments; type "help tellipse"'];
48 err2=['You must specify both "skip" and "sc" if period is 0'];
49 err3=['Too many input arguments; type "help tellipse"'];
50 err4=['Length of x,y,u,v must be the same'];
51 err5=['Length of x,y,phi_u,phi_v must be the same'];
52 err6=['Length of x,y,u,v must be greater than 1'];
53 warn1=str2mat([' Phases in input to TELLIPSE do '],...
54               [' appear to be in radians.  If the'],...
55               [' result looks wierd, this may be the'],...
56               [' problem.']);
57
58 % Argument check
59 if nargin <7
60    error(err1);
61 elseif nargin ==7
62    if per==0
63       error(err2);
64    end
65    sc=1;
66    skip=0;
67 elseif nargin ==8
68    sc=1;
69 elseif nargin >9
70    error(err3);
71 end
72
73 curfig=gcf;
74
75 %columnate input
76 xc=xc(:);
77 yc=yc(:);
78 u=u(:);
79 v=v(:);
80 phi_u=phi_u(:);
81 phi_v=phi_v(:);
82 deg_to_rad=pi/180;
83
84 % check input vector lengths
85 if length(xc)~=length(yc) | length(xc)~=length(u) | length(xc)~=length(v)
86    error(err4);
87 end
88 if length(xc)~=length(phi_u) | length(xc)~=length(phi_v)
89    error(err5);
90 end
91 if length(xc)==1
92    error(err6);
93 end
94
95
96 % compute range of phases
97 pharangeu=range(phi_u);
98 pharangev=range(phi_v);
99 if pharangeu<=2*pi | pharangev<=2*pi
100    hwarn=warndlg(warn1,'WARNING!!');
101    pause(3)
102 end
103
104 figure(curfig)
105
106 % convert input phases to radians
107 phi_u=phi_u*deg_to_rad;
108 phi_v=phi_v*deg_to_rad;
109
110 % subsample if skip !=0
111 if skip~=0
112    xc=xc(1:skip+1:length(xc));
113    yc=yc(1:skip+1:length(yc));
114    u=u(1:skip+1:length(u));
115    v=v(1:skip+1:length(v));
116    phi_u=phi_u(1:skip+1:length(phi_u));
117    phi_v=phi_v(1:skip+1:length(phi_v));
118 end
119 us=u;
120 vs=v;
121 % COMPUTE TIDAL ELLIPSE PARAMETERS FROM AMP-PHASE INFORMATION
122 % NOTATION AS PER : Atlas of Tidal Elevation and Current
123 %                   Observations on the Northeast
124 %                   American Continental Shelf
125 %                   and Slope
126 %
127 %                   By: John A. Moody, Bradford Butman,
128 %                   Robert C. Beardsley, Wendell S. Brown,
129 %                   Peter Daifuku, James D. Irish,
130 %                   Dennis A Mayer, Harold O. Mofjeld,
131 %                   Brian Petrie, Steven Ramp, Peter Smith,
132 %                   and W. R. Wright
133
134 %                   U.S. Geological Survey Bulletin 1611
135 %
136 A1=us.*cos(phi_u);
137 B1=us.*sin(phi_u);
138 A2=vs.*cos(phi_v);
139 B2=vs.*sin(phi_v);
140 Uplus =0.5*sqrt((A1+B2).*(A1+B2)+(A2-B1).*(A2-B1));
141 Uminus=0.5*sqrt((A1-B2).*(A1-B2)+(A2+B1).*(A2+B1));
142
143 % Compute major and minor axis components
144 UMAJOR=Uplus+Uminus;
145 UMINOR=Uplus-Uminus;
146
147 % Compute phase; not needed at this time
148 numer= 2*(A1.*B1) + 2*(A2.*B2);
149 denom= A1.*A1 - B2.*B2 + A2.*A2 - B1.*B1;
150 PHASE=0.5*atan2(numer,denom);
151
152 % Compute orientation
153 numer= 2*(A1.*A2 + B1.*B2);
154 denom= A1.*A1 + B1.*B1 - (A2.*A2 + B2.*B2);
155 ORIEN=0.5*atan2(numer,denom);
156 return
157 %
158 %        Brian O. Blanton
159 %        Curr. in Marine Science
160 %        15-1A Venable Hall
161 %        CB# 3300
162 %        Uni. of North Carolina
163 %        Chapel Hill, NC
164 %                 27599-3300
165 %
166 %        919-962-4466
167 %        blanton@marine.unc.edu
168 %
Note: See TracBrowser for help on using the browser.