1 | function h=add_topo(grdname,toponame) |
---|
2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3 | % |
---|
4 | % add a topography (here etopo2) to a ROMS grid |
---|
5 | % |
---|
6 | % the topogaphy matrix is coarsened prior |
---|
7 | % to the interpolation on the ROMS grid tp |
---|
8 | % prevent the generation of noise due to |
---|
9 | % subsampling. this procedure ensure a better |
---|
10 | % general volume conservation. |
---|
11 | % |
---|
12 | % Last update Pierrick Penven 8/2006. |
---|
13 | % |
---|
14 | % |
---|
15 | % Further Information: |
---|
16 | % http://www.brest.ird.fr/Roms_tools/ |
---|
17 | % |
---|
18 | % This file is part of ROMSTOOLS |
---|
19 | % |
---|
20 | % ROMSTOOLS is free software; you can redistribute it and/or modify |
---|
21 | % it under the terms of the GNU General Public License as published |
---|
22 | % by the Free Software Foundation; either version 2 of the License, |
---|
23 | % or (at your option) any later version. |
---|
24 | % |
---|
25 | % ROMSTOOLS is distributed in the hope that it will be useful, but |
---|
26 | % WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
27 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
28 | % GNU General Public License for more details. |
---|
29 | % |
---|
30 | % You should have received a copy of the GNU General Public License |
---|
31 | % along with this program; if not, write to the Free Software |
---|
32 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
33 | % MA 02111-1307 USA |
---|
34 | % |
---|
35 | % Copyright (c) 2001-2006 by Pierrick Penven |
---|
36 | % e-mail:Pierrick.Penven@ird.fr |
---|
37 | % |
---|
38 | % Updated Aug-2006 by Pierrick Penven |
---|
39 | % Updated 2006/10/05 by Pierrick Penven (dl depend of model |
---|
40 | % resolution at low resolution) |
---|
41 | % |
---|
42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
43 | % |
---|
44 | % read roms grid |
---|
45 | % |
---|
46 | nc=netcdf(grdname); |
---|
47 | lon=nc{'lon_rho'}(:); |
---|
48 | lat=nc{'lat_rho'}(:); |
---|
49 | pm=nc{'pm'}(:); |
---|
50 | pn=nc{'pn'}(:); |
---|
51 | result=close(nc); |
---|
52 | % |
---|
53 | % Get ROMS averaged resolution |
---|
54 | % |
---|
55 | dx=mean(mean(1./pm)); |
---|
56 | dy=mean(mean(1./pn)); |
---|
57 | dx_roms=mean([dx dy]); |
---|
58 | disp([' ROMS resolution : ',num2str(dx_roms/1000,3),' km']) |
---|
59 | % |
---|
60 | dl=max([1 2*(dx_roms/(60*1852))]); |
---|
61 | lonmin=min(min(lon))-dl; |
---|
62 | lonmax=max(max(lon))+dl; |
---|
63 | latmin=min(min(lat))-dl; |
---|
64 | latmax=max(max(lat))+dl; |
---|
65 | % |
---|
66 | % open the topo file |
---|
67 | % |
---|
68 | nc=netcdf(toponame); |
---|
69 | tlon=nc{'lon'}(:); |
---|
70 | tlat=nc{'lat'}(:); |
---|
71 | % |
---|
72 | % get a subgrid |
---|
73 | % |
---|
74 | j=find(tlat>=latmin & tlat<=latmax); |
---|
75 | i1=find(tlon-360>=lonmin & tlon-360<=lonmax); |
---|
76 | i2=find(tlon>=lonmin & tlon<=lonmax); |
---|
77 | i3=find(tlon+360>=lonmin & tlon+360<=lonmax); |
---|
78 | x=cat(1,tlon(i1)-360,tlon(i2),tlon(i3)+360); |
---|
79 | y=tlat(j); |
---|
80 | % |
---|
81 | % Read data |
---|
82 | % |
---|
83 | if ~isempty(i2) |
---|
84 | topo=-nc{'topo'}(j,i2); |
---|
85 | else |
---|
86 | topo=[]; |
---|
87 | end |
---|
88 | if ~isempty(i1) |
---|
89 | topo=cat(2,-nc{'topo'}(j,i1),topo); |
---|
90 | end |
---|
91 | if ~isempty(i3) |
---|
92 | topo=cat(2,topo,-nc{'topo'}(j,i3)); |
---|
93 | end |
---|
94 | result=close(nc); |
---|
95 | % |
---|
96 | % Get TOPO averaged resolution |
---|
97 | % |
---|
98 | R=6367442.76; |
---|
99 | deg2rad=pi/180; |
---|
100 | dg=mean(x(2:end)-x(1:end-1)); |
---|
101 | dphi=y(2:end)-y(1:end-1); |
---|
102 | dy=R*deg2rad*dphi; |
---|
103 | dx=R*deg2rad*dg*cos(deg2rad*y); |
---|
104 | dx_topo=mean([dx ;dy]); |
---|
105 | disp([' Topography data resolution : ',num2str(dx_topo/1000,3),' km']) |
---|
106 | % |
---|
107 | % Degrade TOPO resolution |
---|
108 | % |
---|
109 | n=0; |
---|
110 | while dx_roms>(dx_topo) |
---|
111 | n=n+1; |
---|
112 | % |
---|
113 | x=0.5*(x(2:end)+x(1:end-1)); |
---|
114 | x=x(1:2:end); |
---|
115 | y=0.5*(y(2:end)+y(1:end-1)); |
---|
116 | y=y(1:2:end); |
---|
117 | % |
---|
118 | topo=0.25*(topo(2:end,1:end-1) +topo(2:end,2:end)+... |
---|
119 | topo(1:end-1,1:end-1)+topo(1:end-1,2:end)); |
---|
120 | topo=topo(1:2:end,1:2:end); |
---|
121 | % |
---|
122 | dg=mean(x(2:end)-x(1:end-1)); |
---|
123 | dphi=y(2:end)-y(1:end-1); |
---|
124 | dy=R*deg2rad*dphi; |
---|
125 | dx=R*deg2rad*dg*cos(deg2rad*y); |
---|
126 | dx_topo=mean([dx ;dy]); |
---|
127 | end |
---|
128 | disp([' Topography resolution halved ',num2str(n),' times']) |
---|
129 | disp([' New topography resolution : ',num2str(dx_topo/1000,3),' km']) |
---|
130 | % |
---|
131 | % interpolate the topo |
---|
132 | % |
---|
133 | h=interp2(x,y,topo,lon,lat,'cubic'); |
---|
134 | % |
---|
135 | return |
---|