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

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

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

Initial import of Stark code.

Line 
1 %
2 % NUMSCAL label scalar (Q) values at x,y locations on current axes.
3 %
4 % Input:  x  - x-coordinate array
5 %         y  - y-coordinate array
6 %         Q  - scalar (1-D vector)
7 %         ps - point size for screen text numbers (optional, def=8)
8 %
9 %         NOTES: 1) NUMSCAL overlays existing plots regardless of
10 %                   the state of hold
11 %                2) NUMSCAL determines if the current density of nodes
12 %                   is too high to make the node numbers readable.
13 %                   If node density is too high, NUMSCAL displays
14 %                   a warning box asking the user if NUMSCAL
15 %                   should plot the numbers anyway.
16 %
17 % Call as: >> numscal(x,y,Q,ps);
18 %
19 % Written by : Brian O. Blanton
20 %
21 function h=numscal(x,y,Q,ps)
22
23 % DEFINE ERROR STRINGS
24 err1=['Not enough input arguments; need atleast x,y'];
25 err2=['Lengths of x,y must be the same'];
26 err3=['Lengths of Q must be the same as x,y'];
27 warn1=str2mat('The current axes is too dense for the  ',...
28        'scalar values to be readable.  CONTINUE?');
29        
30 % check arguments
31 if nargin < 3
32    error(err1);
33 end
34
35 % define pointsize if not input
36 if exist('ps')~=1,ps=8;,end
37
38 % check input arguments length
39 if length(x)~=length(y)
40    error(err2);
41 end
42 if length(x)~=length(Q)
43    error(err3);
44 end
45
46 % compute offset as 2% of each axis range
47 X=get(gca,'Xlim');
48 Y=get(gca,'YLim');
49 off=(X(2)-X(1))/50;
50 off=0;
51
52 % get indices of nodes within viewing window defined by X,Y
53 filt=find(x>=X(1)&x<=X(2)&y>=Y(1)&y<=Y(2));
54
55 % determine if viewing window is zoomed-in
56 % enough for node numbers to be meaningful
57 oldunits=get(gca,'Units');
58 set(gca,'Units','Points');
59 rect=get(gca,'Position');        % get viewing window width in
60 set(gca,'Units',oldunits);       % point units (1/72 inches)
61 xr=rect(3)-rect(1);
62 yr=rect(4)-rect(2);;
63 xden=xr/sqrt(length(filt));
64 yden=yr/sqrt(length(filt));
65 den=sqrt(xden*xden+yden*yden);
66 if den < 5*ps
67    click=questdlg(warn1,'yes','no');
68    if strcmp(click,'no'),return,end
69 end
70
71 % label only those nodes that lie within viewing window.
72 for i=1:length(filt)
73     h(i)=text(x(filt(i))+off,y(filt(i))+off,num2str(Q(filt(i)),6),...
74          'FontSize',ps,...
75          'HorizontalAlignment','left',...
76          'VerticalAlignment','middle',...
77          'Tag','Node Scalar Value');
78 end
79 %
80 %        Brian O. Blanton
81 %        Curr. in Marine Science
82 %        15-1A Venable Hall
83 %        CB# 3300
84 %        Uni. of North Carolina
85 %        Chapel Hill, NC
86 %                 27599-3300
87 %
88 %        919-962-4466
89 %        blanton@marine.unc.edu
90 %
91
92
93
Note: See TracBrowser for help on using the browser.