/[MITgcm]/MITgcm_contrib/eh3/llc/ecco-godae/climatology/gen_bathy.m
ViewVC logotype

Contents of /MITgcm_contrib/eh3/llc/ecco-godae/climatology/gen_bathy.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download)
Sat Nov 11 05:32:48 2006 UTC (18 years, 8 months ago) by heimbach
Branch: MAIN
Changes since 1.3: +7 -3 lines
o Fix one erroneous transpose; fixes rotated/mirrored tiles.

1 %
2 % Ed Hill
3 %
4 % Generate approximate bathymetry for the llc grid
5 %
6
7 % clear all ; close all
8
9 do_print = 0;
10 dbug = 0;
11
12 % Get the ETOPO2 data
13 disp('Reading the ETOPO2 data...');
14 nlat = 5400;
15 nlon = 10800;
16 lons = linspace(-180, (180 - 2/60), nlon);
17 lats = linspace(90, -(90 - 2/60), nlat);
18 fid = fopen('ETOPO2.raw.bin', 'r', 'ieee-be');
19 et2 = reshape( fread(fid, nlat*nlon, 'int16'), [ nlon nlat ]);
20 fid = fclose(fid);
21
22 if dbug > 10
23 surf( et2(1:500,1:500) ), view(2), shading flat
24 ilon = [ 1:10:5000 ];
25 ilat = [ 1:10:5400 ];
26 surf(lons(ilon), lats(ilat), et2(ilon,ilat)'), view(2), ...
27 shading flat, axis equal
28 end
29
30 % Get the llc grid information
31 disp('Reading the grid information...');
32 fnc_in = 'llc_p90_%d.nc';
33 vnms = { 'XC' 'YC' 'XG' 'YG' };
34 d2r = pi/180.0;
35 ginfo = {};
36 for k = 1:5
37 nc = netcdf(sprintf(fnc_in,k),'nowrite');
38 for j = 1:length(vnms)
39 eval(sprintf('ginfo(k).%s = nc{''%s''}(:);',vnms{j},vnms{j}));
40 end
41 nc = close(nc);
42
43 % compute 3D coords of the C and G points
44 cor = zeros( [ size(ginfo(k).XG) 3 ]);
45 [cor(:,:,1),cor(:,:,2),cor(:,:,3)] = sph2cart( ginfo(k).XG*d2r, ...
46 ginfo(k).YG*d2r,1 );
47 cen = zeros( [ size(ginfo(k).XC) 3 ]);
48 [cen(:,:,1),cen(:,:,2),cen(:,:,3)] = sph2cart( ginfo(k).XC*d2r, ...
49 ginfo(k).YC*d2r,1 );
50 ginfo(k).cor = cor;
51 ginfo(k).cen = cen;
52
53 % empty bathy
54 ginfo(k).bathy = zeros(size( size(ginfo(k).XC) ));
55 end
56
57 % Do a quick-and-dirty regrid
58 disp('Performing the regrid...');
59 s_lon = -37;
60 s_lat = 0.0;
61 for k = 1:5
62 disp(sprintf(' k = %d',k));
63 %
64 % / i,j+1 i+1,j+1 \
65 % \ i,j i+i,j /
66 for j = 1:size(ginfo(k).XC,2)
67 jr = [ j j+1 ];
68 for i = 1:size(ginfo(k).XC,1)
69 ir = [ i i+1 ];
70 lon_min = min(min( ginfo(k).XG(ir,jr) + s_lon ));
71 lon_max = max(max( ginfo(k).XG(ir,jr) + s_lon ));
72 lat_min = min(min( ginfo(k).YG(ir,jr) + s_lat ));
73 lat_max = max(max( ginfo(k).YG(ir,jr) + s_lat ));
74 % [ lon_min lon_max lat_min lat_max ]
75 lon_mm = [ mod(lon_min + 180,360)-180 ...
76 mod(lon_max + 180,360)-180 ];
77 lon_min = min(lon_mm);
78 lon_max = max(lon_mm);
79
80 d_lon = lon_max - lon_min;
81 if (abs(d_lon) > 45 && lat_min < 88)
82 i_lon = find( lons >= lon_max ...
83 | lons <= lon_min );
84 else
85 i_lon = find(lon_min <= lons & lons <= lon_max);
86 end
87 i_lat = find(lat_min <= lats & lats <= lat_max);
88
89 % average the bathy
90 bv = et2(i_lon,i_lat);
91 if length(bv(:)) > 1
92 ginfo(k).bathy(i,j) = mean(bv(:));
93 else
94 % If not averaging, then interpolate
95 % ginfo(k).bathy(i,j) = NaN;
96 i_lon = interp1(lons,[1:length(lons)],lon_min,'nearest');
97 i_lat = interp1(lats,[1:length(lats)],lat_min,'nearest');
98 ginfo(k).bathy(i,j) = et2(i_lon,i_lat);
99 end
100 end
101 end
102 end
103
104 % Plot the resulting bathymetry
105 k = 3;
106 for k = 1:5
107 disp(sprintf(' k = %d',k));
108 ginfo(k).b_oce = ginfo(k).bathy;
109 % ginfo(k).b_oce(find(ginfo(k).b_oce >= 0.0)) = NaN;
110 ginfo(k).b_oce(find(ginfo(k).b_oce >= 0.0)) = 1000;
111 if k == 2
112 hold on
113 end
114 % figure(k)
115 surf( ginfo(k).cor(:,:,1), ...
116 ginfo(k).cor(:,:,2), ...
117 ginfo(k).cor(:,:,3), ginfo(k).b_oce )
118 if k == 5
119 hold off
120 end
121 end
122 axis equal, view(2)
123
124
125 % Plot the bathymetry at 1/2 resolution
126 k = 3;
127 for k = 1:5
128 disp(sprintf(' k = %d',k));
129 ginfo(k).c_half = ginfo(k).cor(1:2:end,1:2:end,:);
130 ginfo(k).b_half = ginfo(k).bathy(1:2:end,1:2:end);
131 ginfo(k).b_half(find(ginfo(k).b_half >= 0.0)) = 1000;
132 if k == 2
133 hold on
134 end
135 % figure(k)
136 surf( ginfo(k).c_half(:,:,1), ...
137 ginfo(k).c_half(:,:,2), ...
138 ginfo(k).c_half(:,:,3), ginfo(k).b_half )
139 if k == 5
140 hold off
141 end
142 end
143 axis equal, view(2)
144
145 %--- BREAK POINT HERE
146 %--- do e.g. view(80,45) to change view angle
147
148
149
150 if do_print > 0
151 print -depsc llc_bathy.eps
152 end
153
154
155 % Write the bathymetry to netCDF compatible with MNC
156 id = 'bathy';
157 units = 'm';
158 for k = 1:5
159 disp(sprintf(' k = %d',k));
160 ginfo(k).b_out = ginfo(k).bathy;
161 ginfo(k).b_out(find(ginfo(k).bathy >= 0.0)) = 0.0;
162 bfile = sprintf('llc_p90_bathy.f%03d.nc',k);
163
164 nc = netcdf(bfile, 'clobber');
165 nc.reference = 'bathymetry';
166 nc.author = 'Ed Hill <eh3@mit.edu>';
167 nc.date = eval('date');
168 nc('X') = size( ginfo(k).XC, 1 );
169 nc('Y') = size( ginfo(k).XC, 2 );
170 nc{ id } = { 'Y', 'X' };
171 nc{ id }.units = units;
172 nc{ id }(:) = ginfo(k).b_out';
173 nc = close(nc);
174 end
175
176 % Write the bathymetry to a set of 90-by-90 per-tile MDSIO-compatible
177 % files
178 % face is js
179 iti = [ 1 1 1 ; ...
180 1 91 1 ; ...
181 1 181 1 ; ...
182 1 271 1 ; ...
183 2 1 1 ; ...
184 2 91 1 ; ...
185 2 181 1 ; ...
186 2 271 1 ; ...
187 3 1 1 ; ...
188 4 1 1 ; ...
189 4 1 91 ; ...
190 4 1 181 ; ...
191 4 1 271 ; ...
192 5 1 1 ; ...
193 5 1 91 ; ...
194 5 1 181 ; ...
195 5 1 271 ];
196 for k = 1:size(iti,1)
197 disp(sprintf(' k = %d',k));
198 fname = sprintf('bathy.%03d.001.data',k);
199 disp( fname )
200 fid = fopen(fname, 'w', 'ieee-be');
201 is = iti(k,3); ie = is + 90 - 1;
202 js = iti(k,2); je = js + 90 - 1;
203 tmp = ginfo(iti(k,1)).b_out(is:ie,js:je);
204 fwrite(fid,tmp,'real*8',0,'ieee-be');
205 fclose(fid);
206 surf(tmp), view(2), axis equal, shading flat, pause(1)
207 end
208

  ViewVC Help
Powered by ViewVC 1.1.22