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

root/gliderproc/trunk/MATLAB/opnml/mat4/lcontour4.m

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

Initial import of Stark code.

Line 
1 %LCONTOUR4 contour a scalar field on a FEM grid.
2 %   LCONTOUR4 contour a vector of scalar values across a FEM grid.
3 %   LCONTOUR4 accepts a vector of values to be contoured
4 %   over the provided mesh.  LCONTOUR4 expects the element
5 %   file to be either 3 or  4 columns wide.  If elems is 4 columns
6 %   wide, LCONTOUR4 assumes the first column is the element number
7 %   and strips it away.
8 %
9 % Input:    elems - list of nodes per element
10 %           x,y - xy locations of nodes; each must be 1-D
11 %           Q - scalar to be contoured upon; must be 1-D
12 %           cval - vector of values to contour
13 %
14 %           The parameter/value pairs currently allowed in the lcontour4 
15 %           function are as follows ( default values appear in {} ) :
16 %
17 %                Color       {'r' = red}
18 %                LineStyle   {'-' = solid}
19 %                LineWidth   {0.5 points; 1 point = 1/72 inches}
20 %                MarkerSize  {6 points}
21 %
22 %           See the Matlab Reference Guide entry on the LINE command for
23 %           a complete description of parameter/value pair specification.
24 %
25 %           The idea and some of the constructs used in pv decoding
26 %           in this routine come from an unreleased MathWorks function
27 %           called polar2.m written by John L. Galenski III 
28 %           and provided by Jeff Faneuff.
29 %
30 % Output:  lcontour4 returns the handle to the contour line drawn
31 %
32 % Call as: h=lcontour4(e,x,y,Q,cval,p1,v1,p2,v2,...)
33 %
34 % Written by : Brian O. Blanton
35 %
36 function chandle=lcontour4(elems,x,y,Q,cval,p1,v1,p2,v2,p3,v3,p4,v4,...
37                                             p5,v5,p6,v6,p7,v7,p8,v8)                                           
38 % DEFINE ERROR STRINGS
39 err1=['matrix of elements must be either 3 or 4 columns wide' ];
40 err2=['node coordinate vectors must be the same length'];
41 err3=['length of scalar must be the same length as coordinate vectors'];
42 err4=['scalar to be contoured must be 1-D'];
43 err5=['insufficient number of parameters or values'];
44
45 % check number of arguments
46 N=nargin;
47 msg=nargchk(1,21,N);
48 if ~isempty(msg)
49    disp(msg);
50    disp('Routine: lcontour2');
51    return
52 end
53
54 % check array sizes
55 [nelems,s]=size(elems);   % m = number of elements
56 if s<3 | s>4
57    error(err1);
58 end
59 if s==4,elems=elems(:,2:4);,end
60
61 if length(x) ~= length(y)
62    error(err2);
63 end
64
65 [nrowQ,ncolQ]=size(Q);
66 if nrowQ*ncolQ~=length(Q),error(err4),end
67
68 % columnate Q
69 Q=Q(:);
70 [nrowQ,ncolQ]=size(Q);
71
72 if nrowQ ~= length(x)
73    error(err3);
74 end   
75
76 % determine number of pv pairs input
77 npv = N-5;
78 if rem(npv,2)==1,error(err5);,end
79  
80 % process parameter/value pair argument list, if needed
81 PropFlag = zeros(1,4);
82 limt=npv/2;
83 for X = 1:limt
84   p = eval(['p',int2str(X)]);
85   v = eval(['v',int2str(X)]);
86   if X == 1
87     Property_Names = p;
88     Property_Value = v;
89   else
90     Property_Names = str2mat(Property_Names,p);
91     Property_Value = str2mat(Property_Value,v);
92   end
93   if strcmp(lower(p),'color')
94     PropFlag(1) = 1;
95     color = v;
96   elseif strcmp(lower(p),'linestyle')
97     PropFlag(2) = 1;
98     linestyle = v;
99   elseif strcmp(lower(p),'linewidth')
100     PropFlag(3) = 1;
101     linewidth = v;
102   elseif strcmp(lower(p),'markersize')
103     PropFlag(4) = 1;
104     markersize = v;
105   end
106 end
107
108 % Determine which properties have not been set by
109 % the user
110 Set    = find(PropFlag == 1);
111 NotSet = find(PropFlag == 0);
112  
113 % Define property names and assign default values
114 Default_Settings = ['''r''   ';
115                     '''- ''  ';
116                     '0.5   ';
117                     '6     '];
118 Property_Names =   ['color     ';
119                     'linestyle ';
120                     'linewidth ';
121                     'markersize'];
122 for I = 1:length(NotSet)
123   eval([Property_Names(NotSet(I),:),'=',Default_Settings(NotSet(I),:),';'])
124 end
125  
126 % range of scalar quantity to be contoured; columnate cval
127 Qmax=max(Q);
128 Qmin=min(Q);
129 cval=cval(:);
130  
131 for kk=1:length(cval)
132    if cval(kk) > Qmax | cval(kk) < Qmin
133       disp([num2str(cval(kk)),' not within range of specified scalar field']);
134       chandle(kk)=0;
135    else
136    
137 % Call cmex function contmex
138 %
139       C=contmex5(x,y,elems,Q,cval(kk));
140       if(size(C,1)*size(C,2)~=1)
141          X = [ C(:,1) C(:,3) NaN*ones(size(C(:,1)))]';
142          Y = [ C(:,2) C(:,4) NaN*ones(size(C(:,1)))]';
143          X = X(:);
144          Y = Y(:);
145          chandle(kk)=line(X',Y',...
146                           'Color',color,...
147                           'Linestyle',linestyle,...
148                           'LineWidth',linewidth,...
149                           'MarkerSize',markersize);
150       else
151          disp(['CVal ' num2str(cval(kk)) ' within range but still invalid.']);
152          chandle(kk)=0;
153       end
154       set(chandle(kk),'UserData',cval(kk));
155       set(chandle(kk),'Tag','contour');
156       drawnow
157   end
158 end
159
160 return
161 %
162 %        Brian O. Blanton
163 %        Curr. in Marine Science
164 %        15-1A Venable Hall
165 %        CB# 3300
166 %        Uni. of North Carolina
167 %        Chapel Hill, NC
168 %                 27599-3300
169 %
170 %        919-962-4466
171 %        blanton@marine.unc.edu
172
173    
174
175
176
177
178
179  
Note: See TracBrowser for help on using the browser.