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

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

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

Initial import of Stark code.

Line 
1 % PERPVECPLOT routine to plot vectors perpendicular to view axis. 
2 %
3 % PERPVECPLOT scales the magnitude of w and then
4 % forces a vector of magnitude sc to be 10% of the x data
5 % range.  By default, sc = 1., so that a 1 m/s vector will
6 % be scaled to 10% of the x data range.  If sc=.5, then
7 % a vector magnitude of 50 cm/s  will be scaled to 10% of the
8 % x data range.  Decreasing sc serves to make the vectors
9 % appear larger.  PERPVECPLOT then prompts the user to place
10 % the vector scale on the figure, unless scale_xor,scale_yor
11 % is specified (see below).
12 %     
13 %   INPUT:   x,y    - vector origins
14 %            w      - perpendicular velocity
15 %            These inputs are optional, but if one is needed, all
16 %            preceeding it wil be required.
17 %            sc     - vector scaler; (optional; default = 1.)
18 %
19 %  OUTPUT:   h - vector of handles to the vector lines drawn, the
20 %                scale vector, and the scale vector text.
21 %
22 %   NOTES:   VECPLOT requires atleast 2 coordinates and vectors.
23 %
24 %    CALL:   hv=vecplot(x,y,w,sc)
25 %
26 % Calls: plots/drawperpvec
27 %
28 % Catherine R. Edwards
29 % Last modified: 1 Feb 2004
30 % Scaling code by Brian O. Blanton
31 %
32 %
33
34 function  [hp,hc]=perpvecplot(x,y,w,sc)
35
36 % Copy incoming cell array
37
38 % DEFINE ERROR STRINGS
39 err1=['Invalid number of input arguments to PERPVECPLOT'];
40 err4=['Length of (x,y) must equal length of w.'];
41 err7=['Second optional argument (sclab) must be a string.'];
42 err8=['Both x- and y-coords of vector scale must be specified.'];
43
44 % PROCESS THE INPUT ARGUMENTS
45 % Length of varargin must be between 3 and 7, inclusive.
46 if nargin<3 |  nargin>4
47    error(err1)
48 end
49
50 xin=x;yin=y;
51 win=w;
52
53 % At this point, the copy of the input cell has been reduced to
54 % contain the optional arguments, if any.
55 if nargin==3
56    sc=1.;sclab=' cm/s';
57 elseif nargin==4
58    sc=sc;
59    sclab=' cm/s';
60 end
61 col='b';
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
75 % SCALE VELOCITY DATA TO RENDERED WINDOW SCALE
76 %
77 RLs= get(gca,'XLim');
78 xr=RLs(2)-RLs(1);
79 X1=RLs(1);
80 X2=RLs(2);
81 RLs= get(gca,'YLim');
82 yr=RLs(2)-RLs(1);
83 Y1=RLs(1);
84 Y2=RLs(2);
85
86 % IF RenderLimits NOT SET, USE RANGE OF DATA
87 %
88 if(xr==0|yr==0)
89    error('Axes must have been previously set for PERPVECPLOT to work');
90 end
91 xpct10=xr/10; ypct10=yr/10;
92
93 %FILTER DATA THROUGH VIEWING WINDOW
94 %
95 filt=find(xin>=X1&xin<=X2&yin>=Y1&yin<=Y2);
96 x=xin(filt);
97 y=yin(filt);
98 win(filt);
99
100 % SCALE BY MAX VECTOR SIZE IN U AND V
101 %
102 ws=w/sc;
103
104 % SCALE TO 10 PERCENT OF X,Y RANGE
105 %
106 wx=ws*xpct10; wy=ws*ypct10;
107  
108 % SEND VECTORS TO DRAWVEC ROUTINE
109 %
110 [hc,hp]=drawperpvec(x,y,wx,wy,col);
111
112 set(hp,'UserData',[xin yin win]);
113 set(hc,'UserData',[xin yin win]);
114 set(hp,'Tag','perpvectors');
115 set(hc,'Tag','perpvectors');
116
117 % OUTPUT IF DESIRED
118 %
119 if nargout==1,retval=[hp hc];,end
120
121 %
122 % return the saved values of the current figure's WindowButtonDownFcn,
123 % WindowButtonMotionFcn, and WindowButtonUpFcn to the current figure
124 %
125 set(gcf,'WindowButtonDownFcn',WindowButtonDownFcn);
126 set(gcf,'WindowButtonMotionFcn',WindowButtonMotionFcn);
127 set(gcf,'WindowButtonUpFcn',WindowButtonUpFcn);
128
Note: See TracBrowser for help on using the browser.