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

Annotation 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.3 - (hide annotations) (download)
Thu Aug 24 15:30:24 2006 UTC (18 years, 11 months ago) by edhill
Branch: MAIN
Changes since 1.2: +21 -0 lines
add plot of the bathy at 1/2 resolution since the full resolution is
  tough to see and tends to crash matlab

1 edhill 1.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 edhill 1.2 % 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 edhill 1.1 surf( ginfo(k).cor(:,:,1), ...
116     ginfo(k).cor(:,:,2), ...
117     ginfo(k).cor(:,:,3), ginfo(k).b_oce )
118 edhill 1.2 if k == 5
119     hold off
120     end
121 edhill 1.1 end
122 edhill 1.2 axis equal, view(2)
123 edhill 1.1
124    
125 edhill 1.3 % 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    
146 edhill 1.1 if do_print > 0
147     print -depsc llc_bathy.eps
148     end
149    
150    
151 edhill 1.2 % Write the bathymetry to netCDF compatible with MNC
152     id = 'bathy';
153     units = 'm';
154     for k = 1:5
155     disp(sprintf(' k = %d',k));
156     ginfo(k).b_out = ginfo(k).bathy;
157     ginfo(k).b_out(find(ginfo(k).bathy >= 0.0)) = 0.0;
158     bfile = sprintf('llc_p90_bathy.f%03d.nc',k);
159    
160     nc = netcdf(bfile, 'clobber');
161     nc.reference = 'bathymetry';
162     nc.author = 'Ed Hill <eh3@mit.edu>';
163     nc.date = eval('date');
164     nc('X') = size( ginfo(k).XC, 1 );
165     nc('Y') = size( ginfo(k).XC, 2 );
166     nc{ id } = { 'Y', 'X' };
167     nc{ id }.units = units;
168     nc{ id }(:) = ginfo(k).b_out';
169     nc = close(nc);
170     end
171    
172     % Write the bathymetry to a set of 90-by-90 per-tile MDSIO-compatible
173     % files
174     % face is js
175     iti = [ 1 1 1 ; ...
176     1 91 1 ; ...
177     1 181 1 ; ...
178     1 271 1 ; ...
179     2 1 1 ; ...
180     2 91 1 ; ...
181     2 181 1 ; ...
182     2 271 1 ; ...
183     3 1 1 ; ...
184     4 1 1 ; ...
185     4 1 91 ; ...
186     4 1 181 ; ...
187     4 1 271 ; ...
188     5 1 1 ; ...
189     5 1 91 ; ...
190     5 1 181 ; ...
191     5 1 271 ];
192     for k = 1:size(iti,1)
193     disp(sprintf(' k = %d',k));
194     fname = sprintf('bathy.%03d.001.data',k);
195     fid = fopen(fname, 'w', 'ieee-be');
196     % be careful of index orientation
197     is = iti(k,3); ie = is + 90 - 1;
198     js = iti(k,2); je = js + 90 - 1;
199     tmp = ginfo(iti(k,1)).b_out(is:ie,js:je)';
200     surf(tmp), view(2), axis equal, shading flat, pause(1)
201     fwrite(fid,tmp,'real*8',0,'ieee-be');
202     fclose(fid);
203     end
204 edhill 1.1

  ViewVC Help
Powered by ViewVC 1.1.22