1 |
function [c,h,hcb]=fdcontour(bfd,qfe,qmin,qmax,dq,cb) |
---|
2 |
%FDCONTOUR contour FE scalar on FD grid |
---|
3 |
% FDCONTOUR accepts a scalar field from a FEM domain and |
---|
4 |
% an FD grid in bfd form, and contours the FE scalar on the |
---|
5 |
% FD grid, using MATLAB's contourf routine for filled color |
---|
6 |
% bands. |
---|
7 |
% |
---|
8 |
% Input: bfd - big finite difference array (see GENBFD) |
---|
9 |
% qfe - the scalar on FE nodes |
---|
10 |
% qmin - lower limit of scalar to contour |
---|
11 |
% qmax - upper limit of scalar to contour |
---|
12 |
% dq - contour bandwidth (not the number of contours!!) |
---|
13 |
% cb - colorbar flag (0=no colorbar,1=colorbar) |
---|
14 |
% |
---|
15 |
% Output: [c,h,hcb] - same vaules that contourf returns |
---|
16 |
% plus the axes handle to the colorbar |
---|
17 |
% if drawn (cb=1) |
---|
18 |
% |
---|
19 |
% Call as: |
---|
20 |
% >> fdcontour(bfd,qfe) |
---|
21 |
% >> fdcontour(bfd,qfe,qmin,qmax) |
---|
22 |
% >> fdcontour(bfd,qfe,qmin,qmax,dq) |
---|
23 |
% >> fdcontour(bfd,qfe,qmin,qmax,dq,cb) |
---|
24 |
% >> [c,h,hcb]=fdcontour(bfd,qfe,qmin,qmax,dq,cb) |
---|
25 |
% |
---|
26 |
% Written by: Brian Blanton (Spring 99); based |
---|
27 |
% on Chris E. Naimie's colorband routines. |
---|
28 |
|
---|
29 |
if nargin==0 |
---|
30 |
disp('h=fdcontour(bfd,qfe,qmin,qmax,dq,cb);') |
---|
31 |
elseif nargin==1 % Assume bathy contour plot, |
---|
32 |
error('Too many arguments to FDCONTOUR') |
---|
33 |
elseif nargin==2 |
---|
34 |
qmin=min(qfe); |
---|
35 |
qmax=max(qfe); |
---|
36 |
dq=(qmax-qmin)/8; |
---|
37 |
if dq<eps |
---|
38 |
error(' No range in scalar to FDCONTOUR.') |
---|
39 |
end |
---|
40 |
cb=0; |
---|
41 |
elseif nargin==3 |
---|
42 |
error('Both qmin and qmax must be specified.') |
---|
43 |
elseif nargin==4 |
---|
44 |
if qmax<qmin |
---|
45 |
error('qmax < qmin!!') |
---|
46 |
end |
---|
47 |
dq=(qmax-qmin)/8; |
---|
48 |
if dq<eps |
---|
49 |
error(' No range in scalar to FDCONTOUR.') |
---|
50 |
end |
---|
51 |
cb=0; |
---|
52 |
elseif nargin==5 |
---|
53 |
if qmax<qmin |
---|
54 |
error('qmax < qmin!!') |
---|
55 |
end |
---|
56 |
if dq<eps |
---|
57 |
error(' dq < eps in FDCONTOUR.') |
---|
58 |
end |
---|
59 |
cb=0; |
---|
60 |
elseif nargin==6 |
---|
61 |
if qmax<qmin |
---|
62 |
error('qmax < qmin!!') |
---|
63 |
end |
---|
64 |
if dq<eps |
---|
65 |
error(' dq < eps in FDCONTOUR.') |
---|
66 |
end |
---|
67 |
if cb~=0 & cb~=1 |
---|
68 |
error('Colorbar flag to FDCONTOUR must be 0|1') |
---|
69 |
end |
---|
70 |
else |
---|
71 |
error('Too many arguments to FDCONTOUR') |
---|
72 |
end |
---|
73 |
|
---|
74 |
%%%%%%%%%%%%%%%%% |
---|
75 |
%%%%%%%%%%%%%%%%% DEFINITIONS |
---|
76 |
%%%%%%%%%%%%%%%%% |
---|
77 |
cmapname='jet'; |
---|
78 |
ncolbase=64; |
---|
79 |
|
---|
80 |
% Extract parts of bfd array |
---|
81 |
xfd=bfd(:,1); |
---|
82 |
yfd=bfd(:,2); |
---|
83 |
|
---|
84 |
% Determine number of points in x,y; assumes the FD points |
---|
85 |
% in BFD are rectangular |
---|
86 |
nx=2; |
---|
87 |
while xfd(nx+1)~=xfd(1) |
---|
88 |
nx=nx+1; |
---|
89 |
end |
---|
90 |
ny=length(xfd)/nx; |
---|
91 |
|
---|
92 |
% Reshape FD arrays for contourf |
---|
93 |
xfd=reshape(xfd,nx,ny); |
---|
94 |
yfd=reshape(yfd,nx,ny); |
---|
95 |
qfd=reshape(fe2fd(qfe,bfd(:,4:9)),nx,ny); |
---|
96 |
|
---|
97 |
cval=qmin:dq:qmax; |
---|
98 |
%nband=(qmax-qmin)/dq; |
---|
99 |
nband=length(cval)-1; |
---|
100 |
if ~isint(nband) |
---|
101 |
disp('Resulting number of colorbands not an integer') |
---|
102 |
disp('Recompute qmin:dq:qmax') |
---|
103 |
return |
---|
104 |
end |
---|
105 |
|
---|
106 |
njet=64; |
---|
107 |
if nband>=ncolbase |
---|
108 |
disp(['Number of colorbands (' int2str(nband) ') can''t exceed']) |
---|
109 |
disp(['number of colors in colormap(' int2str(ncolbase) ')']) |
---|
110 |
return |
---|
111 |
end |
---|
112 |
|
---|
113 |
% Build ColorMap |
---|
114 |
cmap=gen_cmap(ncolbase,nband,cmapname); |
---|
115 |
|
---|
116 |
[cc,hh]=contourf(xfd,yfd,qfd,cval); |
---|
117 |
colormap(cmap) |
---|
118 |
caxis([min(cval) max(cval)]) |
---|
119 |
|
---|
120 |
if cb == 1 |
---|
121 |
hb=colorbar;set(hb,'ytick',cval);set(hb,'ticklength',[0.05 0.025]); |
---|
122 |
end |
---|
123 |
|
---|
124 |
if nargout==3 |
---|
125 |
c=cc;h=hh;hcb=hb; |
---|
126 |
elseif nargout==2 |
---|
127 |
c=cc;h=hh; |
---|
128 |
elseif nargout==1 |
---|
129 |
c=cc; |
---|
130 |
end |
---|
131 |
|
---|
132 |
|
---|
133 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
134 |
%%%%% PRIVATE FUNCTION FOR FDCONTOUR %%%%%%%%%%%%%%%%%% |
---|
135 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
136 |
function cmap=gen_cmap(ncolorbase,nband,cmaptype) |
---|
137 |
cmapbase=eval([cmaptype '(ncolorbase)']); |
---|
138 |
cmap=ones(nband,3); |
---|
139 |
idx1=floor(.1*ncolorbase); |
---|
140 |
idx2=ceil(.9*ncolorbase); |
---|
141 |
idx=round(linspace(idx1,idx2,nband)); |
---|
142 |
cmap(1:nband,:)=cmapbase(idx,:); |
---|