source: Roms_tools/Preprocessing_tools/add_topo.m @ 2

Last change on this file since 2 was 1, checked in by cholod, 13 years ago

import Roms_Agrif

File size: 3.4 KB
Line 
1function 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%
46nc=netcdf(grdname);
47lon=nc{'lon_rho'}(:);
48lat=nc{'lat_rho'}(:);
49pm=nc{'pm'}(:);
50pn=nc{'pn'}(:);
51result=close(nc);
52%
53% Get ROMS averaged resolution
54%
55dx=mean(mean(1./pm));
56dy=mean(mean(1./pn));
57dx_roms=mean([dx dy]);
58disp(['   ROMS resolution : ',num2str(dx_roms/1000,3),' km'])
59%
60dl=max([1 2*(dx_roms/(60*1852))]);
61lonmin=min(min(lon))-dl;
62lonmax=max(max(lon))+dl;
63latmin=min(min(lat))-dl;
64latmax=max(max(lat))+dl;
65%
66%  open the topo file
67%
68nc=netcdf(toponame);
69tlon=nc{'lon'}(:);
70tlat=nc{'lat'}(:);
71%
72%  get a subgrid
73%
74j=find(tlat>=latmin & tlat<=latmax);
75i1=find(tlon-360>=lonmin & tlon-360<=lonmax);
76i2=find(tlon>=lonmin & tlon<=lonmax);
77i3=find(tlon+360>=lonmin & tlon+360<=lonmax);
78x=cat(1,tlon(i1)-360,tlon(i2),tlon(i3)+360);
79y=tlat(j);
80%
81%  Read data
82%
83if ~isempty(i2)
84  topo=-nc{'topo'}(j,i2);
85else
86  topo=[];
87end
88if ~isempty(i1)
89  topo=cat(2,-nc{'topo'}(j,i1),topo);
90end
91if ~isempty(i3)
92  topo=cat(2,topo,-nc{'topo'}(j,i3));
93end
94result=close(nc);
95%
96% Get TOPO averaged resolution
97%
98R=6367442.76;
99deg2rad=pi/180;
100dg=mean(x(2:end)-x(1:end-1));
101dphi=y(2:end)-y(1:end-1);
102dy=R*deg2rad*dphi;
103dx=R*deg2rad*dg*cos(deg2rad*y);
104dx_topo=mean([dx ;dy]);
105disp(['   Topography data resolution : ',num2str(dx_topo/1000,3),' km'])
106%
107% Degrade TOPO resolution
108%
109n=0;
110while 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]);
127end
128disp(['   Topography resolution halved ',num2str(n),' times'])
129disp(['   New topography resolution : ',num2str(dx_topo/1000,3),' km'])
130%
131%  interpolate the topo
132%
133h=interp2(x,y,topo,lon,lat,'cubic');
134%
135return
Note: See TracBrowser for help on using the repository browser.