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

root/gliderproc/trunk/MATLAB/opnml/FDCONT/old/fdcontour.m

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

Initial import of Stark code.

Line 
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 fdon=find(bfd(:,3)==0);
93 fdonfe=ones(size(bfd(:,3)));fdonfe(fdon)=NaN;
94
95 %  Reshape FD arrays for contourf
96 xfd=reshape(xfd,nx,ny);
97 yfd=reshape(yfd,nx,ny);
98 qfd=reshape(fe2fd(qfe,bfd(:,4:9)),nx,ny);
99 fdon=reshape(fdonfe,nx,ny);
100
101 qfd=qfd.*fdon;
102
103 cval=qmin:dq:qmax;
104 %nband=(qmax-qmin)/dq;
105 nband=length(cval)-1;
106 if ~isint(nband)
107    disp('Resulting number of colorbands not an integer')
108    disp('Recompute qmin:dq:qmax')
109    return
110 end
111
112 njet=64;
113 if nband>=ncolbase
114    disp(['Number of colorbands (' int2str(nband) ') can''t exceed'])
115    disp(['number of colors in colormap(' int2str(ncolbase) ')'])
116    return
117 end
118
119 % Build ColorMap
120 cmap=gen_cmap(ncolbase,nband,cmapname);
121
122 [cc,hh]=contourf(xfd,yfd,qfd,cval);
123 colormap(cmap)
124 caxis([min(cval) max(cval)])
125
126 if cb == 1
127    hb=colorbar;set(hb,'ytick',cval);set(hb,'ticklength',[0.05 0.025]);
128 end
129
130 if nargout==3
131    c=cc;h=hh;hcb=hb;
132 elseif nargout==2
133    c=cc;h=hh;
134 elseif nargout==1
135    c=cc;
136 end
137
138
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 %%%%% PRIVATE FUNCTION FOR FDCONTOUR  %%%%%%%%%%%%%%%%%%
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 function cmap=gen_cmap(ncolorbase,nband,cmaptype)
143 cmapbase=eval([cmaptype '(ncolorbase)']);
144 cmap=ones(nband,3);
145 idx1=floor(.1*ncolorbase);
146 idx2=ceil(.9*ncolorbase);
147 idx=round(linspace(idx1,idx2,nband));
148 cmap(1:nband,:)=cmapbase(idx,:);
Note: See TracBrowser for help on using the browser.