source: Roms_tools/Preprocessing_tools/create_inifile.m @ 2

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

import Roms_Agrif

File size: 7.4 KB
Line 
1function create_inifile2(inifile,gridfile,title,...
2                         theta_s,theta_b,hc,N,time,clobber)
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5%  function nc=create_inifile(inifile,gridfile,theta_s,...
6%                  theta_b,hc,N,ttime,stime,utime,...
7%                  cycle,clobber)
8%
9%   This function create the header of a Netcdf climatology
10%   file.
11%
12%   Input:
13%
14%   inifile      Netcdf initial file name (character string).
15%   gridfile     Netcdf grid file name (character string).
16%   theta_s      S-coordinate surface control parameter.(Real)
17%   theta_b      S-coordinate bottom control parameter.(Real)
18%   hc           Width (m) of surface or bottom boundary layer
19%                where higher vertical resolution is required
20%                during stretching.(Real)
21%   N            Number of vertical levels.(Integer) 
22%   time         Initial time.(Real)
23%   clobber      Switch to allow or not writing over an existing
24%                file.(character string)
25%
26%   Output
27%
28%   nc       Output netcdf object.
29%
30%  Further Information: 
31%  http://www.brest.ird.fr/Roms_tools/
32
33%  This file is part of ROMSTOOLS
34%
35%  ROMSTOOLS is free software; you can redistribute it and/or modify
36%  it under the terms of the GNU General Public License as published
37%  by the Free Software Foundation; either version 2 of the License,
38%  or (at your option) any later version.
39%
40%  ROMSTOOLS is distributed in the hope that it will be useful, but
41%  WITHOUT ANY WARRANTY; without even the implied warranty of
42%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43%  GNU General Public License for more details.
44%
45%  You should have received a copy of the GNU General Public License
46%  along with this program; if not, write to the Free Software
47%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
48%  MA  02111-1307  USA
49%
50%  Copyright (c) 2001-2006 by Pierrick Penven
51%  e-mail:Pierrick.Penven@ird.fr 
52%
53%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54disp(' ')
55disp([' Creating the file : ',inifile])
56%
57%  Read the grid file
58%
59nc=netcdf(gridfile);
60h=nc{'h'}(:); 
61mask=nc{'mask_rho'}(:);
62close(nc);
63hmin=min(min(h(mask==1)));
64if hc > hmin
65  error([' hc (',num2str(hc),' m) > hmin (',num2str(hmin),' m)'])
66end
67[Mp,Lp]=size(h);
68L=Lp-1;
69M=Mp-1;
70Np=N+1;
71%
72%  Create the initial file
73%
74type = 'INITIAL file' ;
75history = 'ROMS' ;
76nc = netcdf(inifile,clobber);
77result = redef(nc);
78%
79%  Create dimensions
80%
81nc('xi_u') = L;
82nc('xi_v') = Lp;
83nc('xi_rho') = Lp;
84nc('eta_u') = Mp;
85nc('eta_v') = M;
86nc('eta_rho') = Mp;
87nc('s_rho') = N;
88nc('s_w') = Np;
89nc('tracer') = 2;
90nc('time') = 0;
91nc('one') = 1;
92%
93%  Create variables
94%
95nc{'tstart'} = ncdouble('one') ;
96nc{'tend'} = ncdouble('one') ;
97nc{'theta_s'} = ncdouble('one') ;
98nc{'theta_b'} = ncdouble('one') ;
99nc{'Tcline'} = ncdouble('one') ;
100nc{'hc'} = ncdouble('one') ;
101nc{'sc_r'} = ncdouble('s_rho') ;
102nc{'Cs_r'} = ncdouble('s_rho') ;
103nc{'scrum_time'} = ncdouble('time') ;
104nc{'u'} = ncdouble('time','s_rho','eta_u','xi_u') ;
105nc{'v'} = ncdouble('time','s_rho','eta_v','xi_v') ;
106nc{'ubar'} = ncdouble('time','eta_u','xi_u') ;
107nc{'vbar'} = ncdouble('time','eta_v','xi_v') ;
108nc{'zeta'} = ncdouble('time','eta_rho','xi_rho') ;
109nc{'temp'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
110nc{'salt'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
111%
112%  Create attributes
113%
114nc{'tstart'}.long_name = ncchar('start processing day');
115nc{'tstart'}.long_name = 'start processing day';
116nc{'tstart'}.units = ncchar('day');
117nc{'tstart'}.units = 'day';
118%
119nc{'tend'}.long_name = ncchar('end processing day');
120nc{'tend'}.long_name = 'end processing day';
121nc{'tend'}.units = ncchar('day');
122nc{'tend'}.units = 'day';
123%
124nc{'theta_s'}.long_name = ncchar('S-coordinate surface control parameter');
125nc{'theta_s'}.long_name = 'S-coordinate surface control parameter';
126nc{'theta_s'}.units = ncchar('nondimensional');
127nc{'theta_s'}.units = 'nondimensional';
128%
129nc{'theta_b'}.long_name = ncchar('S-coordinate bottom control parameter');
130nc{'theta_b'}.long_name = 'S-coordinate bottom control parameter';
131nc{'theta_b'}.units = ncchar('nondimensional');
132nc{'theta_b'}.units = 'nondimensional';
133%
134nc{'Tcline'}.long_name = ncchar('S-coordinate surface/bottom layer width');
135nc{'Tcline'}.long_name = 'S-coordinate surface/bottom layer width';
136nc{'Tcline'}.units = ncchar('meter');
137nc{'Tcline'}.units = 'meter';
138%
139nc{'hc'}.long_name = ncchar('S-coordinate parameter, critical depth');
140nc{'hc'}.long_name = 'S-coordinate parameter, critical depth';
141nc{'hc'}.units = ncchar('meter');
142nc{'hc'}.units = 'meter';
143%
144nc{'sc_r'}.long_name = ncchar('S-coordinate at RHO-points');
145nc{'sc_r'}.long_name = 'S-coordinate at RHO-points';
146nc{'sc_r'}.units = ncchar('nondimensional');
147nc{'sc_r'}.units = 'nondimensional';
148nc{'sc_r'}.valid_min = -1;
149nc{'sc_r'}.valid_max = 0;
150%
151nc{'Cs_r'}.long_name = ncchar('S-coordinate stretching curves at RHO-points');
152nc{'Cs_r'}.long_name = 'S-coordinate stretching curves at RHO-points';
153nc{'Cs_r'}.units = ncchar('nondimensional');
154nc{'Cs_r'}.units = 'nondimensional';
155nc{'Cs_r'}.valid_min = -1;
156nc{'Cs_r'}.valid_max = 0;
157%
158nc{'scrum_time'}.long_name = ncchar('time since initialization');
159nc{'scrum_time'}.long_name = 'time since initialization';
160nc{'scrum_time'}.units = ncchar('second');
161nc{'scrum_time'}.units = 'second';
162%
163nc{'u'}.long_name = ncchar('u-momentum component');
164nc{'u'}.long_name = 'u-momentum component';
165nc{'u'}.units = ncchar('meter second-1');
166nc{'u'}.units = 'meter second-1';
167%
168nc{'v'}.long_name = ncchar('v-momentum component');
169nc{'v'}.long_name = 'v-momentum component';
170nc{'v'}.units = ncchar('meter second-1');
171nc{'v'}.units = 'meter second-1';
172%
173nc{'ubar'}.long_name = ncchar('vertically integrated u-momentum component');
174nc{'ubar'}.long_name = 'vertically integrated u-momentum component';
175nc{'ubar'}.units = ncchar('meter second-1');
176nc{'ubar'}.units = 'meter second-1';
177%
178nc{'vbar'}.long_name = ncchar('vertically integrated v-momentum component');
179nc{'vbar'}.long_name = 'vertically integrated v-momentum component';
180nc{'vbar'}.units = ncchar('meter second-1');
181nc{'vbar'}.units = 'meter second-1';
182%
183nc{'zeta'}.long_name = ncchar('free-surface');
184nc{'zeta'}.long_name = 'free-surface';
185nc{'zeta'}.units = ncchar('meter');
186nc{'zeta'}.units = 'meter';
187%
188nc{'temp'}.long_name = ncchar('potential temperature');
189nc{'temp'}.long_name = 'potential temperature';
190nc{'temp'}.units = ncchar('Celsius');
191nc{'temp'}.units = 'Celsius';
192%
193nc{'salt'}.long_name = ncchar('salinity');
194nc{'salt'}.long_name = 'salinity';
195nc{'salt'}.units = ncchar('PSU');
196nc{'salt'}.units = 'PSU';
197%
198% Create global attributes
199%
200nc.title = ncchar(title);
201nc.title = title;
202nc.date = ncchar(date);
203nc.date = date;
204nc.clim_file = ncchar(inifile);
205nc.clim_file = inifile;
206nc.grd_file = ncchar(gridfile);
207nc.grd_file = gridfile;
208nc.type = ncchar(type);
209nc.type = type;
210nc.history = ncchar(history);
211nc.history = history;
212%
213% Leave define mode
214%
215result = endef(nc);
216%
217% Compute S coordinates
218%
219cff1=1./sinh(theta_s);
220cff2=0.5/tanh(0.5*theta_s);
221sc=((1:N)-N-0.5)/N;
222Cs=(1.-theta_b)*cff1*sinh(theta_s*sc)...
223    +theta_b*(cff2*tanh(theta_s*(sc+0.5))-0.5);
224%
225% Write variables
226%
227nc{'tstart'}(:) =  time;
228nc{'tend'}(:) =  time;
229nc{'theta_s'}(:) =  theta_s;
230nc{'theta_b'}(:) =  theta_b;
231nc{'Tcline'}(:) =  hc;
232nc{'hc'}(:) =  hc;
233nc{'sc_r'}(:) =  sc;
234nc{'Cs_r'}(:) =  Cs;
235nc{'scrum_time'}(1) =  time*24*3600;
236nc{'u'}(:) =  0;
237nc{'v'}(:) =  0;
238nc{'zeta'}(:) =  0;
239nc{'ubar'}(:) =  0;
240nc{'vbar'}(:) =  0;
241nc{'temp'}(:) =  0;
242nc{'salt'}(:) =  0;
243%
244% Synchronize on disk
245%
246close(nc);
247return
248
249
Note: See TracBrowser for help on using the repository browser.