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

root/gliderproc/trunk/MATLAB/opnml/basics/ellscale.m

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

Initial import of Stark code.

Line 
1 function hes=ellscale(htel,unitn,scale_xor,scale_yor)
2 %ELLSCALE  draw a speed scale on an ellipse plot
3 % ELLSCALE  draw a speed scale on an ellipse picture.  Typically
4 % called after TELLIPSE, passing the object handle returned
5 % by TELLIPSE.  If TELLIPSE was used in "particle-excursion"
6 % mode, then ELLSCALE cannot draw a vector scale, as there is
7 % to draw.
8 %
9 % htel MUST be the handle returned by TELLIPSE.
10 % TELLIPSE returns this number to the main
11 % workspace.
12 %
13 % unitn (optional) is the flag that indicates which
14 % units-text ELLSCALE should put on the figure to
15 % correspond to the vector magnitudes:
16 %
17 % If omitted, ELLSCALE uses the string 'units'.
18 % If unitn=1, ELLSCALE uses the string 'm/sec'.
19 % If unitn=2, ELLSCALE uses the string 'cm/sec'.
20 % If unitn='text', ELLSCALE uses the string 'text'.
21 %   
22 % This last option provides for the user to specify
23 % the string of choice for units.
24
25 % If unitn is anything other than one of the possibilities
26 % specified above, ELLSCALE aborts.
27 %
28 % Call as: >>  ellscale(h,unitn)
29 %
30 % Written by : Brian O. Blanton
31 %
32 err1=['UserData associated with the object handle supplied to ELLSCALE',...
33       ' is empty. ELLSCALE cannot draw the ellipse scale.'];
34 err2=['Improper unit specification in unitn; type "help ELLSCALE"'];
35 err3=['TELLIPSE was used in "particle-excursion" mode. No scaling.'];
36
37 if nargin<2 | nargin > 5
38    error('Wrong number of input arguments to ELLSCALE')
39 end
40
41 if nargin==2
42    if isstr(htel)
43       error('Arg 1 to ELLSCALE cannot be a string.')
44    end
45 end
46    
47 parent_of_htel=get(htel,'Parent');      % the axes
48 parent_of_parent_of_htel=get(parent_of_htel,'Parent');  % the figure
49 children_of_parent_of_htel=get(parent_of_htel,'Children');
50
51 X=get(parent_of_htel,'XLim');
52 Y=get(parent_of_htel,'YLim');
53 xrange=X(2)-X(1);
54 yrange=Y(2)-Y(1);
55
56 % ensure that the current axes is the parent
57 % of the vector handle passed to ELLSCALE
58 axes(parent_of_htel);
59  
60 % clear previous scales from this axes
61 for i=1:length(children_of_parent_of_htel)
62    if strcmp(get(children_of_parent_of_htel(i),'UserData'),'scaletext')==1
63       delete(children_of_parent_of_htel(i));
64    elseif strcmp(get(children_of_parent_of_htel(i),'UserData'),'scalearrow')==1
65       delete(children_of_parent_of_htel(i));
66    end
67 end
68
69 data=get(htel,'UserData');
70 if isempty(data)== 1
71    error(err1);
72 end
73
74 % determine which text to use for units-string
75 if ~exist('unitn')
76    unitstring='units';
77 else
78    if unitn==1
79       unitstring='m/sec';
80    elseif unitn==2
81       unitstring='cm/sec';
82    elseif isstr(unitn)
83       unitstring=unitn;
84    else
85       error(err2);
86    end
87 end
88
89 % The last line of "data" is the scaling information.  If TELLIPSE
90 % was used in "particle-excursiuon" mode, the 2nd and 3rd values in the
91 % last line will both be NaN.  "Check this and return if so.
92 magscale=data(length(data(:,1)),2);
93 vecscale=data(length(data(:,1)),3);
94 if (isnan(magscale)|isnan(vecscale))
95    error(err3)
96 end
97
98 %FILTER DATA THROUGH VIEWING WINDOW
99 filt=find(data(:,1)>=X(1)&data(:,1)<=X(2)&data(:,2)>=Y(1)&data(:,2)<=Y(2));
100 umaj=data(filt,3);
101
102 % now working with umaj
103 maxell=max(umaj);
104
105 %
106 % save the current value of the current figure's WindowButtonDownFcn,
107 % WindowButtonMotionFcn, and WindowButtonUpFcn
108 %
109 WindowButtonDownFcn=get(gcf,'WindowButtonDownFcn');
110 WindowButtonMotionFcn=get(gcf,'WindowButtonMotionFcn');
111 WindowButtonUpFcn=get(gcf,'WindowButtonUpFcn');
112 set(gcf,'WindowButtonDownFcn','');
113 set(gcf,'WindowButtonMotionFcn','');
114 set(gcf,'WindowButtonUpFcn','');
115
116 if ~exist('scale_xor')| ~exist('scale_yor')
117    disp('place scale on plot with a mouse button');
118    [scale_xor,scale_yor]=ginput(1);
119 end
120 hp=drawvec(scale_xor,scale_yor,maxell,0.,25,'r');
121 set(hp,'UserData','scalearrow');
122 set(hp,'Tag','scalearrow');
123 tnum=num2str(magscale);
124 tnum=[tnum ' ' unitstring];
125
126 scaletext=text(scale_xor,scale_yor-(Y(2)-Y(1))*(.05),tnum);
127 set(scaletext,'HorizontalAlignment','center');
128 set(scaletext,'UserData','scaletext');
129 set(scaletext,'Tag','scaletext');
130
131 hes=[hp; scaletext];
132
133 %
134 % return the saved values of the current figure's WindowButtonDownFcn,
135 % WindowButtonMotionFcn, and WindowButtonUpFcn to the current figure
136 %
137 set(gcf,'WindowButtonDownFcn',WindowButtonDownFcn);
138 set(gcf,'WindowButtonMotionFcn',WindowButtonMotionFcn);
139 set(gcf,'WindowButtonUpFcn',WindowButtonUpFcn);
140 %
141 %LabSig  Brian O. Blanton
142 %        Department of Marine Sciences
143 %        12-7 Venable Hall
144 %        CB# 3300
145 %        University of North Carolina
146 %        Chapel Hill, NC
147 %                 27599-3300
148 %
149 %        brian_blanton@unc.edu
150 %
151
152
Note: See TracBrowser for help on using the browser.