source: Roms_tools/Preprocessing_tools/make_grid.m @ 2

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

import Roms_Agrif

File size: 5.6 KB
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%
3%  Build a ROMS grid file
4%
5%  Further Information: 
6%  http://www.brest.ird.fr/Roms_tools/
7
8%  This file is part of ROMSTOOLS
9%
10%  ROMSTOOLS is free software; you can redistribute it and/or modify
11%  it under the terms of the GNU General Public License as published
12%  by the Free Software Foundation; either version 2 of the License,
13%  or (at your option) any later version.
14%
15%  ROMSTOOLS is distributed in the hope that it will be useful, but
16%  WITHOUT ANY WARRANTY; without even the implied warranty of
17%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18%  GNU General Public License for more details.
19%
20%  You should have received a copy of the GNU General Public License
21%  along with this program; if not, write to the Free Software
22%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23%  MA  02111-1307  USA
24%
25%  Copyright (c) 2002-2006 by Pierrick Penven
26%  e-mail:Pierrick.Penven@ird.fr 
27%
28%  Contributions of P. Marchesiello (IRD) and X. Capet (UCLA)
29%
30%  Updated    Aug-2006 by Pierrick Penven
31%  Updated    24-Oct-2006 by Pierrick Penven (mask correction)
32%
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34clear all
35close all
36%%%%%%%%%%%%%%%%%%%%% USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%
37%
38romstools_param
39%
40%%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%
41warning off
42%
43% Title
44%
45disp(' ')
46disp([' Making the grid: ',grdname])
47disp(' ')
48disp([' Title: ',ROMS_title])
49disp(' ')
50disp([' Resolution: 1/',num2str(1/dl),' deg'])
51%
52% Get the Longitude
53%
54lonr=(lonmin:dl:lonmax);
55%
56% Get the latitude for an isotropic grid
57%
58i=1;
59latr(i)=latmin;
60while latr(i)<=latmax
61  i=i+1;
62  latr(i)=latr(i-1)+dl*cos(latr(i-1)*pi/180);
63end
64[Lonr,Latr]=meshgrid(lonr,latr);
65[Lonu,Lonv,Lonp]=rho2uvp(Lonr);
66[Latu,Latv,Latp]=rho2uvp(Latr);
67%
68% Create the grid file
69%
70disp(' ')
71disp(' Create the grid file...')
72[M,L]=size(Latp);
73disp([' LLm = ',num2str(L-1)])
74disp([' MMm = ',num2str(M-1)])
75create_grid(L,M,grdname,ROMS_title)
76%
77% Fill the grid file
78%
79disp(' ')
80disp(' Fill the grid file...')
81nc=netcdf(grdname,'write');
82nc{'lat_u'}(:)=Latu;
83nc{'lon_u'}(:)=Lonu;
84nc{'lat_v'}(:)=Latv;
85nc{'lon_v'}(:)=Lonv;
86nc{'lat_rho'}(:)=Latr;
87nc{'lon_rho'}(:)=Lonr;
88nc{'lat_psi'}(:)=Latp;
89nc{'lon_psi'}(:)=Lonp;
90close(nc)
91%
92%  Compute the metrics
93%
94disp(' ')
95disp(' Compute the metrics...')
96[pm,pn,dndx,dmde]=get_metrics(grdname);
97xr=0.*pm;
98yr=xr;
99for i=1:L
100  xr(:,i+1)=xr(:,i)+2./(pm(:,i+1)+pm(:,i));
101end
102for j=1:M
103  yr(j+1,:)=yr(j,:)+2./(pn(j+1,:)+pn(j,:));
104end
105[xu,xv,xp]=rho2uvp(xr);
106[yu,yv,yp]=rho2uvp(yr);
107dx=1./pm;
108dy=1./pn;
109dxmax=max(max(dx/1000));
110dxmin=min(min(dx/1000));
111dymax=max(max(dy/1000));
112dymin=min(min(dy/1000));
113disp(' ')
114disp([' Min dx=',num2str(dxmin),' km - Max dx=',num2str(dxmax),' km'])
115disp([' Min dy=',num2str(dymin),' km - Max dy=',num2str(dymax),' km'])
116%
117%  Angle between XI-axis and the direction
118%  to the EAST at RHO-points [radians].
119%
120angle=get_angle(Latu,Lonu);
121%
122%  Coriolis parameter
123%
124f=4*pi*sin(pi*Latr/180)/(24*3600);
125%
126% Fill the grid file
127%
128disp(' ')
129disp(' Fill the grid file...')
130nc=netcdf(grdname,'write');
131nc{'pm'}(:)=pm;
132nc{'pn'}(:)=pn;
133nc{'dndx'}(:)=dndx;
134nc{'dmde'}(:)=dmde;
135nc{'x_u'}(:)=xu;
136nc{'y_u'}(:)=yu;
137nc{'x_v'}(:)=xv;
138nc{'y_v'}(:)=yv;
139nc{'x_rho'}(:)=xr;
140nc{'y_rho'}(:)=yr;
141nc{'x_psi'}(:)=xp;
142nc{'y_psi'}(:)=yp;
143nc{'angle'}(:)=angle;
144nc{'f'}(:)=f;
145nc{'spherical'}(:)='T';
146close(nc);
147%
148%
149%  Add topography from topofile
150%
151disp(' ')
152disp(' Add topography...')
153h=add_topo(grdname,topofile);
154%
155% Compute the mask
156%
157maskr=h>0;
158maskr=process_mask(maskr);
159[masku,maskv,maskp]=uvp_mask(maskr);
160%
161%  Write it down
162%
163nc=netcdf(grdname,'write');
164nc{'h'}(:)=h;
165nc{'mask_u'}(:)=masku;
166nc{'mask_v'}(:)=maskv;
167nc{'mask_psi'}(:)=maskp;
168nc{'mask_rho'}(:)=maskr;
169close(nc);
170%
171% Create the coastline
172%
173if ~isempty(coastfileplot)
174  make_coast(grdname,coastfileplot);
175end
176%
177r=input('Do you want to use editmask ? y,[n]','s');
178if strcmp(r,'y')
179  disp(' Editmask:')
180  disp(' Edit manually the land mask.')
181  disp(' Press enter when finished.')
182  disp(' ')
183  if ~isempty(coastfileplot)
184    editmask(grdname,coastfilemask)
185  else
186    editmask(grdname)
187  end
188  r=input(' Finished with edit mask ? [press enter when finished]','s');
189end
190%
191close all
192%
193%  Smooth the topography
194%
195nc=netcdf(grdname,'write');
196h=nc{'h'}(:);
197maskr=nc{'mask_rho'}(:);
198%
199h=smoothgrid(h,maskr,hmin,hmax_coast,...
200             rtarget,n_filter_deep_topo,n_filter_final);
201%
202%  Write it down
203%
204disp(' ')
205disp(' Write it down...')
206nc{'h'}(:)=h;
207close(nc);
208%
209% make a plot
210%
211if makeplot==1
212  disp(' ')
213  disp(' Do a plot...')
214  themask=ones(size(maskr));
215  themask(maskr==0)=NaN;
216  domaxis=[min(min(Lonr)) max(max(Lonr)) min(min(Latr)) max(max(Latr))];
217  colaxis=[min(min(h)) max(max(h))];
218  fixcolorbar([0.25 0.05 0.5 0.03],colaxis,...
219              'Topography',10)
220  width=1;
221  height=0.8;
222  subplot('position',[0. 0.14 width height])
223  m_proj('mercator',...
224         'lon',[domaxis(1) domaxis(2)],...
225         'lat',[domaxis(3) domaxis(4)]);
226  m_pcolor(Lonr,Latr,h.*themask);
227  shading flat
228  caxis(colaxis)
229  hold on
230  [C1,h1]=m_contour(Lonr,Latr,h,[hmin 100 200 500 1000 2000 4000],'k');
231  clabel(C1,h1,'LabelSpacing',1000,'Rotation',0,'Color','r')
232  if ~isempty(coastfileplot)
233    m_usercoast(coastfileplot,'color','r');
234    %m_usercoast(coastfileplot,'speckle','color','r');
235  else
236    m_gshhs_l('color','r');
237    m_gshhs_l('speckle','color','r');
238  end
239  m_grid('box','fancy',...
240         'xtick',5,'ytick',5,'tickdir','out',...
241         'fontsize',7);
242  hold off
243end
244warning on
245%
246% End
247%
248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249
Note: See TracBrowser for help on using the repository browser.