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 |
|
|
ginfo(k).b_oce(find(ginfo(k).b_oce >= 0.0)) = NaN; |
110 |
|
|
% if k == 2, hold on, end |
111 |
|
|
figure(k) |
112 |
|
|
surf( ginfo(k).cor(:,:,1), ... |
113 |
|
|
ginfo(k).cor(:,:,2), ... |
114 |
|
|
ginfo(k).cor(:,:,3), ginfo(k).b_oce ) |
115 |
|
|
% if k == 5, hold off, end |
116 |
|
|
axis equal, view(2) |
117 |
|
|
end |
118 |
|
|
|
119 |
|
|
|
120 |
|
|
if do_print > 0 |
121 |
|
|
print -depsc llc_bathy.eps |
122 |
|
|
end |
123 |
|
|
|
124 |
|
|
|
125 |
|
|
% Write the resulting bathymetry |
126 |
|
|
|