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

root/gliderproc/trunk/MATLAB/opnml/FEM/lcontour.m

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

Initial import of Stark code.

Line 
1 function chandle=lcontour(fem_grid_struct,Q,cval,p1,v1,p2,v2,p3,v3,p4,v4,...
2                                             p5,v5,p6,v6,p7,v7,p8,v8)
3 %LCONTOUR contour a scalar on a FEM grid.
4 %   LCONTOUR contours a scalar field on the input FEM grid.
5 %   LCONTOUR accepts a vector of values to be contoured
6 %   over the provided mesh. 
7 %
8 %   INPUT : fem_grid_struct (from LOADGRID, see FEM_GRID_STRUCT)
9 %           Q    - scalar to be contoured upon; must be a 1-D vector
10 %                  or the single character 'z', IN SINGLE QUOTES!!
11 %           cval - vector of values to contour
12 %
13 %           In order to contour the FEM domain bathymetry, pass
14 %           in the string 'z' in place of an actual scalar field Q.
15 %           You could, of course, pass in the actual bathymetry as
16 %           the scalar to contour.  Otherwise, Q must be a 1-D vector
17 %           with length equal to the number of nodes in the FEM mesh.
18 %
19 %           The parameter/value pairs currently allowed in the LCONTOUR 
20 %           function are as follows (default values appear in {}) :
21 %
22 %                Color       {'r' = red}
23 %                LineStyle   {'-' = solid}
24 %                LineWidth   {0.5 points; 1 point = 1/72 inches}
25 %                MarkerSize  {6 points}
26 %
27 %           See the Matlab Reference Guide entry on the LINE command for
28 %           a complete description of parameter/value pair specification.
29 %
30 %           The idea and some of the constructs used in pv decoding
31 %           in this routine come from an unreleased MathWorks function
32 %           called polar2.m written by John L. Galenski III 
33 %           and provided by Jeff Faneuff.
34 %
35 %  OUTPUT :  h - the handle to the contour line(s) drawn
36 %
37 %    CALL : >> h=lcontour(fem_grid_struct,Q,cval,p1,v1,p2,v2,...)
38 %     or
39 %           >> h=lcontour(fem_grid_struct,'z',cval,p1,v1,p2,v2,...)
40 %
41 % Written by : Brian O. Blanton
42 %
43
44 % VERIFY INCOMING STRUCTURE
45 %
46 if ~isstruct(fem_grid_struct)
47    msg=str2mat(' ',...
48                'First argument to LCONTOUR not a structure.  Perhaps its',...
49                'the element list.  If so you should use LCONTOUR4, which',...
50                'takes the standard grid arrays (e,x,...).  The first ',...
51                'argument to LCONTOUR MUST be a fem_grid_struct.',' ');
52    disp(msg)
53    error(' ')
54 end
55 if ~is_valid_struct(fem_grid_struct)
56    error('    fem_grid_struct to LCONTOUR invalid.')
57 end
58
59 e=fem_grid_struct.e;
60 x=fem_grid_struct.x;
61 y=fem_grid_struct.y;
62
63 % DETERMINE SCALAR TO CONTOUR
64 %
65 if ischar(Q)
66    Q=fem_grid_struct.z;
67 else
68    % columnate Q
69    Q=Q(:);
70    [nrowQ,ncolQ]=size(Q);
71    if nrowQ ~= length(x)
72       error('Length of scalar must be same length as grid coordinates.');
73    end   
74 end
75
76 % determine number of pv pairs input
77 npv = nargin-3;
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 contmex5
138 %
139       C=contmex5(x,y,e,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 %        Department of Marine Sciences
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 %        Summer 1997
174    
175
176
177
178
179
180  
Note: See TracBrowser for help on using the browser.