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

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/matlab_cen/lndmake.m

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

Initial import of Stark code.

Line 
1 %-----------------------------------------------------------------------
2 % function lndmake
3 % read boundary element and node files and create land and island
4 % polygons
5 %-----------------------------------------------------------------------
6 function lndmake
7 %-----------------------------------------------------------------------
8 % Read boundary elements
9 %
10 !ls *.bel
11 filebel=input('Enter the name of the boundary element file: ','s');
12 [x,y,bel,gridname]=read_bel(filebel);
13 %
14 % Outer land boundary
15 %
16 sea=find(bel(:,5)==2);
17 polygon=bel(1:sea(1)-1,2);
18 xp=x(polygon);yp=y(polygon);
19 %
20 xrange=max(xp)-min(xp);yrange=max(yp)-min(yp);
21 ni=length(xp)+1; xp(ni)=xp(1);              yp(ni)=yp(1);
22 ni=length(xp)+1; xp(ni)=min(xp)-0.1*xrange; yp(ni)=yp(ni-1);
23 ni=length(xp)+1; xp(ni)=xp(ni-1);           yp(ni)=max(yp)+0.1*yrange;
24 ni=length(xp)+1; xp(ni)=max(xp)+0.1*xrange; yp(ni)=yp(ni-1);
25 ni=length(xp)+1; xp(ni)=xp(ni-1);           yp(ni)=min(yp)-0.1*yrange;
26 ni=length(xp)+1; xp(ni)=xp(1)  -0.1*xrange; yp(ni)=yp(ni-1);
27 ni=length(xp)+1; xp(ni)=xp(1)  -0.1*xrange; yp(ni)=yp(1);
28 %
29 figure;
30 whitebg('w');
31 hp=plot(xp,yp,'b-');
32 hold on
33 %
34 fnod=fopen([gridname,'.lnd'],'w');
35 fbel=fopen([gridname,'.lbe'],'w');
36 ione=1;
37 for i=1:length(xp)-1
38    fprintf(fnod,'%i %f %f\n',i,xp(i),yp(i));
39    fprintf(fbel,'%i %i %i\n',i,i,i+1);
40 end
41 i=length(xp);
42 fprintf(fnod,'%i %f %f\n',i,xp(i),yp(i));
43 fprintf(fbel,'%i %i %i\n',i,i,ione);
44 %
45 % first island
46 %
47 clear polygon;
48 i1=sea(1);
49 i2=find(bel(:,3)==bel(i1,2));
50 polygon=bel(i1:i2,2);
51 xp=x(polygon);yp=y(polygon);
52 hp=plot(xp,yp,'r-');
53 %
54 ione=i+1;
55 for ii=1:length(xp)-1
56    i=i+1;
57    fprintf(fnod,'%i %f %f\n',i,xp(ii),yp(ii));
58    fprintf(fbel,'%i %i %i\n',i,i,i+1);
59 end
60 i=i+1;
61 fprintf(fnod,'%i %f %f\n',i,xp(length(xp)),yp(length(xp)));
62 fprintf(fbel,'%i %i %i\n',i,i,ione);
63 %
64 % remaining islands
65 %
66 while i2 < length(bel)
67 %
68    i1=i2+1;
69    i2=find(bel(:,3)==bel(i1,2));
70    polygon=bel(i1:i2,2);
71    xp=x(polygon);yp=y(polygon);
72    hp=plot(xp,yp,'r-');
73 %
74    ione=i+1;
75    for ii=1:length(xp)-1
76       i=i+1;
77       fprintf(fnod,'%i %f %f\n',i,xp(ii),yp(ii));
78       fprintf(fbel,'%i %i %i\n',i,i,i+1);
79    end
80    i=i+1;
81    fprintf(fnod,'%i %f %f\n',i,xp(length(xp)),yp(length(xp)));
82    fprintf(fbel,'%i %i %i\n',i,i,ione);
83 end
84 fclose(fnod);
85 fclose(fbel);
86 %-----------------------------------------------------------------------
87 %-----------------------------------------------------------------------
Note: See TracBrowser for help on using the browser.