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

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

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

Initial import of Stark code.

Line 
1 %COLORMESH2D draw a FEM mesh in 2-d colored by a scalar quantity.
2 %
3 %   INPUT : fem_grid_struct (from LOADGRID, see FEM_GRID_STRUCT)
4 %           Q         - scalar to color with (optional)
5 %           nband     - number of contour bands to compute (optional)
6 %
7 %           With no scalar specified to contour, COLORMESH2D
8 %           defaults to the bathymetry fem_grid_struct.z
9 %
10 %  OUTPUT : hp - vector of handles, one for each element patch drawn.
11 %
12 %   COLORMESH2D colors the mesh using the scalar Q.  If Q
13 %   is omitted from the argument list, COLORMESH2D draws
14 %   the element connectivity in black and white.
15 %
16 % NOTE: This is one of the few (2 or 3) OPNML MATLAB functions that
17 %       deletes existing patch objects in  the current axes before
18 %       rendering the surface.  This is to avoid having an unmanageable
19 %       number of patch objects on the screen. 
20 %
21 %   CALL : >> hp=colormesh2d(fem_grid_struct,Q,nband)
22 %
23 % Written by : Brian O. Blanton
24 %
25 function rv1=colormesh2d(fem_grid_struct,Q,nband)
26
27 nargchk(1,3,nargin);
28
29 % VERIFY INCOMING STRUCTURE
30 %
31 if ~isstruct(fem_grid_struct)
32    error('First argument to COLORMESH2D must be a structure.')
33 end
34 if ~is_valid_struct(fem_grid_struct)
35    error('fem_grid_struct to COLORMESH2D invalid.')
36 end
37  
38 e=fem_grid_struct.e;
39 x=fem_grid_struct.x;
40 y=fem_grid_struct.y;
41
42 % DETERMINE SCALAR TO CONTOUR
43 %
44 if ~exist('Q')
45   Q=fem_grid_struct.z;
46   nband=16;
47 elseif ischar(Q)
48   if strcmp(lower(Q),'z')
49     Q=fem_grid_struct.z;            % Default to bathymetry
50   else
51      error('Second arg to COLORMESH2D must be ''z'' for depth')
52   end
53   nband=16;
54 elseif length(Q)==1
55   % nband pass in as Q
56   nband=Q;
57   Q=fem_grid_struct.z;
58 else
59    % columnate Q
60    Q=Q(:);
61    [nrowQ,ncolQ]=size(Q);
62    if nrowQ ~= length(x)
63       error('scalar used to color must be 1-D');
64    end
65    if nargin==2,nband=16;,end
66 end
67
68 if nargin==3
69    if length(nband)>1
70       error('nband argument to COLORMESH2D must be 1 integer')
71    end
72 end
73
74
75                      
76 [nrowQ,ncolQ]=size(Q);
77 if ncolQ>1,error(err4);,end
78 if nrowQ ~= length(x)
79    error('length of scalar must be the same length as coordinate vectors')
80
81 end
82 Q=Q(:);
83
84 [nelems,ncol]=size(e);   % nelems,ncol = number of elements, columns
85
86 e=e';
87 [m,n]=size(e);
88 xt=x(e);
89 xt=reshape(xt,m,n);
90 yt=y(e);
91 yt=reshape(yt,m,n);
92 Qt=Q(e);
93 Qt=reshape(Qt,m,n);
94
95 % delete previous colorsurf objects
96 %delete(findobj(gca,'Type','patch','Tag','colorsurf'))
97
98 hp=patch(xt,yt,Qt,'EdgeColor','interp',...
99          'FaceColor','interp','Tag','colorsurf');
100 %colormap(jet(nband))
101
102 % Output if requested.
103 if nargout==1,rv1=hp;,end
104
105 %
106 %        Brian O. Blanton
107 %        Department of Marine Sciences
108 %        15-1A Venable Hall
109 %        CB# 3300
110 %        Uni. of North Carolina
111 %        Chapel Hill, NC
112 %                 27599-3300
113 %
114 %        919-962-4466
115 %        blanton@marine.unc.edu
116
117  
Note: See TracBrowser for help on using the browser.