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

root/gliderproc/trunk/MATLAB/opnml/mat4/vecplot2.m

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

Initial import of Stark code.

Line 
1 function  retval=vecplot2(xin,yin,uin,vin,sc,sclab,scale_xor,scale_yor)
2 %VECPLOT2 routine to plot vectors. 
3 % VECPLOT2 draws vectors on the current figure, at (x,y)
4 % locations determined in one of two ways.  If the first
5 % argument to VECPLOT is a fem_grid_struct, then VECPLOT
6 % extracts the FEM domain coordinates as the vector origins.
7 % Otherwise, the user supplies the (x,y) coordinates
8 % explicitly.  This flexibility exists because vector
9 % plotting does not require any knowledge of nodal
10 % connectivity, and perhaps the (u,v) data are not
11 % from a FEM model output.
12 %
13 % VECPLOT scales the magnitude of
14 % (u,v) by the magnitude of max(abs(u,v)) and then
15 % forces a vector of magnitude sc to be 10% of the x data
16 % range.  By default, sc = 1., so that a 1 m/s vector will
17 % be scaled to 10% of the x data range.  If sc=.5, then
18 % a vector magnitude of 50 cm/s  will be scaled to 10% of the
19 % x data range.  Decreasing sc serves to make the vectors
20 % appear larger.  VECPLOT then prompts the user to place
21 % the vector scale on the figure, unless scale_xor,scale_yor
22 % is specified (see below).
23 %
24 % hv=vecplot(x,y,u,v,sc,sclab)
25 % OR
26 % hv=vecplot(fem_grid_struct,u,v,sc,sclab)
27 %
28 %     
29 %   INPUT:   fem_grid_struct  (from LOADGRID, see FEM_GRID_STRUCT)
30 %            OR
31 %            x,y    - vector origins
32 %            u,v    - vector amplitudes
33 %            These inputs are optional, but if one is needed, all
34 %            preceeding it wil be required.
35 %            sc     - vector scaler; (optional; default = 1.)
36 %            sclab  - label for vector scale; (optional; default = 'cm/s')
37 %            scale_xor,scale_yor  -  location to place vector scale
38 %
39 %  OUTPUT:   h - vector of handles to the vector lines drawn, the
40 %                scale vector, and the scale vector text.
41 %
42 %   NOTES:   VECPLOT requires atleast 2 coordinates and vectors.
43 %
44 %    CALL:   hv=vecplot(x,y,u,v,sc,sclab)
45 %     or
46 %            hv=vecplot(fem_grid_struct,u,v,sc,sclab)
47 %
48 % Written by : Brian O. Blanton
49 %
50
51 if nargin==0,
52    disp('Call as: hv=vecplot(x,y,u,v,sc,sclab) OR ')
53    disp('         hv=vecplot(fem_grid_struct,u,v,sc,sclab)')
54    return
55 end
56
57 % DEFINE ERROR STRINGS
58 err1=['Not enough input arguments; type "help vecplot2"'];
59 err2=['Too many input arguments; type "help vecplot2"'];
60 err3=['Length of x,y,u,v must be the same'];
61 err4=['Length of x,y,u,v must be greater than 1'];
62
63 %
64 % save the current value of the current figure's WindowButtonDownFcn,
65 % WindowButtonMotionFcn, and WindowButtonUpFcn
66 %
67 WindowButtonDownFcn=get(gcf,'WindowButtonDownFcn');
68 WindowButtonMotionFcn=get(gcf,'WindowButtonMotionFcn');
69 WindowButtonUpFcn=get(gcf,'WindowButtonUpFcn');
70 set(gcf,'WindowButtonDownFcn','');
71 set(gcf,'WindowButtonMotionFcn','');
72 set(gcf,'WindowButtonUpFcn','');
73
74 % Argument check
75 if nargin < 4
76    error(err1);
77 elseif nargin > 8
78    error(err2);
79 end
80
81 % Is the first argument a structure?
82 if isstruct(xin)
83    % Then is it valid?
84    if ~is_valid_struct(fem_grid_struct)
85       error('fem_grid_struct to VECPLOT not valid')
86    end
87    fem_grid_struct=xin;
88    xin=fem_grid_struct.x;
89    yin=fem_grid_struct.y;
90 end
91  
92 % process argument list
93 if nargin==4
94    sc=1.;
95    sclab='cm/s';     
96 elseif nargin==5
97    sclab='cm/s';     
98 end
99 sclab=[' ' sclab];
100 col='b';
101
102 if length(xin)~=length(yin) | ...
103    length(xin)~=length(uin) | ...
104    length(xin)~=length(vin)
105    error(err3);
106 end
107 if length(xin)==1
108    error(err4);
109 end
110
111 xin=xin(:);
112 yin=yin(:);
113 uin=uin(:);
114 vin=vin(:);
115
116 % SCALE VELOCITY DATA TO RENDERED WINDOW SCALE
117 %
118 RLs= get(gca,'XLim');
119 xr=RLs(2)-RLs(1);
120 X1=RLs(1);
121 X2=RLs(2);
122 RLs= get(gca,'YLim');
123 yr=RLs(2)-RLs(1);
124 Y1=RLs(1);
125 Y2=RLs(2);
126
127 % IF RenderLimits NOT SET, USE RANGE OF DATA
128 %
129 if(xr==0|yr==0)
130    error('Axes must have been previously set for VECPLOT2 to work');
131 end
132 pct10=xr/10;
133
134 %FILTER DATA THROUGH VIEWING WINDOW
135 %
136 filt=find(xin>=X1&xin<=X2&yin>=Y1&yin<=Y2);
137 x=xin(filt);
138 y=yin(filt);
139 u=uin(filt);
140 v=vin(filt);
141
142 % SCALE BY MAX VECTOR SIZE IN U AND V
143 %
144 us=u/sc;
145 vs=v/sc;
146
147 % SCALE TO 10 PERCENT OF X RANGE
148 %
149 us=us*pct10;
150 vs=vs*pct10;
151  
152 % SEND VECTORS TO DRAWVEC ROUTINE
153 %
154 hp=drawvec(x,y,us,vs,25,col);
155 set(hp,'UserData',[xin yin uin vin]);
156 set(hp,'Tag','vectors');
157
158 % COLOR LARGEST VECTOR RED
159 [trash,imax]=max(sqrt(us.*us+vs.*vs));
160 hvmax=drawvec(x(imax),y(imax),us(imax),vs(imax),25,'r');
161 set(hvmax,'Tag','scalearrow');
162
163 % PLACE SCALE WITH MOUSE ON SCREEN
164 %
165 if ~strcmp(blank(sclab),'no scale')
166    ptr=get(gcf,'Pointer');
167    if ~exist('scale_xor')| ~exist('scale_yor')
168       disp('place scale on plot with a mouse button');
169       [scale_xor,scale_yor]=ginput(1);
170    end
171    
172    ht1=drawvec(scale_xor,scale_yor,pct10,0.,25,'r');
173    set(ht1,'Tag','scalearrow');
174    if strcmp(blank(sclab),'m/s')
175       sctext=[num2str(sc) sclab];
176    else
177       sctext=[num2str(100*sc) sclab];
178    end
179    scaletext=text((scale_xor+scale_xor+pct10)/2,scale_yor-(Y2-Y1)*(.05),sctext);
180    set(scaletext,'HorizontalAlignment','center');
181    set(scaletext,'VerticalAlignment','middle');
182    set(scaletext,'Tag','scaletext');
183    set(gcf,'Pointer',ptr);
184
185 end
186
187 % OUTPUT IF DESIRED
188 %
189 if nargout==1,retval=[hp ht1 scaletext];,end
190
191 %
192 % return the saved values of the current figure's WindowButtonDownFcn,
193 % WindowButtonMotionFcn, and WindowButtonUpFcn to the current figure
194 %
195 set(gcf,'WindowButtonDownFcn',WindowButtonDownFcn);
196 set(gcf,'WindowButtonMotionFcn',WindowButtonMotionFcn);
197 set(gcf,'WindowButtonUpFcn',WindowButtonUpFcn);
198
199 %
200 %        Brian O. Blanton
201 %        Department of Marine Science
202 %        15-1A Venable Hall
203 %        CB# 3300
204 %        Uni. of North Carolina
205 %        Chapel Hill, NC
206 %                 27599-3300
207 %
208 %        919-962-4466
209 %        blanton@marine.unc.edu
210 %     
211 %        SUMMER 1998
212 %
Note: See TracBrowser for help on using the browser.