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

root/gliderproc/trunk/MATLAB/plots/vecplotxy.m

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

Initial import of Stark code.

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