source: Roms_tools/Preprocessing_tools/create_oafile.m @ 2

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

import Roms_Agrif

File size: 8.9 KB
Line 
1function create_oafile(oaname,grdname,title,Z,...
2                       time,cycle,clobber);
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5%  function nc=create_oafile(oaname,grdname,title,Z,...
6%                       time,cycle,clobber);
7%
8%   This function create the header of a Netcdf OA
9%   file. ie an intermediate file on a Z-grid.
10%
11%   Input:
12%
13%   oaname       Netcdf OA file name (character string).
14%   grdname      Netcdf grid file name (character string).
15%   Z            Vertical levels.(Vector) 
16%   time         OA time.(Vector)
17%   clobber      Switch to allow or not writing over an existing
18%                file.(character string)
19%
20%   Output
21%
22%   nc       Output netcdf object.
23%
24%  Further Information: 
25%  http://www.brest.ird.fr/Roms_tools/
26
27%  This file is part of ROMSTOOLS
28%
29%  ROMSTOOLS is free software; you can redistribute it and/or modify
30%  it under the terms of the GNU General Public License as published
31%  by the Free Software Foundation; either version 2 of the License,
32%  or (at your option) any later version.
33%
34%  ROMSTOOLS is distributed in the hope that it will be useful, but
35%  WITHOUT ANY WARRANTY; without even the implied warranty of
36%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37%  GNU General Public License for more details.
38%
39%  You should have received a copy of the GNU General Public License
40%  along with this program; if not, write to the Free Software
41%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
42%  MA  02111-1307  USA
43%
44%  Copyright (c) 2001-2006 by Pierrick Penven
45%  e-mail:Pierrick.Penven@ird.fr 
46%
47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48disp(' ')
49disp([' Creating the file : ',oaname])
50disp(' ')
51%
52%  Read the grid file
53%
54nc = netcdf(grdname, 'nowrite');
55lonr=nc{'lon_rho'}(:);
56latr=nc{'lat_rho'}(:);
57lonu=nc{'lon_u'}(:);
58latu=nc{'lat_u'}(:);
59lonv=nc{'lon_v'}(:);
60latv=nc{'lat_v'}(:);
61status=close(nc);
62[Mp,Lp]=size(lonr);
63L=Lp-1;
64M=Mp-1;
65%
66%  Create the climatology file
67%
68type = 'OA file' ;
69history = 'ROMS' ;
70nc = netcdf(oaname,clobber);
71result = redef(nc);
72%
73%  Create dimensions
74%
75nc('xi_rho') = Lp;
76nc('eta_rho') = Mp;
77nc('xi_u') = L;
78nc('eta_v') = M;
79nc('Z') = length(Z);
80nc('tracer') = 2;
81nc('tclm_time') = length(time);
82nc('sclm_time') = length(time);
83nc('uclm_time') = length(time);
84nc('vclm_time') = length(time);
85nc('v2d_time')  = length(time);
86nc('v3d_time')  = length(time);
87nc('ssh_time')  = length(time);
88nc('zeta_time') = length(time);
89nc('one') = 1;
90%
91%  Create variables
92%
93nc{'lon_rho'} = ncdouble('eta_rho','xi_rho') ;
94nc{'lat_rho'} = ncdouble('eta_rho','xi_rho') ;
95nc{'lon_u'} = ncdouble('eta_rho','xi_u') ;
96nc{'lat_u'} = ncdouble('eta_rho','xi_u') ;
97nc{'lon_v'} = ncdouble('eta_v','xi_rho') ;
98nc{'lat_v'} = ncdouble('eta_v','xi_rho') ;
99nc{'Z'} = ncdouble('Z') ;
100nc{'tclm_time'} = ncdouble('tclm_time') ;
101nc{'sclm_time'} = ncdouble('sclm_time') ;
102nc{'uclm_time'} = ncdouble('uclm_time') ;
103nc{'vclm_time'} = ncdouble('vclm_time') ;
104nc{'v2d_time'} = ncdouble('v2d_time') ;
105nc{'v3d_time'} = ncdouble('v3d_time') ;
106nc{'ssh_time'} = ncdouble('ssh_time') ;
107nc{'zeta_time'} = ncdouble('zeta_time') ;
108nc{'temp'} = ncdouble('tclm_time','Z','eta_rho','xi_rho') ;
109nc{'salt'} = ncdouble('sclm_time','Z','eta_rho','xi_rho') ;
110nc{'u'} = ncdouble('uclm_time','Z','eta_rho','xi_u') ;
111nc{'v'} = ncdouble('vclm_time','Z','eta_v','xi_rho') ;
112nc{'ubar'} = ncdouble('uclm_time','eta_rho','xi_u') ;
113nc{'vbar'} = ncdouble('vclm_time','eta_v','xi_rho') ;
114nc{'SSH'} = ncdouble('ssh_time','eta_rho','xi_rho') ;
115nc{'zeta'} = ncdouble('zeta_time','eta_rho','xi_rho') ;
116%
117%  Create attributes
118%
119nc{'lon_rho'}.long_name = ncchar('longitude of RHO-points');
120nc{'lon_rho'}.long_name = 'longitude of RHO-points';
121nc{'lon_rho'}.units = ncchar('degree_east');
122nc{'lon_rho'}.units = 'degree_east';
123%
124nc{'lat_rho'}.latg_name = ncchar('latitude of RHO-points');
125nc{'lat_rho'}.latg_name = 'latitude of RHO-points';
126nc{'lat_rho'}.units = ncchar('degree_north');
127nc{'lat_rho'}.units = 'degree_north';
128%
129nc{'lon_u'}.long_name = ncchar('longitude of U-points');
130nc{'lon_u'}.long_name = 'longitude of U-points';
131nc{'lon_u'}.units = ncchar('degree_east');
132nc{'lon_u'}.units = 'degree_east';
133%
134nc{'lat_u'}.latg_name = ncchar('latitude of U-points');
135nc{'lat_u'}.latg_name = 'latitude of U-points';
136nc{'lat_u'}.units = ncchar('degree_north');
137nc{'lat_u'}.units = 'degree_north';
138%
139nc{'lon_v'}.long_name = ncchar('longitude of V-points');
140nc{'lon_v'}.long_name = 'longitude of V-points';
141nc{'lon_v'}.units = ncchar('degree_east');
142nc{'lon_v'}.units = 'degree_east';
143%
144nc{'lat_v'}.latg_name = ncchar('latitude of V-points');
145nc{'lat_v'}.latg_name = 'latitude of V-points';
146nc{'lat_v'}.units = ncchar('degree_north');
147nc{'lat_v'}.units = 'degree_north';
148%
149nc{'Z'}.long_name = ncchar('Depth');
150nc{'Z'}.long_name = 'Depth';
151nc{'Z'}.units = ncchar('m');
152nc{'Z'}.units = 'm';
153%
154nc{'tclm_time'}.long_name = ncchar('time for temperature climatology');
155nc{'tclm_time'}.long_name = 'time for temperature climatology';
156nc{'tclm_time'}.units = ncchar('day');
157nc{'tclm_time'}.units = 'day';
158nc{'tclm_time'}.cycle_length = cycle;
159%
160nc{'sclm_time'}.long_name = ncchar('time for salinity climatology');
161nc{'sclm_time'}.long_name = 'time for salinity climatology';
162nc{'sclm_time'}.units = ncchar('day');
163nc{'sclm_time'}.units = 'day';
164nc{'sclm_time'}.cycle_length = cycle;
165%
166nc{'uclm_time'}.long_name = ncchar('time for u climatology');
167nc{'uclm_time'}.long_name = 'time for u climatology';
168nc{'uclm_time'}.units = ncchar('day');
169nc{'uclm_time'}.units = 'day';
170nc{'uclm_time'}.cycle_length = cycle;
171%
172nc{'vclm_time'}.long_name = ncchar('time for v climatology');
173nc{'vclm_time'}.long_name = 'time for v climatology';
174nc{'vclm_time'}.units = ncchar('day');
175nc{'vclm_time'}.units = 'day';
176nc{'vclm_time'}.cycle_length = cycle;
177%
178nc{'v2d_time'}.long_name = ncchar('time for 2D velocity climatology');
179nc{'v2d_time'}.long_name = 'time for 2D velocity climatology';
180nc{'v2d_time'}.units = ncchar('day');
181nc{'v2d_time'}.units = 'day';
182nc{'v2d_time'}.cycle_length = cycle;
183%
184nc{'v3d_time'}.long_name = ncchar('time for 3D velocity climatology');
185nc{'v3d_time'}.long_name = 'time for 3D velocity climatology';
186nc{'v3d_time'}.units = ncchar('day');
187nc{'v3d_time'}.units = 'day';
188nc{'v3d_time'}.cycle_length = cycle;
189%
190nc{'ssh_time'}.long_name = ncchar('time for sea surface height');
191nc{'ssh_time'}.long_name = 'time for sea surface height';
192nc{'ssh_time'}.units = ncchar('day');
193nc{'ssh_time'}.units = 'day';
194nc{'ssh_time'}.cycle_length = cycle;
195%
196nc{'zeta_time'}.long_name = ncchar('time for zeta climatology');
197nc{'zeta_time'}.long_name = 'time for zeta climatology';
198nc{'zeta_time'}.units = ncchar('day');
199nc{'zeta_time'}.units = 'day';
200nc{'zeta_time'}.cycle_length = cycle;
201%
202nc{'temp'}.long_name = ncchar('potential temperature');
203nc{'temp'}.long_name = 'potential temperature';
204nc{'temp'}.units = ncchar('Celsius');
205nc{'temp'}.units = 'Celsius';
206%
207nc{'salt'}.long_name = ncchar('salinity');
208nc{'salt'}.long_name = 'salinity';
209nc{'salt'}.units = ncchar('PSU');
210nc{'salt'}.units = 'PSU';
211%
212nc{'u'}.long_name = ncchar('u-momentum component');
213nc{'u'}.long_name = 'u-momentum component';
214nc{'u'}.units = ncchar('meter second-1');
215nc{'u'}.units = 'meter second-1';
216%
217nc{'v'}.long_name = ncchar('v-momentum component');
218nc{'v'}.long_name = 'v-momentum component';
219nc{'v'}.units = ncchar('meter second-1');
220nc{'v'}.units = 'meter second-1';
221%
222nc{'ubar'}.long_name = ncchar('vertically integrated u-momentum component');
223nc{'ubar'}.long_name = 'vertically integrated u-momentum component';
224nc{'ubar'}.units = ncchar('meter second-1');
225nc{'ubar'}.units = 'meter second-1';
226%
227nc{'vbar'}.long_name = ncchar('vertically integrated v-momentum component');
228nc{'vbar'}.long_name = 'vertically integrated v-momentum component';
229nc{'vbar'}.units = ncchar('meter second-1');
230nc{'vbar'}.units = 'meter second-1';
231%
232nc{'SSH'}.long_name = ncchar('sea surface height');
233nc{'SSH'}.long_name = 'sea surface height';
234nc{'SSH'}.units = ncchar('meter');
235nc{'SSH'}.units = 'meter';
236%
237nc{'zeta'}.long_name = ncchar('sea surface height');
238nc{'zeta'}.long_name = 'sea surface height';
239nc{'zeta'}.units = ncchar('meter');
240nc{'zeta'}.units = 'meter';
241%
242% Create global attributes
243%
244nc.title = ncchar(title);
245nc.title = title;
246nc.date = ncchar(date);
247nc.date = date;
248nc.grd_file = ncchar(grdname);
249nc.grd_file = grdname;
250nc.type = ncchar(type);
251nc.type = type;
252nc.history = ncchar(history);
253nc.history = history;
254%
255% Leave define mode
256%
257result = endef(nc);
258%
259% Write variables
260%
261nc{'Z'}(:) =  Z;
262nc{'lon_rho'}(:) =  lonr;
263nc{'lat_rho'}(:) =  latr;
264nc{'lon_u'}(:) =  lonu;
265nc{'lat_u'}(:) =  latu;
266nc{'lon_v'}(:) =  lonv;
267nc{'lat_v'}(:) =  latv;
268nc{'tclm_time'}(:) = time;
269nc{'sclm_time'}(:) = time;
270nc{'uclm_time'}(:) = time;
271nc{'vclm_time'}(:) = time;
272nc{'v2d_time'}(:) =   time;
273nc{'v3d_time'}(:) =   time;
274nc{'ssh_time'}(:) =   time;
275nc{'zeta_time'}(:) = time;
276nc{'u'}(:) =  0;
277nc{'v'}(:) =  0;
278nc{'ubar'}(:) =  0;
279nc{'vbar'}(:) =  0;
280nc{'SSH'}(:) =  0;
281nc{'zeta'}(:) =  0;
282nc{'temp'}(:) =  0;
283nc{'salt'}(:) =  0;
284close(nc)
285return
286
287
Note: See TracBrowser for help on using the repository browser.