1 | function 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 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
54 | disp(' ') |
---|
55 | disp([' Creating the file : ',inifile]) |
---|
56 | % |
---|
57 | % Read the grid file |
---|
58 | % |
---|
59 | nc=netcdf(gridfile); |
---|
60 | h=nc{'h'}(:); |
---|
61 | mask=nc{'mask_rho'}(:); |
---|
62 | close(nc); |
---|
63 | hmin=min(min(h(mask==1))); |
---|
64 | if hc > hmin |
---|
65 | error([' hc (',num2str(hc),' m) > hmin (',num2str(hmin),' m)']) |
---|
66 | end |
---|
67 | [Mp,Lp]=size(h); |
---|
68 | L=Lp-1; |
---|
69 | M=Mp-1; |
---|
70 | Np=N+1; |
---|
71 | % |
---|
72 | % Create the initial file |
---|
73 | % |
---|
74 | type = 'INITIAL file' ; |
---|
75 | history = 'ROMS' ; |
---|
76 | nc = netcdf(inifile,clobber); |
---|
77 | result = redef(nc); |
---|
78 | % |
---|
79 | % Create dimensions |
---|
80 | % |
---|
81 | nc('xi_u') = L; |
---|
82 | nc('xi_v') = Lp; |
---|
83 | nc('xi_rho') = Lp; |
---|
84 | nc('eta_u') = Mp; |
---|
85 | nc('eta_v') = M; |
---|
86 | nc('eta_rho') = Mp; |
---|
87 | nc('s_rho') = N; |
---|
88 | nc('s_w') = Np; |
---|
89 | nc('tracer') = 2; |
---|
90 | nc('time') = 0; |
---|
91 | nc('one') = 1; |
---|
92 | % |
---|
93 | % Create variables |
---|
94 | % |
---|
95 | nc{'tstart'} = ncdouble('one') ; |
---|
96 | nc{'tend'} = ncdouble('one') ; |
---|
97 | nc{'theta_s'} = ncdouble('one') ; |
---|
98 | nc{'theta_b'} = ncdouble('one') ; |
---|
99 | nc{'Tcline'} = ncdouble('one') ; |
---|
100 | nc{'hc'} = ncdouble('one') ; |
---|
101 | nc{'sc_r'} = ncdouble('s_rho') ; |
---|
102 | nc{'Cs_r'} = ncdouble('s_rho') ; |
---|
103 | nc{'scrum_time'} = ncdouble('time') ; |
---|
104 | nc{'u'} = ncdouble('time','s_rho','eta_u','xi_u') ; |
---|
105 | nc{'v'} = ncdouble('time','s_rho','eta_v','xi_v') ; |
---|
106 | nc{'ubar'} = ncdouble('time','eta_u','xi_u') ; |
---|
107 | nc{'vbar'} = ncdouble('time','eta_v','xi_v') ; |
---|
108 | nc{'zeta'} = ncdouble('time','eta_rho','xi_rho') ; |
---|
109 | nc{'temp'} = ncdouble('time','s_rho','eta_rho','xi_rho') ; |
---|
110 | nc{'salt'} = ncdouble('time','s_rho','eta_rho','xi_rho') ; |
---|
111 | % |
---|
112 | % Create attributes |
---|
113 | % |
---|
114 | nc{'tstart'}.long_name = ncchar('start processing day'); |
---|
115 | nc{'tstart'}.long_name = 'start processing day'; |
---|
116 | nc{'tstart'}.units = ncchar('day'); |
---|
117 | nc{'tstart'}.units = 'day'; |
---|
118 | % |
---|
119 | nc{'tend'}.long_name = ncchar('end processing day'); |
---|
120 | nc{'tend'}.long_name = 'end processing day'; |
---|
121 | nc{'tend'}.units = ncchar('day'); |
---|
122 | nc{'tend'}.units = 'day'; |
---|
123 | % |
---|
124 | nc{'theta_s'}.long_name = ncchar('S-coordinate surface control parameter'); |
---|
125 | nc{'theta_s'}.long_name = 'S-coordinate surface control parameter'; |
---|
126 | nc{'theta_s'}.units = ncchar('nondimensional'); |
---|
127 | nc{'theta_s'}.units = 'nondimensional'; |
---|
128 | % |
---|
129 | nc{'theta_b'}.long_name = ncchar('S-coordinate bottom control parameter'); |
---|
130 | nc{'theta_b'}.long_name = 'S-coordinate bottom control parameter'; |
---|
131 | nc{'theta_b'}.units = ncchar('nondimensional'); |
---|
132 | nc{'theta_b'}.units = 'nondimensional'; |
---|
133 | % |
---|
134 | nc{'Tcline'}.long_name = ncchar('S-coordinate surface/bottom layer width'); |
---|
135 | nc{'Tcline'}.long_name = 'S-coordinate surface/bottom layer width'; |
---|
136 | nc{'Tcline'}.units = ncchar('meter'); |
---|
137 | nc{'Tcline'}.units = 'meter'; |
---|
138 | % |
---|
139 | nc{'hc'}.long_name = ncchar('S-coordinate parameter, critical depth'); |
---|
140 | nc{'hc'}.long_name = 'S-coordinate parameter, critical depth'; |
---|
141 | nc{'hc'}.units = ncchar('meter'); |
---|
142 | nc{'hc'}.units = 'meter'; |
---|
143 | % |
---|
144 | nc{'sc_r'}.long_name = ncchar('S-coordinate at RHO-points'); |
---|
145 | nc{'sc_r'}.long_name = 'S-coordinate at RHO-points'; |
---|
146 | nc{'sc_r'}.units = ncchar('nondimensional'); |
---|
147 | nc{'sc_r'}.units = 'nondimensional'; |
---|
148 | nc{'sc_r'}.valid_min = -1; |
---|
149 | nc{'sc_r'}.valid_max = 0; |
---|
150 | % |
---|
151 | nc{'Cs_r'}.long_name = ncchar('S-coordinate stretching curves at RHO-points'); |
---|
152 | nc{'Cs_r'}.long_name = 'S-coordinate stretching curves at RHO-points'; |
---|
153 | nc{'Cs_r'}.units = ncchar('nondimensional'); |
---|
154 | nc{'Cs_r'}.units = 'nondimensional'; |
---|
155 | nc{'Cs_r'}.valid_min = -1; |
---|
156 | nc{'Cs_r'}.valid_max = 0; |
---|
157 | % |
---|
158 | nc{'scrum_time'}.long_name = ncchar('time since initialization'); |
---|
159 | nc{'scrum_time'}.long_name = 'time since initialization'; |
---|
160 | nc{'scrum_time'}.units = ncchar('second'); |
---|
161 | nc{'scrum_time'}.units = 'second'; |
---|
162 | % |
---|
163 | nc{'u'}.long_name = ncchar('u-momentum component'); |
---|
164 | nc{'u'}.long_name = 'u-momentum component'; |
---|
165 | nc{'u'}.units = ncchar('meter second-1'); |
---|
166 | nc{'u'}.units = 'meter second-1'; |
---|
167 | % |
---|
168 | nc{'v'}.long_name = ncchar('v-momentum component'); |
---|
169 | nc{'v'}.long_name = 'v-momentum component'; |
---|
170 | nc{'v'}.units = ncchar('meter second-1'); |
---|
171 | nc{'v'}.units = 'meter second-1'; |
---|
172 | % |
---|
173 | nc{'ubar'}.long_name = ncchar('vertically integrated u-momentum component'); |
---|
174 | nc{'ubar'}.long_name = 'vertically integrated u-momentum component'; |
---|
175 | nc{'ubar'}.units = ncchar('meter second-1'); |
---|
176 | nc{'ubar'}.units = 'meter second-1'; |
---|
177 | % |
---|
178 | nc{'vbar'}.long_name = ncchar('vertically integrated v-momentum component'); |
---|
179 | nc{'vbar'}.long_name = 'vertically integrated v-momentum component'; |
---|
180 | nc{'vbar'}.units = ncchar('meter second-1'); |
---|
181 | nc{'vbar'}.units = 'meter second-1'; |
---|
182 | % |
---|
183 | nc{'zeta'}.long_name = ncchar('free-surface'); |
---|
184 | nc{'zeta'}.long_name = 'free-surface'; |
---|
185 | nc{'zeta'}.units = ncchar('meter'); |
---|
186 | nc{'zeta'}.units = 'meter'; |
---|
187 | % |
---|
188 | nc{'temp'}.long_name = ncchar('potential temperature'); |
---|
189 | nc{'temp'}.long_name = 'potential temperature'; |
---|
190 | nc{'temp'}.units = ncchar('Celsius'); |
---|
191 | nc{'temp'}.units = 'Celsius'; |
---|
192 | % |
---|
193 | nc{'salt'}.long_name = ncchar('salinity'); |
---|
194 | nc{'salt'}.long_name = 'salinity'; |
---|
195 | nc{'salt'}.units = ncchar('PSU'); |
---|
196 | nc{'salt'}.units = 'PSU'; |
---|
197 | % |
---|
198 | % Create global attributes |
---|
199 | % |
---|
200 | nc.title = ncchar(title); |
---|
201 | nc.title = title; |
---|
202 | nc.date = ncchar(date); |
---|
203 | nc.date = date; |
---|
204 | nc.clim_file = ncchar(inifile); |
---|
205 | nc.clim_file = inifile; |
---|
206 | nc.grd_file = ncchar(gridfile); |
---|
207 | nc.grd_file = gridfile; |
---|
208 | nc.type = ncchar(type); |
---|
209 | nc.type = type; |
---|
210 | nc.history = ncchar(history); |
---|
211 | nc.history = history; |
---|
212 | % |
---|
213 | % Leave define mode |
---|
214 | % |
---|
215 | result = endef(nc); |
---|
216 | % |
---|
217 | % Compute S coordinates |
---|
218 | % |
---|
219 | cff1=1./sinh(theta_s); |
---|
220 | cff2=0.5/tanh(0.5*theta_s); |
---|
221 | sc=((1:N)-N-0.5)/N; |
---|
222 | Cs=(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 | % |
---|
227 | nc{'tstart'}(:) = time; |
---|
228 | nc{'tend'}(:) = time; |
---|
229 | nc{'theta_s'}(:) = theta_s; |
---|
230 | nc{'theta_b'}(:) = theta_b; |
---|
231 | nc{'Tcline'}(:) = hc; |
---|
232 | nc{'hc'}(:) = hc; |
---|
233 | nc{'sc_r'}(:) = sc; |
---|
234 | nc{'Cs_r'}(:) = Cs; |
---|
235 | nc{'scrum_time'}(1) = time*24*3600; |
---|
236 | nc{'u'}(:) = 0; |
---|
237 | nc{'v'}(:) = 0; |
---|
238 | nc{'zeta'}(:) = 0; |
---|
239 | nc{'ubar'}(:) = 0; |
---|
240 | nc{'vbar'}(:) = 0; |
---|
241 | nc{'temp'}(:) = 0; |
---|
242 | nc{'salt'}(:) = 0; |
---|
243 | % |
---|
244 | % Synchronize on disk |
---|
245 | % |
---|
246 | close(nc); |
---|
247 | return |
---|
248 | |
---|
249 | |
---|