source: Roms_tools/Preprocessing_tools/create_bryfile.m @ 1

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

import Roms_Agrif

File size: 14.7 KB
Line 
1function create_bryfile(bryname,grdname,title,obc,...
2                        theta_s,theta_b,hc,N,...
3                        time,cycle,clobber);
4%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5%
6% function create_bryfile(bryname,grdname,title,obc...
7%                          theta_s,theta_b,hc,N,...
8%                          time,cycle,clobber);
9%
10%   This function create the header of a Netcdf climatology
11%   file.
12%
13%   Input:
14%
15%   bryname      Netcdf climatology file name (character string).
16%   grdname      Netcdf grid file name (character string).
17%   obc          open boundaries flag (1=open , [S E N W]).
18%   theta_s      S-coordinate surface control parameter.(Real)
19%   theta_b      S-coordinate bottom control parameter.(Real)
20%   hc           Width (m) of surface or bottom boundary layer
21%                where higher vertical resolution is required
22%                during stretching.(Real)
23%   N            Number of vertical levels.(Integer)
24%   time         time.(vector)
25%   cycle        Length (days) for cycling the climatology.(Real)
26%   clobber      Switch to allow or not writing over an existing
27%                file.(character string)
28%
29%  Further Information: 
30%  http://www.brest.ird.fr/Roms_tools/
31
32%  This file is part of ROMSTOOLS
33%
34%  ROMSTOOLS is free software; you can redistribute it and/or modify
35%  it under the terms of the GNU General Public License as published
36%  by the Free Software Foundation; either version 2 of the License,
37%  or (at your option) any later version.
38%
39%  ROMSTOOLS is distributed in the hope that it will be useful, but
40%  WITHOUT ANY WARRANTY; without even the implied warranty of
41%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42%  GNU General Public License for more details.
43%
44%  You should have received a copy of the GNU General Public License
45%  along with this program; if not, write to the Free Software
46%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
47%  MA  02111-1307  USA
48%
49%  Copyright (c) 2001-2006 by Pierrick Penven
50%  e-mail:Pierrick.Penven@ird.fr 
51%
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53disp(' ')
54disp([' Creating the file : ',bryname])
55disp(' ')
56%
57%  Read the grid file and check the topography
58%
59nc = netcdf(grdname, 'nowrite');
60h=nc{'h'}(:);
61maskr=nc{'mask_rho'}(:);
62Lp=length(nc('xi_rho'));
63Mp=length(nc('eta_rho'));
64status=close(nc);
65hmin=min(min(h(maskr==1)));
66if hc > hmin
67  error([' hc (',num2str(hc),' m) > hmin (',num2str(hmin),' m)'])
68end
69L=Lp-1;
70M=Mp-1;
71Np=N+1;
72%
73%  Create the boundary file
74%
75type = 'BOUNDARY file' ;
76history = 'ROMS' ;
77nc = netcdf(bryname,clobber);
78result = redef(nc);
79%
80%  Create dimensions
81%
82nc('xi_u') = L;
83nc('xi_rho') = Lp;
84nc('eta_v') = M;
85nc('eta_rho') = Mp;
86nc('s_rho') = N;
87nc('bry_time') = length(time);
88nc('one') = 1;
89%
90%  Create variables and attributes
91%
92nc{'theta_s'} = ncdouble('one') ;
93nc{'theta_s'}.long_name = ncchar('S-coordinate surface control parameter');
94nc{'theta_s'}.long_name = 'S-coordinate surface control parameter';
95nc{'theta_s'}.units = ncchar('nondimensional');
96nc{'theta_s'}.units = 'nondimensional';
97%
98nc{'theta_b'} = ncdouble('one') ;
99nc{'theta_b'}.long_name = ncchar('S-coordinate bottom control parameter');
100nc{'theta_b'}.long_name = 'S-coordinate bottom control parameter';
101nc{'theta_b'}.units = ncchar('nondimensional');
102nc{'theta_b'}.units = 'nondimensional';
103%
104nc{'Tcline'} = ncdouble('one') ;
105nc{'Tcline'}.long_name = ncchar('S-coordinate surface/bottom layer width');
106nc{'Tcline'}.long_name = 'S-coordinate surface/bottom layer width';
107nc{'Tcline'}.units = ncchar('meter');
108nc{'Tcline'}.units = 'meter';
109%
110nc{'hc'} = ncdouble('one') ;
111nc{'hc'}.long_name = ncchar('S-coordinate parameter, critical depth');
112nc{'hc'}.long_name = 'S-coordinate parameter, critical depth';
113nc{'hc'}.units = ncchar('meter');
114nc{'hc'}.units = 'meter';
115%
116nc{'sc_r'} = ncdouble('s_rho') ;
117nc{'sc_r'}.long_name = ncchar('S-coordinate at RHO-points');
118nc{'sc_r'}.long_name = 'S-coordinate at RHO-points';
119nc{'sc_r'}.units = ncchar('nondimensional');
120nc{'sc_r'}.units = 'nondimensional';
121nc{'sc_r'}.valid_min = -1;
122nc{'sc_r'}.valid_max = 0;
123%
124nc{'Cs_r'} = ncdouble('s_rho') ;
125nc{'Cs_r'}.long_name = ncchar('S-coordinate stretching curves at RHO-points');
126nc{'Cs_r'}.long_name = 'S-coordinate stretching curves at RHO-points';
127nc{'Cs_r'}.units = ncchar('nondimensional');
128nc{'Cs_r'}.units = 'nondimensional';
129nc{'Cs_r'}.valid_min = -1;
130nc{'Cs_r'}.valid_max = 0;
131%
132nc{'bry_time'} = ncdouble('bry_time') ;
133nc{'bry_time'}.long_name = ncchar('time for temperature climatology');
134nc{'bry_time'}.long_name = 'time for temperature climatology';
135nc{'bry_time'}.units = ncchar('day');
136nc{'bry_time'}.units = 'day';
137nc{'bry_time'}.cycle_length = cycle;%
138%
139if obc(1)==1
140%
141%   Southern boundary
142%
143  nc{'temp_south'} = ncdouble('bry_time','s_rho','xi_rho') ;
144  nc{'temp_south'}.long_name = ncchar('southern boundary potential temperature');
145  nc{'temp_south'}.long_name = 'southern boundary potential temperature';
146  nc{'temp_south'}.units = ncchar('Celsius');
147  nc{'temp_south'}.units = 'Celsius';
148%
149  nc{'salt_south'} = ncdouble('bry_time','s_rho','xi_rho') ;
150  nc{'salt_south'}.long_name = ncchar('southern boundary salinity');
151  nc{'salt_south'}.long_name = 'southern boundary salinity';
152  nc{'salt_south'}.units = ncchar('PSU');
153  nc{'salt_south'}.units = 'PSU';
154%
155  nc{'u_south'} = ncdouble('bry_time','s_rho','xi_u') ;
156  nc{'u_south'}.long_name = ncchar('southern boundary u-momentum component');
157  nc{'u_south'}.long_name = 'southern boundary u-momentum component';
158  nc{'u_south'}.units = ncchar('meter second-1');
159  nc{'u_south'}.units = 'meter second-1';
160%
161  nc{'v_south'} = ncdouble('bry_time','s_rho','xi_rho') ;
162  nc{'v_south'}.long_name = ncchar('southern boundary v-momentum component');
163  nc{'v_south'}.long_name = 'southern boundary v-momentum component';
164  nc{'v_south'}.units = ncchar('meter second-1');
165  nc{'v_south'}.units = 'meter second-1';
166%
167  nc{'ubar_south'} = ncdouble('bry_time','xi_u') ;
168  nc{'ubar_south'}.long_name = ncchar('southern boundary vertically integrated u-momentum component');
169  nc{'ubar_south'}.long_name = 'southern boundary vertically integrated u-momentum component';
170  nc{'ubar_south'}.units = ncchar('meter second-1');
171  nc{'ubar_south'}.units = 'meter second-1';
172%
173  nc{'vbar_south'} = ncdouble('bry_time','xi_rho') ;
174  nc{'vbar_south'}.long_name = ncchar('southern boundary vertically integrated v-momentum component');
175  nc{'vbar_south'}.long_name = 'southern boundary vertically integrated v-momentum component';
176  nc{'vbar_south'}.units = ncchar('meter second-1');
177  nc{'vbar_south'}.units = 'meter second-1';
178%
179  nc{'zeta_south'} = ncdouble('bry_time','xi_rho') ;
180  nc{'zeta_south'}.long_name = ncchar('southern boundary sea surface height');
181  nc{'zeta_south'}.long_name = 'southern boundary sea surface height';
182  nc{'zeta_south'}.units = ncchar('meter');
183  nc{'zeta_south'}.units = 'meter';
184%
185end
186%
187if obc(2)==1
188%
189%   Eastern boundary
190%
191  nc{'temp_east'} = ncdouble('bry_time','s_rho','eta_rho') ;
192  nc{'temp_east'}.long_name = ncchar('eastern boundary potential temperature');
193  nc{'temp_east'}.long_name = 'eastern boundary potential temperature';
194  nc{'temp_east'}.units = ncchar('Celsius');
195  nc{'temp_east'}.units = 'Celsius';
196%
197  nc{'salt_east'} = ncdouble('bry_time','s_rho','eta_rho') ;
198  nc{'salt_east'}.long_name = ncchar('eastern boundary salinity');
199  nc{'salt_east'}.long_name = 'eastern boundary salinity';
200  nc{'salt_east'}.units = ncchar('PSU');
201  nc{'salt_east'}.units = 'PSU';
202%
203  nc{'u_east'} = ncdouble('bry_time','s_rho','eta_rho') ;
204  nc{'u_east'}.long_name = ncchar('eastern boundary u-momentum component');
205  nc{'u_east'}.long_name = 'eastern boundary u-momentum component';
206  nc{'u_east'}.units = ncchar('meter second-1');
207  nc{'u_east'}.units = 'meter second-1';
208%
209  nc{'v_east'} = ncdouble('bry_time','s_rho','eta_v') ;
210  nc{'v_east'}.long_name = ncchar('eastern boundary v-momentum component');
211  nc{'v_east'}.long_name = 'eastern boundary v-momentum component';
212  nc{'v_east'}.units = ncchar('meter second-1');
213  nc{'v_east'}.units = 'meter second-1';
214%
215  nc{'ubar_east'} = ncdouble('bry_time','eta_rho') ;
216  nc{'ubar_east'}.long_name = ncchar('eastern boundary vertically integrated u-momentum component');
217  nc{'ubar_east'}.long_name = 'eastern boundary vertically integrated u-momentum component';
218  nc{'ubar_east'}.units = ncchar('meter second-1');
219  nc{'ubar_east'}.units = 'meter second-1';
220%
221  nc{'vbar_east'} = ncdouble('bry_time','eta_v') ;
222  nc{'vbar_east'}.long_name = ncchar('eastern boundary vertically integrated v-momentum component');
223  nc{'vbar_east'}.long_name = 'eastern boundary vertically integrated v-momentum component';
224  nc{'vbar_east'}.units = ncchar('meter second-1');
225  nc{'vbar_east'}.units = 'meter second-1';
226%
227  nc{'zeta_east'} = ncdouble('bry_time','eta_rho') ;
228  nc{'zeta_east'}.long_name = ncchar('eastern boundary sea surface height');
229  nc{'zeta_east'}.long_name = 'eastern boundary sea surface height';
230  nc{'zeta_east'}.units = ncchar('meter');
231  nc{'zeta_east'}.units = 'meter';
232%
233end
234%
235if obc(3)==1
236%
237%   Northern boundary
238%
239  nc{'temp_north'} = ncdouble('bry_time','s_rho','xi_rho') ;
240  nc{'temp_north'}.long_name = ncchar('northern boundary potential temperature');
241  nc{'temp_north'}.long_name = 'northern boundary potential temperature';
242  nc{'temp_north'}.units = ncchar('Celsius');
243  nc{'temp_north'}.units = 'Celsius';
244%
245  nc{'salt_north'} = ncdouble('bry_time','s_rho','xi_rho') ;
246  nc{'salt_north'}.long_name = ncchar('northern boundary salinity');
247  nc{'salt_north'}.long_name = 'northern boundary salinity';
248  nc{'salt_north'}.units = ncchar('PSU');
249  nc{'salt_north'}.units = 'PSU';
250%
251  nc{'u_north'} = ncdouble('bry_time','s_rho','xi_u') ;
252  nc{'u_north'}.long_name = ncchar('northern boundary u-momentum component');
253  nc{'u_north'}.long_name = 'northern boundary u-momentum component';
254  nc{'u_north'}.units = ncchar('meter second-1');
255  nc{'u_north'}.units = 'meter second-1';
256%
257  nc{'v_north'} = ncdouble('bry_time','s_rho','xi_rho') ;
258  nc{'v_north'}.long_name = ncchar('northern boundary v-momentum component');
259  nc{'v_north'}.long_name = 'northern boundary v-momentum component';
260  nc{'v_north'}.units = ncchar('meter second-1');
261  nc{'v_north'}.units = 'meter second-1';
262%
263  nc{'ubar_north'} = ncdouble('bry_time','xi_u') ;
264  nc{'ubar_north'}.long_name = ncchar('northern boundary vertically integrated u-momentum component');
265  nc{'ubar_north'}.long_name = 'northern boundary vertically integrated u-momentum component';
266  nc{'ubar_north'}.units = ncchar('meter second-1');
267  nc{'ubar_north'}.units = 'meter second-1';
268%
269  nc{'vbar_north'} = ncdouble('bry_time','xi_rho') ;
270  nc{'vbar_north'}.long_name = ncchar('northern boundary vertically integrated v-momentum component');
271  nc{'vbar_north'}.long_name = 'northern boundary vertically integrated v-momentum component';
272  nc{'vbar_north'}.units = ncchar('meter second-1');
273  nc{'vbar_north'}.units = 'meter second-1';
274%
275  nc{'zeta_north'} = ncdouble('bry_time','xi_rho') ;
276  nc{'zeta_north'}.long_name = ncchar('northern boundary sea surface height');
277  nc{'zeta_north'}.long_name = 'northern boundary sea surface height';
278  nc{'zeta_north'}.units = ncchar('meter');
279  nc{'zeta_north'}.units = 'meter';
280%
281end
282%
283if obc(4)==1
284%
285%   Western boundary
286%
287  nc{'temp_west'} = ncdouble('bry_time','s_rho','eta_rho') ;
288  nc{'temp_west'}.long_name = ncchar('western boundary potential temperature');
289  nc{'temp_west'}.long_name = 'western boundary potential temperature';
290  nc{'temp_west'}.units = ncchar('Celsius');
291  nc{'temp_west'}.units = 'Celsius';
292%
293  nc{'salt_west'} = ncdouble('bry_time','s_rho','eta_rho') ;
294  nc{'salt_west'}.long_name = ncchar('western boundary salinity');
295  nc{'salt_west'}.long_name = 'western boundary salinity';
296  nc{'salt_west'}.units = ncchar('PSU');
297  nc{'salt_west'}.units = 'PSU';
298%
299  nc{'u_west'} = ncdouble('bry_time','s_rho','eta_rho') ;
300  nc{'u_west'}.long_name = ncchar('western boundary u-momentum component');
301  nc{'u_west'}.long_name = 'western boundary u-momentum component';
302  nc{'u_west'}.units = ncchar('meter second-1');
303  nc{'u_west'}.units = 'meter second-1';
304%
305  nc{'v_west'} = ncdouble('bry_time','s_rho','eta_v') ;
306  nc{'v_west'}.long_name = ncchar('western boundary v-momentum component');
307  nc{'v_west'}.long_name = 'western boundary v-momentum component';
308  nc{'v_west'}.units = ncchar('meter second-1');
309  nc{'v_west'}.units = 'meter second-1';
310%
311  nc{'ubar_west'} = ncdouble('bry_time','eta_rho') ;
312  nc{'ubar_west'}.long_name = ncchar('western boundary vertically integrated u-momentum component');
313  nc{'ubar_west'}.long_name = 'western boundary vertically integrated u-momentum component';
314  nc{'ubar_west'}.units = ncchar('meter second-1');
315  nc{'ubar_west'}.units = 'meter second-1';
316%
317  nc{'vbar_west'} = ncdouble('bry_time','eta_v') ;
318  nc{'vbar_west'}.long_name = ncchar('western boundary vertically integrated v-momentum component');
319  nc{'vbar_west'}.long_name = 'western boundary vertically integrated v-momentum component';
320  nc{'vbar_west'}.units = ncchar('meter second-1');
321  nc{'vbar_west'}.units = 'meter second-1';
322%
323  nc{'zeta_west'} = ncdouble('bry_time','eta_rho') ;
324  nc{'zeta_west'}.long_name = ncchar('western boundary sea surface height');
325  nc{'zeta_west'}.long_name = 'western boundary sea surface height';
326  nc{'zeta_west'}.units = ncchar('meter');
327  nc{'zeta_west'}.units = 'meter';
328%
329end
330%
331%
332% Create global attributes
333%
334nc.title = ncchar(title);
335nc.title = title;
336nc.date = ncchar(date);
337nc.date = date;
338nc.clim_file = ncchar(bryname);
339nc.clim_file = bryname;
340nc.grd_file = ncchar(grdname);
341nc.grd_file = grdname;
342nc.type = ncchar(type);
343nc.type = type;
344nc.history = ncchar(history);
345nc.history = history;
346%
347% Leave define mode
348%
349result = endef(nc);
350%
351% Compute S coordinates
352%
353cff1=1./sinh(theta_s);
354cff2=0.5/tanh(0.5*theta_s);
355sc=((1:N)-N-0.5)/N;
356Cs=(1.-theta_b)*cff1*sinh(theta_s*sc)...
357    +theta_b*(cff2*tanh(theta_s*(sc+0.5))-0.5);
358%
359% Write variables
360%
361nc{'theta_s'}(:) =  theta_s;
362nc{'theta_b'}(:) =  theta_b;
363nc{'Tcline'}(:) =  hc;
364nc{'hc'}(:) =  hc;
365nc{'sc_r'}(:) =  sc;
366nc{'Cs_r'}(:) =  Cs;
367nc{'bry_time'}(:) =  time;
368if obc(1)==1
369  nc{'u_south'}(:) =  0;
370  nc{'v_south'}(:) =  0;
371  nc{'ubar_south'}(:) =  0;
372  nc{'vbar_south'}(:) =  0;
373  nc{'zeta_south'}(:) =  0;
374  nc{'temp_south'}(:) =  0;
375  nc{'salt_south'}(:) =  0;
376end
377if obc(2)==1
378  nc{'u_east'}(:) =  0;
379  nc{'v_east'}(:) =  0;
380  nc{'ubar_east'}(:) =  0;
381  nc{'vbar_east'}(:) =  0;
382  nc{'zeta_east'}(:) =  0;
383  nc{'temp_east'}(:) =  0;
384  nc{'salt_east'}(:) =  0;
385end
386if obc(3)==1
387  nc{'u_north'}(:) =  0;
388  nc{'v_north'}(:) =  0;
389  nc{'ubar_north'}(:) =  0;
390  nc{'vbar_north'}(:) =  0;
391  nc{'zeta_north'}(:) =  0;
392  nc{'temp_north'}(:) =  0;
393  nc{'salt_north'}(:) =  0;
394end
395if obc(4)==1
396  nc{'u_west'}(:) =  0;
397  nc{'v_west'}(:) =  0;
398  nc{'ubar_west'}(:) =  0;
399  nc{'vbar_west'}(:) =  0;
400  nc{'zeta_west'}(:) =  0;
401  nc{'temp_west'}(:) =  0;
402  nc{'salt_west'}(:) =  0;
403end
404close(nc)
405return
406
407
Note: See TracBrowser for help on using the repository browser.