1 | function create_forcing(frcname,grdname,title,smst,... |
---|
2 | shft,swft,srft,sstt,ssst,smsc,... |
---|
3 | shfc,swfc,srfc,sstc,sssc) |
---|
4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
5 | % |
---|
6 | % Create an empty netcdf forcing file |
---|
7 | % frcname: name of the forcing file |
---|
8 | % grdname: name of the grid file |
---|
9 | % title: title in the netcdf file |
---|
10 | % |
---|
11 | % Further Information: |
---|
12 | % http://www.brest.ird.fr/Roms_tools/ |
---|
13 | % |
---|
14 | % This file is part of ROMSTOOLS |
---|
15 | % |
---|
16 | % ROMSTOOLS is free software; you can redistribute it and/or modify |
---|
17 | % it under the terms of the GNU General Public License as published |
---|
18 | % by the Free Software Foundation; either version 2 of the License, |
---|
19 | % or (at your option) any later version. |
---|
20 | % |
---|
21 | % ROMSTOOLS is distributed in the hope that it will be useful, but |
---|
22 | % WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | % GNU General Public License for more details. |
---|
25 | % |
---|
26 | % You should have received a copy of the GNU General Public License |
---|
27 | % along with this program; if not, write to the Free Software |
---|
28 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
29 | % MA 02111-1307 USA |
---|
30 | % |
---|
31 | % Copyright (c) 2001-2006 by Pierrick Penven |
---|
32 | % e-mail:Pierrick.Penven@ird.fr |
---|
33 | % |
---|
34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
35 | nc=netcdf(grdname); |
---|
36 | L=length(nc('xi_psi')); |
---|
37 | M=length(nc('eta_psi')); |
---|
38 | result=close(nc); |
---|
39 | Lp=L+1; |
---|
40 | Mp=M+1; |
---|
41 | |
---|
42 | nw = netcdf(frcname, 'clobber'); |
---|
43 | result = redef(nw); |
---|
44 | |
---|
45 | % |
---|
46 | % Create dimensions |
---|
47 | % |
---|
48 | |
---|
49 | nw('xi_u') = L; |
---|
50 | nw('eta_u') = Mp; |
---|
51 | nw('xi_v') = Lp; |
---|
52 | nw('eta_v') = M; |
---|
53 | nw('xi_rho') = Lp; |
---|
54 | nw('eta_rho') = Mp; |
---|
55 | nw('xi_psi') = L; |
---|
56 | nw('eta_psi') = M; |
---|
57 | nw('sms_time') = length(smst); |
---|
58 | nw('shf_time') = length(shft); |
---|
59 | nw('swf_time') = length(swft); |
---|
60 | nw('sst_time') = length(sstt); |
---|
61 | nw('srf_time') = length(srft); |
---|
62 | nw('sss_time') = length(ssst); |
---|
63 | % |
---|
64 | % Create variables and attributes |
---|
65 | % |
---|
66 | nw{'sms_time'} = ncdouble('sms_time'); |
---|
67 | nw{'sms_time'}.long_name = ncchar('surface momentum stress time'); |
---|
68 | nw{'sms_time'}.long_name = 'surface momentum stress time'; |
---|
69 | nw{'sms_time'}.units = ncchar('days'); |
---|
70 | nw{'sms_time'}.units = 'days'; |
---|
71 | nw{'sms_time'}.cycle_length = smsc; |
---|
72 | |
---|
73 | nw{'shf_time'} = ncdouble('shf_time'); |
---|
74 | nw{'shf_time'}.long_name = ncchar('surface heat flux time'); |
---|
75 | nw{'shf_time'}.long_name = 'surface heat flux time'; |
---|
76 | nw{'shf_time'}.units = ncchar('days'); |
---|
77 | nw{'shf_time'}.units = 'days'; |
---|
78 | nw{'shf_time'}.cycle_length =shfc ; |
---|
79 | |
---|
80 | nw{'swf_time'} = ncdouble('swf_time'); |
---|
81 | nw{'swf_time'}.long_name = ncchar('surface freshwater flux time'); |
---|
82 | nw{'swf_time'}.long_name = 'surface freshwater flux time'; |
---|
83 | nw{'swf_time'}.units = ncchar('days'); |
---|
84 | nw{'swf_time'}.units = 'days'; |
---|
85 | nw{'swf_time'}.cycle_length = swfc; |
---|
86 | |
---|
87 | |
---|
88 | nw{'sst_time'} = ncdouble('sst_time'); |
---|
89 | nw{'sst_time'}.long_name = ncchar('sea surface temperature time'); |
---|
90 | nw{'sst_time'}.long_name = 'sea surface temperature time'; |
---|
91 | nw{'sst_time'}.units = ncchar('days'); |
---|
92 | nw{'sst_time'}.units = 'days'; |
---|
93 | nw{'sst_time'}.cycle_length = sstc; |
---|
94 | |
---|
95 | nw{'sss_time'} = ncdouble('sss_time'); |
---|
96 | nw{'sss_time'}.long_name = ncchar('sea surface salinity time'); |
---|
97 | nw{'sss_time'}.long_name = 'sea surface salinity time'; |
---|
98 | nw{'sss_time'}.units = ncchar('days'); |
---|
99 | nw{'sss_time'}.units = 'days'; |
---|
100 | nw{'sss_time'}.cycle_length = sssc; |
---|
101 | |
---|
102 | nw{'srf_time'} = ncdouble('srf_time'); |
---|
103 | nw{'srf_time'}.long_name = ncchar('solar shortwave radiation time'); |
---|
104 | nw{'srf_time'}.long_name = 'solar shortwave radiation time'; |
---|
105 | nw{'srf_time'}.units = ncchar('days'); |
---|
106 | nw{'srf_time'}.units = 'days'; |
---|
107 | nw{'srf_time'}.cycle_length = srfc; |
---|
108 | |
---|
109 | nw{'sustr'} = ncdouble('sms_time', 'eta_u', 'xi_u'); |
---|
110 | nw{'sustr'}.long_name = ncchar('surface u-momentum stress'); |
---|
111 | nw{'sustr'}.long_name = 'surface u-momentum stress'; |
---|
112 | nw{'sustr'}.units = ncchar('Newton meter-2'); |
---|
113 | nw{'sustr'}.units = 'Newton meter-2'; |
---|
114 | |
---|
115 | nw{'svstr'} = ncdouble('sms_time', 'eta_v', 'xi_v'); |
---|
116 | nw{'svstr'}.long_name = ncchar('surface v-momentum stress'); |
---|
117 | nw{'svstr'}.long_name = 'surface v-momentum stress'; |
---|
118 | nw{'svstr'}.units = ncchar('Newton meter-2'); |
---|
119 | nw{'svstr'}.units = 'Newton meter-2'; |
---|
120 | |
---|
121 | nw{'shflux'} = ncdouble('shf_time', 'eta_rho', 'xi_rho'); |
---|
122 | nw{'shflux'}.long_name = ncchar('surface net heat flux'); |
---|
123 | nw{'shflux'}.long_name = 'surface net heat flux'; |
---|
124 | nw{'shflux'}.units = ncchar('Watts meter-2'); |
---|
125 | nw{'shflux'}.units = 'Watts meter-2'; |
---|
126 | |
---|
127 | nw{'swflux'} = ncdouble('swf_time', 'eta_rho', 'xi_rho'); |
---|
128 | nw{'swflux'}.long_name = ncchar('surface freshwater flux (E-P)'); |
---|
129 | nw{'swflux'}.long_name = 'surface freshwater flux (E-P)'; |
---|
130 | nw{'swflux'}.units = ncchar('centimeter day-1'); |
---|
131 | nw{'swflux'}.units = 'centimeter day-1'; |
---|
132 | nw{'swflux'}.positive = ncchar('net evaporation'); |
---|
133 | nw{'swflux'}.positive = 'net evaporation'; |
---|
134 | nw{'swflux'}.negative = ncchar('net precipitation'); |
---|
135 | nw{'swflux'}.negative = 'net precipitation'; |
---|
136 | |
---|
137 | nw{'SST'} = ncdouble('sst_time', 'eta_rho', 'xi_rho'); |
---|
138 | nw{'SST'}.long_name = ncchar('sea surface temperature'); |
---|
139 | nw{'SST'}.long_name = 'sea surface temperature'; |
---|
140 | nw{'SST'}.units = ncchar('Celsius'); |
---|
141 | nw{'SST'}.units = 'Celsius'; |
---|
142 | |
---|
143 | nw{'SSS'} = ncdouble('sss_time', 'eta_rho', 'xi_rho'); |
---|
144 | nw{'SSS'}.long_name = ncchar('sea surface salinity'); |
---|
145 | nw{'SSS'}.long_name = 'sea surface salinity'; |
---|
146 | nw{'SSS'}.units = ncchar('PSU'); |
---|
147 | nw{'SSS'}.units = 'PSU'; |
---|
148 | |
---|
149 | nw{'dQdSST'} = ncdouble('sst_time', 'eta_rho', 'xi_rho'); |
---|
150 | nw{'dQdSST'}.long_name = ncchar('surface net heat flux sensitivity to SST'); |
---|
151 | nw{'dQdSST'}.long_name = 'surface net heat flux sensitivity to SST'; |
---|
152 | nw{'dQdSST'}.units = ncchar('Watts meter-2 Celsius-1'); |
---|
153 | nw{'dQdSST'}.units = 'Watts meter-2 Celsius-1'; |
---|
154 | |
---|
155 | nw{'swrad'} = ncdouble('srf_time', 'eta_rho', 'xi_rho'); |
---|
156 | nw{'swrad'}.long_name = ncchar('solar shortwave radiation'); |
---|
157 | nw{'swrad'}.long_name = 'solar shortwave radiation'; |
---|
158 | nw{'swrad'}.units = ncchar('Watts meter-2'); |
---|
159 | nw{'swrad'}.units = 'Watts meter-2'; |
---|
160 | nw{'swrad'}.positive = ncchar('downward flux, heating'); |
---|
161 | nw{'swrad'}.positive = 'downward flux, heating'; |
---|
162 | nw{'swrad'}.negative = ncchar('upward flux, cooling'); |
---|
163 | nw{'swrad'}.negative = 'upward flux, cooling'; |
---|
164 | |
---|
165 | result = endef(nw); |
---|
166 | |
---|
167 | % |
---|
168 | % Create global attributes |
---|
169 | % |
---|
170 | |
---|
171 | nw.title = ncchar(title); |
---|
172 | nw.title = title; |
---|
173 | nw.date = ncchar(date); |
---|
174 | nw.date = date; |
---|
175 | nw.grd_file = ncchar(grdname); |
---|
176 | nw.grd_file = grdname; |
---|
177 | nw.type = ncchar('ROMS forcing file'); |
---|
178 | nw.type = 'ROMS forcing file'; |
---|
179 | |
---|
180 | % |
---|
181 | % Write time variables |
---|
182 | % |
---|
183 | |
---|
184 | nw{'sms_time'}(:) = smst; |
---|
185 | nw{'shf_time'}(:) = shft; |
---|
186 | nw{'swf_time'}(:) = swft; |
---|
187 | nw{'sst_time'}(:) = sstt; |
---|
188 | nw{'srf_time'}(:) = srft; |
---|
189 | nw{'sss_time'}(:) = ssst; |
---|
190 | |
---|
191 | close(nw); |
---|