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

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/vecplotstick.m

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

Initial import of Stark code.

Line 
1 %
2 % VECPLOTSTICK vecplotstick(x,y,u,v,sc,color,dotsize)
3 %
4 %            routine to plot vectors.  STICKPLOT scales the magnitude of
5 %            (u,v) by the magnitude of max(abs(u,v)) and then
6 %            to Q percent of the range of the domain (xin,yin) coordinates. 
7 %            Initially, Q is 10.  The input argument sc scales Q. 
8 %            If sc=1, Q=10.  If sc=2, Q=20. If sc=.5, Q=5.
9 %
10 %            STICKPLOT overlays on existing axes, regardless of the state
11 %            of 'hold'.  If there is no current axes, STICKPLOT draws a
12 %            new axes.
13 %         
14 %            x,y     - vector origins
15 %            u,v     - vector amplitudes
16 %            sc      - vector scale; use '1' first time.
17 %            color   - stick color; (optional, def = 'r')
18 %            dotsize - vector origin "dot" size (optional, def = 10)
19 %
20 %            dotsizes are given in points where a point is 1/72 inches
21 %            The MATLAB default MarkerSize of 6 is approx. the size of a .
22 %            (period).
23 %
24 %            Example call:  stickplot(x,y,u,v,2,'r',10)
25 %            This will draw vectors at (x,y) with appropriately scaled
26 %            magnitudes (u,v), with the maximum vector size being 20
27 %            percent of the domain exent, with red lines used
28 %            to draw the vectors, and with vector origin dots being
29 %            10 points wide. 
30 %
31 %            NOTES:
32 %            STICKPLOT requires atleast 2 points and vectors.
33 %            STICKPLOT does NOT force the axis aspect ratio to be 1:1.
34 %
35 % Call as:   hp=vecplotstick(x,y,u,v,sc,color,dotsize);
36 %
37 function  retval=vecplotstick(xin,yin,uin,vin,sc,...
38                               vcolor,ds,sclab,scale_xor,scale_yor)
39 %
40 % Argument check
41 %
42 if nargin<5
43    error('VECPLOTSTICK must have atleast 5 input arguments; type "help stickplot"');
44 elseif nargin == 5
45    vcolor='k';
46    ds=10;
47 elseif nargin == 6
48    if ~isstr(vcolor)
49       error('color argument to VECPLOTSTICK not a string');
50    end
51    ds=10;
52 elseif nargin > 10
53    error('Too many input arguments; type "help stickplot"');
54 end
55
56 if ~isstr(vcolor)
57    error('color argument to VECPLOTSTICK not a string');
58 end
59
60
61 if length(xin)~=length(yin) | length(xin)~=length(uin) | length(xin)~=length(vin)
62    error('Length of x,y,u,v must be the same');
63 end
64 if length(xin)==1
65    error('Length of x,y,u,v must be greater than 1');
66 end
67
68 xin=xin(:);
69 yin=yin(:);
70 uin=uin(:);
71 vin=vin(:);
72
73 % SCALE VELOCITY DATA TO RENDERED WINDOW SCALE
74 %
75 RLs= get(gca,'XLim');
76 xr=RLs(2)-RLs(1);
77 X1=RLs(1);
78 X2=RLs(2);
79 RLs= get(gca,'YLim');
80 yr=RLs(2)-RLs(1);
81 Y1=RLs(1);
82 Y2=RLs(2);
83 % IF RenderLimits NOT SET, USE RANGE OF DATA
84 %
85 if(xr==0|yr==0)
86    error('Axes must have been previously set for VECPLOT2 to work');
87 end
88 pct10=xr/10;
89 %FILTER DATA THROUGH VIEWING WINDOW
90 %
91 filt=find(xin>=X1&xin<=X2&yin>=Y1&yin<=Y2);
92 x=xin(filt);
93 y=yin(filt);
94 u=uin(filt);
95 v=vin(filt);
96 % SCALE BY MAX VECTOR SIZE IN U AND V
97 %
98 us=u/sc;
99 vs=v/sc;
100 % SCALE TO 10 PERCENT OF X RANGE
101 %
102 us=us*pct10;
103 vs=vs*pct10;
104
105 % SEND VECTORS TO DRAWSTICK ROUTINE
106 %
107 hp=drawstick(xin,yin,us,vs,ds,vcolor);
108 set(hp(1),'UserData',[xin yin uin vin]);
109 set(hp,'Tag','vectors');
110
111 mainax=gca;
112 % Draw vector scale
113 data_axis=axis;
114 cur_units=get(gca,'Units');
115 set(gca,'Units','normalized');
116 axnorm=get(gca,'Position');
117 xstart=axnorm(1)+axnorm(3)*.8;
118 ystart=axnorm(2);
119 dx=axnorm(3)*.2;
120 dy=axnorm(4)*.1;
121 %scale_axes=axes('Units','normalized','Position',[xstart ystart dx dy]);
122 scale_axes=axes('Units','normalized','Position',[0 0 dx dy]);
123 set(scale_axes,'XTick',[],'YTick',[])
124 set(scale_axes,'Tag','vecscaleaxes');
125 set(scale_axes,'ButtonDownFcn','movescaleaxes(1)');
126 dx1=data_axis(1)+(data_axis(2)-data_axis(1))*.8;
127 dx2=data_axis(2);
128 dy1=data_axis(3);
129 dy2=data_axis(3)+(data_axis(4)-data_axis(3))*.1;
130 axis([dx1 dx2 dy1 dy2])
131 sc_or_x=dx1+(dx2-dx1)/10;
132 ht1=drawstick(sc_or_x,(dy1+dy2)/2.05,pct10,0.,10,vcolor);
133 set(ht1,'Tag','scalearrow');
134 sctext=[num2str(sc) sclab];
135 scaletext=text((dx1+dx2)/2,(dy1+dy2)/1.95,sctext);
136 set(scaletext,'HorizontalAlignment','center');
137 set(scaletext,'VerticalAlignment','middle');
138 set(scaletext,'Tag','scaletext');
139 drawnow
140 axes(mainax)
141 set(scale_axes,'Visible','on')
142
143 % OUTPUT HANDLES IF DESIRED
144 %
145 if nargout==1,retval=hp;,end
146
147 %
148 %        Brian O. Blanton
149 %        Department of Marine Sciences
150 %        15-1A Venable Hall
151 %        CB# 3300
152 %        Uni. of North Carolna
153 %        Chapel Hill, NC
154 %                 27599-3300
155 %
156 %        919-962-4466
157 %        blanton@cuda.chem.unc.edu
158 %
Note: See TracBrowser for help on using the browser.