source: Roms_tools/Preprocessing_tools/make_grid2.m @ 1

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

import Roms_Agrif

File size: 4.6 KB
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%
3%  Build a ROMS grid file
4%
5%
6%  Pierrick Penven, IRD, 2002.
7%
8%  Version of 10-Oct-2002
9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10clear all
11close all
12%%%%%%%%%%%%%%%%%%%%% USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%
13%
14%  Title
15%
16title='TEST';
17config='test';
18%
19%  Grid file name
20%
21grdname='test_grd.nc';
22%
23% Slope parameter (r=grad(h)/h) maximum value for topography smoothing
24%
25rtarget=0.15;
26%
27% Grid dimensions:
28%   lonmin : Minimum longitude [degree east]
29%   lonmax : Maximum longitude [degree east]
30%   latmin : Minimum latitude [degree north]
31%   latmax : Maximum latitude [degree north]
32if config=='test'
33%
34%  Test
35  lon1=43.9;
36  lat1=8.7;
37  lon2=34.1;
38  lat2=31.2;
39  lon3=46.9;
40  lat3=10.7;
41 
42end
43%
44% Grid resolution [degree]
45%
46dl=1/4;
47%
48% Minimum depth [m]
49%
50hmin=10;
51%
52%  Topography netcdf file name (ETOPO 2)
53%
54topofile='../Topo/etopo2.nc';
55%
56%  GSHSS user defined coastline (see m_map)
57%
58coastfileplot='';
59%
60%
61%%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%
62%
63% Title
64%
65disp(' ')
66disp([' Making the grid: ',grdname])
67disp(' ')
68disp([' Title: ',title])
69disp(' ')
70disp([' Resolution: 1/',num2str(1/dl),' deg'])
71%
72% Get the Longitude and latitude
73%
74theta=atan((lat3-lat1)/(lon3-lon1))
75l=(lon2-lon1)*cos(theta)+(lat2-lat1)*sin(theta)
76L=(lat2-lat1)*cos(theta)-(lon2-lon1)*sin(theta)
77x=(0:dl:l);
78y=(0:dl:L);
79[xr,yr]=meshgrid(x,y);
80Lonr=lon1+xr*cos(theta)-yr*sin(theta);
81Latr=lat1+xr*sin(theta)+yr*cos(theta);
82[Lonu,Lonv,Lonp]=rho2uvp(Lonr);
83[Latu,Latv,Latp]=rho2uvp(Latr);
84%
85% Create the grid file
86%
87disp(' ')
88disp(' Create the grid file...')
89[M,L]=size(Latp);
90disp([' LLm = ',num2str(L-1)])
91disp([' MMm = ',num2str(M-1)])
92create_grid(L,M,grdname,title)
93%
94% Fill the grid file
95%
96disp(' ')
97disp(' Fill the grid file...')
98nc=netcdf(grdname,'write');
99nc{'lat_u'}(:)=Latu;
100nc{'lon_u'}(:)=Lonu;
101nc{'lat_v'}(:)=Latv;
102nc{'lon_v'}(:)=Lonv;
103nc{'lat_rho'}(:)=Latr;
104nc{'lon_rho'}(:)=Lonr;
105nc{'lat_psi'}(:)=Latp;
106nc{'lon_psi'}(:)=Lonp;
107result=close(nc);
108%
109%  Compute the metrics
110%
111disp(' ')
112disp(' Compute the metrics...')
113[pm,pn,dndx,dmde]=get_metrics(grdname);
114xr=0.*pm;
115yr=xr;
116for i=1:L
117  xr(:,i+1)=xr(:,i)+2./(pm(:,i+1)+pm(:,i));
118end
119for j=1:M
120  yr(j+1,:)=yr(j,:)+2./(pn(j+1,:)+pn(j,:));
121end
122[xu,xv,xp]=rho2uvp(xr);
123[yu,yv,yp]=rho2uvp(yr);
124dx=1./pm;
125dy=1./pn;
126dxmax=max(max(dx/1000));
127dxmin=min(min(dx/1000));
128dymax=max(max(dy/1000));
129dymin=min(min(dy/1000));
130disp(' ')
131disp([' Min dx=',num2str(dxmin),' km - Max dx=',num2str(dxmax),' km'])
132disp([' Min dy=',num2str(dymin),' km - Max dy=',num2str(dymax),' km'])
133%
134%  Add topography from topofile
135%
136disp(' ')
137disp(' Add topography...')
138h=add_topo(grdname,topofile);
139%
140% Compute the mask
141%
142maskr=h>0;
143maskr=process_mask(maskr);
144if config=='kago'
145 maskr(Latr>45.5)=0;
146end
147if config=='test'
148 maskr(Lonr<41.5 & Latr<14.4)=0.;
149 maskr(Lonr<40.5 & Latr<14.6)=0.;
150end
151[masku,maskv,maskp]=uvp_mask(maskr);
152%
153%  Smooth the topography
154%
155h = smoothgrid(h,hmin,rtarget);
156%
157%  Angle between XI-axis and the direction
158%  to the EAST at RHO-points [radians].
159%
160angle=get_angle(Latu,Lonu);
161%
162%  Coriolis parameter
163%
164f=4*pi*sin(pi*Latr/180)/(24*3600);
165%
166%  Write it down
167%
168disp(' ')
169disp(' Write it down...')
170nc=netcdf(grdname,'write');
171nc{'h'}(:)=h;
172nc{'pm'}(:)=pm;
173nc{'pn'}(:)=pn;
174nc{'dndx'}(:)=dndx;
175nc{'dmde'}(:)=dmde;
176nc{'mask_u'}(:)=masku;
177nc{'mask_v'}(:)=maskv;
178nc{'mask_psi'}(:)=maskp;
179nc{'mask_rho'}(:)=maskr;
180nc{'x_u'}(:)=xu;
181nc{'y_u'}(:)=yu;
182nc{'x_v'}(:)=xv;
183nc{'y_v'}(:)=yv;
184nc{'x_rho'}(:)=xr;
185nc{'y_rho'}(:)=yr;
186nc{'x_psi'}(:)=xp;
187nc{'y_psi'}(:)=yp;
188nc{'angle'}(:)=angle;
189nc{'f'}(:)=f;
190nc{'spherical'}(:)='T';
191result=close(nc);
192disp(' ')
193disp(['  Size of the grid:  L = ',...
194      num2str(L),' - M = ',num2str(M)])
195%
196% make a plot
197%
198disp(' ')
199disp(' Do a plot...')
200themask=ones(size(maskr));
201themask(maskr==0)=NaN;
202domaxis=[min(min(Lonr)) max(max(Lonr)) min(min(Latr)) max(max(Latr))];
203colaxis=[min(min(h)) max(max(h))];
204fixcolorbar([0.25 0.05 0.5 0.03],colaxis,...
205            'Topography',10)
206width=1;
207height=0.8;
208subplot('position',[0. 0.14 width height])
209m_proj('mercator',...
210       'lon',[domaxis(1) domaxis(2)],...
211       'lat',[domaxis(3) domaxis(4)]);
212m_pcolor(Lonr,Latr,h.*themask);
213%shading interp
214caxis(colaxis)
215hold on
216m_contour(Lonr,Latr,h,[hmin 100 200 500 1000 2000 4000],'k--');
217if ~isempty(coastfileplot)
218  m_usercoast(coastfileplot,'patch',[.9 .9 .9]);
219else
220%  m_gshhs_l('patch',[.9 .9 .9])
221end
222m_grid('box','fancy',...
223       'xtick',5,'ytick',5,'tickdir','out',...
224       'fontsize',7);
225hold off
226%
227% End
228%
229%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note: See TracBrowser for help on using the repository browser.