/[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.2 - (hide annotations) (download)
Wed Aug 23 21:07:50 2006 UTC (18 years, 11 months ago) by edhill
Branch: MAIN
Changes since 1.1: +63 -6 lines
initial ci of bathy

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     if do_print > 0
126     print -depsc llc_bathy.eps
127     end
128    
129    
130 edhill 1.2 % Write the bathymetry to netCDF compatible with MNC
131     id = 'bathy';
132     units = 'm';
133     for k = 1:5
134     disp(sprintf(' k = %d',k));
135     ginfo(k).b_out = ginfo(k).bathy;
136     ginfo(k).b_out(find(ginfo(k).bathy >= 0.0)) = 0.0;
137     bfile = sprintf('llc_p90_bathy.f%03d.nc',k);
138    
139     nc = netcdf(bfile, 'clobber');
140     nc.reference = 'bathymetry';
141     nc.author = 'Ed Hill <eh3@mit.edu>';
142     nc.date = eval('date');
143     nc('X') = size( ginfo(k).XC, 1 );
144     nc('Y') = size( ginfo(k).XC, 2 );
145     nc{ id } = { 'Y', 'X' };
146     nc{ id }.units = units;
147     nc{ id }(:) = ginfo(k).b_out';
148     nc = close(nc);
149     end
150    
151     % Write the bathymetry to a set of 90-by-90 per-tile MDSIO-compatible
152     % files
153     % face is js
154     iti = [ 1 1 1 ; ...
155     1 91 1 ; ...
156     1 181 1 ; ...
157     1 271 1 ; ...
158     2 1 1 ; ...
159     2 91 1 ; ...
160     2 181 1 ; ...
161     2 271 1 ; ...
162     3 1 1 ; ...
163     4 1 1 ; ...
164     4 1 91 ; ...
165     4 1 181 ; ...
166     4 1 271 ; ...
167     5 1 1 ; ...
168     5 1 91 ; ...
169     5 1 181 ; ...
170     5 1 271 ];
171     for k = 1:size(iti,1)
172     disp(sprintf(' k = %d',k));
173     fname = sprintf('bathy.%03d.001.data',k);
174     fid = fopen(fname, 'w', 'ieee-be');
175     % be careful of index orientation
176     is = iti(k,3); ie = is + 90 - 1;
177     js = iti(k,2); je = js + 90 - 1;
178     tmp = ginfo(iti(k,1)).b_out(is:ie,js:je)';
179     surf(tmp), view(2), axis equal, shading flat, pause(1)
180     fwrite(fid,tmp,'real*8',0,'ieee-be');
181     fclose(fid);
182     end
183 edhill 1.1

  ViewVC Help
Powered by ViewVC 1.1.22