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

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/femfill.m

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

Initial import of Stark code.

Line 
1 function [hsurfo,hcb,hisl,csurf]=femfill(Q,mesh,cint);
2
3 % [HSURFACES,HCOLORBAR,HISLANDS,CSURF]=
4 %                    femfill(Q,CINT,FEM_MESH_STRUCT);
5 %
6 % HSURFACES - handles of data objects
7 % HCOLORBAR - handle to colorbar axis
8 % HISLANDS  - handle to land and island masks
9 % CSURF     - lines defining HSURFACES, useful for EXTCLABEL
10 %
11 % Draw nifty filled colored contours of a finite element mesh.  Masks
12 % islands and any non-filled regions inside the mesh using the current
13 % axis 'Color' property with a black border.
14 %
15 % Requires: CONTOURFILL (R. Pawlowicz) and subfunctions
16
17 % CVL 1/24/99
18
19 if exist('cint')
20         if isempty(cint)|isnan(cint)
21                 clear cint
22         end
23 end
24
25 % MOVE AXIS TO MAKE ROOM FOR COLORBAR
26
27 ah=gca;
28 set(ah,'position',get(ah,'position').*[1 1 0.85 1]);
29 ap=get(ah,'position');
30
31 % MASK LAND AND CALCULATE ISLAND MASKS
32
33 hold on
34 xo=[];
35 yo=[];
36 while ~isempty(mesh.bnd)
37         ind=2;
38         indseries=nan*mesh.bnd(:,1)';
39         indseries(1:2)=mesh.bnd(1,:);
40         mesh.bnd=mesh.bnd(2:size(mesh.bnd,1),:);
41         while indseries(1)~=indseries(ind);
42                 nind=find(mesh.bnd(:,1)==indseries(ind));
43                 if isempty(nind)
44                         mesh.bnd=fliplr(mesh.bnd);
45                         nind=find(mesh.bnd(:,1)==indseries(ind));
46                 end
47                 ind=ind+1;
48                 indseries(ind)=mesh.bnd(nind,2);
49                 mesh.bnd=mesh.bnd([1:(nind-1) ...
50                         (nind+1):size(mesh.bnd,1)],:);
51         end
52         xo=[xo,mesh.x(indseries(1:ind))',nan];
53         yo=[yo,mesh.y(indseries(1:ind))',nan];
54 end
55
56 ind=find(isnan(xo));
57 olst=1:ind(1)-1;
58 plst=max(olst);
59 for in=ind(2:length(ind))
60         plst=max(plst)+2:in-1;
61         if isinpoly(xo(olst(1)),yo(olst(1)),xo(plst),yo(plst))
62                 olst=plst;
63         end
64 end
65
66 hisl=fill3(xo(olst),yo(olst),zeros(size(olst)),...
67         get(gca,'color'),'edgecolor',1-get(gca,'color'));
68        
69 % FILL AXIS
70
71 Qt=Q;
72 if exist('cint')==1
73         [csurf,hs]=contourfill([mesh.x,mesh.y],mesh.e',Qt,cint);
74         cinto=cint;
75 else
76         [csurf,hs]=contourfill([mesh.x,mesh.y],mesh.e',Qt);
77 end
78
79 % DETERMINE ACTUAL CINT
80
81 ii = 1;
82 cint = [];
83 while (ii < size(csurf,2)),
84         cint=[cint csurf(1,ii)];
85         ii = ii + csurf(2,ii) + 1;
86 end
87 cint=cint(find(diff([cint(:);max(cint)+1])));
88 if ~exist('cinto')
89         cinto=cint;
90 end
91
92 % SET EDGECOLORS AND HEIGHTS
93
94 ct=0;
95 for in=hs(:)'
96         ct=ct+1;
97         set(in,'edgecolor','k')
98         if ~isnan(get(in,'cdata'))
99                 set(in,'cdata',find(get(in,'cdata')==cint),...
100                         'zdata',zeros(size(get(in,'xdata')))+ct);
101         else
102                 set(in,'facecolor',get(gca,'color'),...
103                         'zdata',zeros(size(get(in,'xdata')))+ct)
104         end
105 end
106
107 % MASK ISLANDS
108
109 hisl(2)=fill3(xo(olst),yo(olst),zeros(size(olst))+length(hs)+1,...
110         get(gca,'color'),...
111         'facecolor','none',...
112         'edgecolor',1-get(gca,'color'));
113 plst=-1;
114 for in=ind
115         plst=max(plst)+2:in-1;
116         if olst(1)~=plst(1)
117                 hisl=[hisl,fill3(xo(plst),yo(plst),...
118                         zeros(size(plst))+length(hs)+1,...
119                         get(gca,'color'),...
120                         'edgecolor',1-get(gca,'color'))];
121         end
122 end
123
124 % CREATE COLORBAR
125
126 hcb=axes('position',[ap(1)+1.04*ap(3) ap(2) ap(3)*.1 ap(4)]);
127
128 ulm=max(cint)>max(Q(:));
129 xcb=1:2;
130 ycb=[(min(Q(:))>min(cint(:))):...
131         length(cint)+(max(Q(:))>max(cint(:)))-ulm];
132
133
134 [xcbg,ycbg]=meshgrid(xcb,ycb);
135
136 [outlines,hsbar]=contourf(xcb,ycb,ycbg,[1:length(cint)]);
137
138 set(hcb,'ticklength',[0 0],...
139         'XTick',[],...
140         'yTick',1:length(cinto),...
141         'yticklabel',num2str(cinto(:)),...
142         'YAxisLocation','right',...
143         'color',get(ah,'color'))
144 for in=hsbar
145         set(in,'edgecolor','k')
146 end
147
148 % RETURN TO ORIGINALLY SCHEDULED AXIS AND CHECK FOR NARGOUT
149
150 axes(ah)
151 if nargout
152         hsurfo=hs;
153 end
Note: See TracBrowser for help on using the browser.