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 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
34 | clear all |
---|
35 | close all |
---|
36 | %%%%%%%%%%%%%%%%%%%%% USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%% |
---|
37 | % |
---|
38 | romstools_param |
---|
39 | % |
---|
40 | %%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%% |
---|
41 | warning off |
---|
42 | % |
---|
43 | % Title |
---|
44 | % |
---|
45 | disp(' ') |
---|
46 | disp([' Making the grid: ',grdname]) |
---|
47 | disp(' ') |
---|
48 | disp([' Title: ',ROMS_title]) |
---|
49 | disp(' ') |
---|
50 | disp([' Resolution: 1/',num2str(1/dl),' deg']) |
---|
51 | % |
---|
52 | % Get the Longitude |
---|
53 | % |
---|
54 | lonr=(lonmin:dl:lonmax); |
---|
55 | % |
---|
56 | % Get the latitude for an isotropic grid |
---|
57 | % |
---|
58 | i=1; |
---|
59 | latr(i)=latmin; |
---|
60 | while latr(i)<=latmax |
---|
61 | i=i+1; |
---|
62 | latr(i)=latr(i-1)+dl*cos(latr(i-1)*pi/180); |
---|
63 | end |
---|
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 | % |
---|
70 | disp(' ') |
---|
71 | disp(' Create the grid file...') |
---|
72 | [M,L]=size(Latp); |
---|
73 | disp([' LLm = ',num2str(L-1)]) |
---|
74 | disp([' MMm = ',num2str(M-1)]) |
---|
75 | create_grid(L,M,grdname,ROMS_title) |
---|
76 | % |
---|
77 | % Fill the grid file |
---|
78 | % |
---|
79 | disp(' ') |
---|
80 | disp(' Fill the grid file...') |
---|
81 | nc=netcdf(grdname,'write'); |
---|
82 | nc{'lat_u'}(:)=Latu; |
---|
83 | nc{'lon_u'}(:)=Lonu; |
---|
84 | nc{'lat_v'}(:)=Latv; |
---|
85 | nc{'lon_v'}(:)=Lonv; |
---|
86 | nc{'lat_rho'}(:)=Latr; |
---|
87 | nc{'lon_rho'}(:)=Lonr; |
---|
88 | nc{'lat_psi'}(:)=Latp; |
---|
89 | nc{'lon_psi'}(:)=Lonp; |
---|
90 | close(nc) |
---|
91 | % |
---|
92 | % Compute the metrics |
---|
93 | % |
---|
94 | disp(' ') |
---|
95 | disp(' Compute the metrics...') |
---|
96 | [pm,pn,dndx,dmde]=get_metrics(grdname); |
---|
97 | xr=0.*pm; |
---|
98 | yr=xr; |
---|
99 | for i=1:L |
---|
100 | xr(:,i+1)=xr(:,i)+2./(pm(:,i+1)+pm(:,i)); |
---|
101 | end |
---|
102 | for j=1:M |
---|
103 | yr(j+1,:)=yr(j,:)+2./(pn(j+1,:)+pn(j,:)); |
---|
104 | end |
---|
105 | [xu,xv,xp]=rho2uvp(xr); |
---|
106 | [yu,yv,yp]=rho2uvp(yr); |
---|
107 | dx=1./pm; |
---|
108 | dy=1./pn; |
---|
109 | dxmax=max(max(dx/1000)); |
---|
110 | dxmin=min(min(dx/1000)); |
---|
111 | dymax=max(max(dy/1000)); |
---|
112 | dymin=min(min(dy/1000)); |
---|
113 | disp(' ') |
---|
114 | disp([' Min dx=',num2str(dxmin),' km - Max dx=',num2str(dxmax),' km']) |
---|
115 | disp([' 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 | % |
---|
120 | angle=get_angle(Latu,Lonu); |
---|
121 | % |
---|
122 | % Coriolis parameter |
---|
123 | % |
---|
124 | f=4*pi*sin(pi*Latr/180)/(24*3600); |
---|
125 | % |
---|
126 | % Fill the grid file |
---|
127 | % |
---|
128 | disp(' ') |
---|
129 | disp(' Fill the grid file...') |
---|
130 | nc=netcdf(grdname,'write'); |
---|
131 | nc{'pm'}(:)=pm; |
---|
132 | nc{'pn'}(:)=pn; |
---|
133 | nc{'dndx'}(:)=dndx; |
---|
134 | nc{'dmde'}(:)=dmde; |
---|
135 | nc{'x_u'}(:)=xu; |
---|
136 | nc{'y_u'}(:)=yu; |
---|
137 | nc{'x_v'}(:)=xv; |
---|
138 | nc{'y_v'}(:)=yv; |
---|
139 | nc{'x_rho'}(:)=xr; |
---|
140 | nc{'y_rho'}(:)=yr; |
---|
141 | nc{'x_psi'}(:)=xp; |
---|
142 | nc{'y_psi'}(:)=yp; |
---|
143 | nc{'angle'}(:)=angle; |
---|
144 | nc{'f'}(:)=f; |
---|
145 | nc{'spherical'}(:)='T'; |
---|
146 | close(nc); |
---|
147 | % |
---|
148 | % |
---|
149 | % Add topography from topofile |
---|
150 | % |
---|
151 | disp(' ') |
---|
152 | disp(' Add topography...') |
---|
153 | h=add_topo(grdname,topofile); |
---|
154 | % |
---|
155 | % Compute the mask |
---|
156 | % |
---|
157 | maskr=h>0; |
---|
158 | maskr=process_mask(maskr); |
---|
159 | [masku,maskv,maskp]=uvp_mask(maskr); |
---|
160 | % |
---|
161 | % Write it down |
---|
162 | % |
---|
163 | nc=netcdf(grdname,'write'); |
---|
164 | nc{'h'}(:)=h; |
---|
165 | nc{'mask_u'}(:)=masku; |
---|
166 | nc{'mask_v'}(:)=maskv; |
---|
167 | nc{'mask_psi'}(:)=maskp; |
---|
168 | nc{'mask_rho'}(:)=maskr; |
---|
169 | close(nc); |
---|
170 | % |
---|
171 | % Create the coastline |
---|
172 | % |
---|
173 | if ~isempty(coastfileplot) |
---|
174 | make_coast(grdname,coastfileplot); |
---|
175 | end |
---|
176 | % |
---|
177 | r=input('Do you want to use editmask ? y,[n]','s'); |
---|
178 | if 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'); |
---|
189 | end |
---|
190 | % |
---|
191 | close all |
---|
192 | % |
---|
193 | % Smooth the topography |
---|
194 | % |
---|
195 | nc=netcdf(grdname,'write'); |
---|
196 | h=nc{'h'}(:); |
---|
197 | maskr=nc{'mask_rho'}(:); |
---|
198 | % |
---|
199 | h=smoothgrid(h,maskr,hmin,hmax_coast,... |
---|
200 | rtarget,n_filter_deep_topo,n_filter_final); |
---|
201 | % |
---|
202 | % Write it down |
---|
203 | % |
---|
204 | disp(' ') |
---|
205 | disp(' Write it down...') |
---|
206 | nc{'h'}(:)=h; |
---|
207 | close(nc); |
---|
208 | % |
---|
209 | % make a plot |
---|
210 | % |
---|
211 | if 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 |
---|
243 | end |
---|
244 | warning on |
---|
245 | % |
---|
246 | % End |
---|
247 | % |
---|
248 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
249 | |
---|