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

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/matlab_cen/lcontour3.m

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

Initial import of Stark code.

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