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

root/gliderproc/trunk/MATLAB/opnml/FDCONT/lndmake.m

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

Initial import of Stark code.

Line 
1 function lndmake(fem_grid_struct,belfilename)
2 %LNDMAKE create land masking information for FD CONTOURING
3 %   LNDMAKE creates a polygon list from existing .bel  and the node
4 %   lists from a fem_grid_struct. This polygon list can be used with
5 %   the FD-based contouring and vector plotting functions (FDCONT)
6 %   to mask out the land.
7 %
8 %   The .bel file must have been generated by the OPNML boundary
9 %   code generator GENBEL, since this code orders the boundary
10 %   elements in order, with islands connected and last in the file.
11 %   Other codes (CONVCODES, fortran, Dartmouth) also output .bel
12 %   information in the needed order.  Work is ongoing to remove
13 %   this requirement.  If a .bel file needs ordering, load the
14 %   .bel file into GENBEL and directly  output it to a different
15 %   filename.
16 %
17 %   LNDMAKE outputs new files for the land nodes and segments.
18 %   The new files are <gridname>.lnd and <gridname>.lbe, and are
19 %   output to the current working directory.  Thus, LNDMAKE need
20 %   only be run once per domain.
21 %
22 %   Input: fem_grid_struct - FEM domain structure
23 %          belfilename - FEM domain .bel file
24 %
25 %   Output: NONE (See above)
26 %
27 %   Call as: >> lndmake(fem_grid_struct,belfilename)
28 %
29 %   Written by: Chris E. Naimie
30 %   Modified by: Brian O. Blanton to more general usage. (Jan 99)
31
32 %-----------------------------------------------------------------------
33
34 if nargin ~=2
35    error('    Incorrect number of input arguments to LNDMAKE');
36 end
37
38 if ~is_valid_struct(fem_grid_struct)
39    error('    Argument to LNDMAKE must be a valid fem_grid_struct.')
40 end
41
42 x=fem_grid_struct.x;
43 y=fem_grid_struct.y;
44
45 % Read boundary elements
46 %
47 [bel,gridname]=read_bel(belfilename);
48 %
49 % Outer boundary
50 %
51 % find last non-island boundary segment
52 notsea=find(bel(:,5)~=2);
53 lastnotsea=max(notsea);
54 sea=find(bel(:,5)==2); firstsea=min(sea);
55 if(firstsea<lastnotsea)
56   sea=lastnotsea+1:length(bel);
57 end
58 % find last non-island boundary segment
59 sea=find(bel(:,5)==2);
60 % do a recurrency test within the 2's
61 [elts,nelt]=count(bel(sea,2:3));
62 % islands within outer boundaries have last boundary elements with
63 % only one occurency within the bel file
64 oones=find(nelt==1); oones=reshape(oones,2,length(oones)/2)';
65 beg=sea(oones(:,1)); en=oones(:,2);
66
67 sea(elts(beg):elts(en))=[];
68 %
69 if ~isempty(sea)
70    polygon=bel(1:sea(1)-1,2);
71 else
72    polygon=bel(:,2);        % no islands
73 end
74
75 xp=x(polygon);yp=y(polygon);
76 %
77 xrange=max(xp)-min(xp);yrange=max(yp)-min(yp);
78 ni=length(xp)+1; xp(ni)=xp(1);              yp(ni)=yp(1);
79 ni=length(xp)+1; xp(ni)=min(xp)-0.1*xrange; yp(ni)=yp(ni-1);
80 ni=length(xp)+1; xp(ni)=xp(ni-1);           yp(ni)=max(yp)+0.1*yrange;
81 ni=length(xp)+1; xp(ni)=max(xp)+0.1*xrange; yp(ni)=yp(ni-1);
82 ni=length(xp)+1; xp(ni)=xp(ni-1);           yp(ni)=min(yp)-0.1*yrange;
83 ni=length(xp)+1; xp(ni)=xp(1)  -0.1*xrange; yp(ni)=yp(ni-1);
84 ni=length(xp)+1; xp(ni)=xp(1)  -0.1*xrange; yp(ni)=yp(1);
85 %
86 delete(findobj(0,'Tag','LNDMAKE fig'))
87 figure('MenuBar','none','Name','LNDMAKE Output','Tag','LNDMAKE fig')
88 title(['LNDMAKE on ' gridname])
89 whitebg('w');
90 hp=line(xp,yp,'Color','b','LineStyle','-','LineWidth',2);
91 axis('tight')
92 drawnow
93
94 %
95 gridname=fem_grid_struct.name;
96 lndname=[gridname,'.lnd'];
97 lbename=[gridname,'.lbe'];
98 fnod=fopen(lndname,'w');
99 fbel=fopen(lbename,'w');
100 ione=1;
101 for i=1:length(xp)-1
102    fprintf(fnod,'%i %f %f\n',i,xp(i),yp(i));
103    fprintf(fbel,'%i %i %i\n',i,i,i+1);
104 end
105 i=length(xp);
106 fprintf(fnod,'%i %f %f\n',i,xp(i),yp(i));
107 fprintf(fbel,'%i %i %i\n',i,i,ione);
108
109 if ~isempty(sea)
110    %
111    % first island
112    %
113    clear polygon;
114    i1=sea(1);
115    i2=find(bel(:,3)==bel(i1,2));
116    polygon=bel(i1:i2,2);
117    xp=x(polygon);yp=y(polygon);
118    hp=line(xp,yp,'Color','r','LineStyle','-');
119    drawnow
120    %
121    ione=i+1;
122    for ii=1:length(xp)-1
123       i=i+1;
124       fprintf(fnod,'%i %f %f\n',i,xp(ii),yp(ii));
125       fprintf(fbel,'%i %i %i\n',i,i,i+1);
126    end
127    i=i+1;
128    fprintf(fnod,'%i %f %f\n',i,xp(length(xp)),yp(length(xp)));
129    fprintf(fbel,'%i %i %i\n',i,i,ione);
130    %
131    % remaining islands
132    %
133    while i2 < length(bel)
134    %
135       i1=i2+1;
136       i2=find(bel(:,3)==bel(i1,2));
137       polygon=bel(i1:i2,2);
138       xp=x(polygon);yp=y(polygon);
139       hp=line(xp,yp,'Color','r','LineStyle','-');
140       drawnow
141    %
142       ione=i+1;
143       for ii=1:length(xp)-1
144          i=i+1;
145          fprintf(fnod,'%i %f %f\n',i,xp(ii),yp(ii));
146          fprintf(fbel,'%i %i %i\n',i,i,i+1);
147       end
148       i=i+1;
149       fprintf(fnod,'%i %f %f\n',i,xp(length(xp)),yp(length(xp)));
150       fprintf(fbel,'%i %i %i\n',i,i,ione);
151    end
152 end
153 fclose(fnod);
154 fclose(fbel);
155
156 disp([lndname ' output to ' pwd])
157 disp([lbename ' output to ' pwd])
158
159
Note: See TracBrowser for help on using the browser.