1 | !> @file data_output_spectra.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of the PALM model system. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
6 | ! terms of the GNU General Public License as published by the Free Software |
---|
7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
8 | ! version. |
---|
9 | ! |
---|
10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
13 | ! |
---|
14 | ! You should have received a copy of the GNU General Public License along with |
---|
15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | ! |
---|
17 | ! Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ------------------ |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: data_output_spectra.f90 3421 2018-10-24 18:39:32Z suehring $ |
---|
27 | ! Renamed output variables |
---|
28 | ! |
---|
29 | ! 3419 2018-10-24 17:27:31Z gronemeier |
---|
30 | ! Modularization of all bulk cloud physics code components |
---|
31 | ! |
---|
32 | ! 3241 2018-09-12 15:02:00Z raasch |
---|
33 | ! unused variables removed |
---|
34 | ! |
---|
35 | ! 2718 2018-01-02 08:49:38Z maronga |
---|
36 | ! Corrected "Former revisions" section |
---|
37 | ! |
---|
38 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
39 | ! Change in file header (GPL part) |
---|
40 | ! |
---|
41 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
42 | ! |
---|
43 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
44 | ! Forced header and separation lines into 80 columns |
---|
45 | ! |
---|
46 | ! 1960 2016-07-12 16:34:24Z suehring |
---|
47 | ! Additional default spectra for passive scalar |
---|
48 | ! |
---|
49 | ! 1833 2016-04-07 14:23:03Z raasch |
---|
50 | ! spectrum renamed spectra_mod, spectra related variables moved to spectra_mod, |
---|
51 | ! routines data_output_spectra_x/y removed |
---|
52 | ! |
---|
53 | ! 1786 2016-03-08 05:49:27Z raasch |
---|
54 | ! cpp-directives for spectra removed, immediate return if no spectra levels are |
---|
55 | ! given |
---|
56 | ! |
---|
57 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
58 | ! name change of netcdf routines and module + related changes |
---|
59 | ! |
---|
60 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
61 | ! Code annotations made doxygen readable |
---|
62 | ! |
---|
63 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
64 | ! REAL constants provided with KIND-attribute |
---|
65 | ! |
---|
66 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
67 | ! -netcdf output queries |
---|
68 | ! |
---|
69 | ! 1324 2014-03-21 09:13:16Z suehring |
---|
70 | ! Bugfix: module statistics and module spectrum added, missing variables in ONLY |
---|
71 | ! arguments added |
---|
72 | ! |
---|
73 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
74 | ! REAL functions provided with KIND-attribute |
---|
75 | ! |
---|
76 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
77 | ! ONLY-attribute added to USE-statements, |
---|
78 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
79 | ! kinds are defined in new module kinds, |
---|
80 | ! revision history before 2012 removed, |
---|
81 | ! comment fields (!:) to be used for variable explanations added to |
---|
82 | ! all variable declaration statements |
---|
83 | ! |
---|
84 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
85 | ! module interfaces removed |
---|
86 | ! |
---|
87 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
88 | ! code put under GPL (PALM 3.9) |
---|
89 | ! |
---|
90 | ! 964 2012-07-26 09:14:24Z raasch |
---|
91 | ! code for profil-output removed |
---|
92 | ! |
---|
93 | ! Revision 1.1 2001/01/05 15:14:20 raasch |
---|
94 | ! Initial revision |
---|
95 | ! |
---|
96 | ! |
---|
97 | ! Description: |
---|
98 | ! ------------ |
---|
99 | !> Writing spectra data on file, using a special format which allows |
---|
100 | !> plotting of these data with PROFIL-graphic-software |
---|
101 | !------------------------------------------------------------------------------! |
---|
102 | SUBROUTINE data_output_spectra |
---|
103 | |
---|
104 | #if defined( __netcdf ) |
---|
105 | USE control_parameters, & |
---|
106 | ONLY: message_string, time_since_reference_point |
---|
107 | |
---|
108 | USE cpulog, & |
---|
109 | ONLY: cpu_log, log_point |
---|
110 | |
---|
111 | USE kinds |
---|
112 | |
---|
113 | USE NETCDF |
---|
114 | |
---|
115 | USE netcdf_interface, & |
---|
116 | ONLY: id_set_sp, id_var_time_sp, nc_stat, netcdf_handle_error |
---|
117 | |
---|
118 | USE pegrid |
---|
119 | |
---|
120 | USE spectra_mod, & |
---|
121 | ONLY: average_count_sp, averaging_interval_sp, comp_spectra_level, & |
---|
122 | data_output_sp, dosp_time_count, spectra_direction, spectrum_x, & |
---|
123 | spectrum_y |
---|
124 | |
---|
125 | |
---|
126 | IMPLICIT NONE |
---|
127 | |
---|
128 | INTEGER(iwp) :: m !< |
---|
129 | INTEGER(iwp) :: pr !< |
---|
130 | |
---|
131 | CALL cpu_log( log_point(31), 'data_output_spectra', 'start' ) |
---|
132 | |
---|
133 | ! |
---|
134 | !-- Check if user gave any levels for spectra to be calculated |
---|
135 | IF ( comp_spectra_level(1) == 999999 ) RETURN |
---|
136 | |
---|
137 | ! |
---|
138 | !-- Output is only performed on PE0 |
---|
139 | IF ( myid == 0 ) THEN |
---|
140 | |
---|
141 | ! |
---|
142 | !-- Open file for spectra output in NetCDF format |
---|
143 | CALL check_open( 107 ) |
---|
144 | |
---|
145 | ! |
---|
146 | !-- Increment the counter for number of output times |
---|
147 | dosp_time_count = dosp_time_count + 1 |
---|
148 | |
---|
149 | ! |
---|
150 | !-- Update the spectra time axis |
---|
151 | nc_stat = NF90_PUT_VAR( id_set_sp, id_var_time_sp, & |
---|
152 | (/ time_since_reference_point /), & |
---|
153 | start = (/ dosp_time_count /), count = (/ 1 /) ) |
---|
154 | CALL netcdf_handle_error( 'data_output_spectra', 47 ) |
---|
155 | |
---|
156 | ! |
---|
157 | !-- If necessary, calculate time average and reset average counter |
---|
158 | IF ( average_count_sp == 0 ) THEN |
---|
159 | message_string = 'no spectra data available' |
---|
160 | CALL message( 'data_output_spectra', 'PA0186', 0, 0, 0, 6, 0 ) |
---|
161 | ENDIF |
---|
162 | IF ( average_count_sp /= 1 ) THEN |
---|
163 | spectrum_x = spectrum_x / REAL( average_count_sp, KIND=wp ) |
---|
164 | spectrum_y = spectrum_y / REAL( average_count_sp, KIND=wp ) |
---|
165 | average_count_sp = 0 |
---|
166 | ENDIF |
---|
167 | |
---|
168 | ! |
---|
169 | !-- Loop over all spectra defined by the user |
---|
170 | m = 1 |
---|
171 | DO WHILE ( data_output_sp(m) /= ' ' .AND. m <= 10 ) |
---|
172 | |
---|
173 | SELECT CASE ( TRIM( data_output_sp(m) ) ) |
---|
174 | |
---|
175 | CASE ( 'u' ) |
---|
176 | pr = 1 |
---|
177 | |
---|
178 | CASE ( 'v' ) |
---|
179 | pr = 2 |
---|
180 | |
---|
181 | CASE ( 'w' ) |
---|
182 | pr = 3 |
---|
183 | |
---|
184 | CASE ( 'theta' ) |
---|
185 | pr = 4 |
---|
186 | |
---|
187 | CASE ( 'q' ) |
---|
188 | pr = 5 |
---|
189 | |
---|
190 | CASE ( 's' ) |
---|
191 | pr = 6 |
---|
192 | |
---|
193 | CASE DEFAULT |
---|
194 | ! |
---|
195 | !-- The DEFAULT case is reached either if the parameter |
---|
196 | !-- data_output_sp(m) contains a wrong character string or if the |
---|
197 | !-- user has coded a special case in the user interface. There, the |
---|
198 | !-- subroutine user_spectra checks which of these two conditions |
---|
199 | !-- applies. |
---|
200 | CALL user_spectra( 'data_output', m, pr ) |
---|
201 | |
---|
202 | END SELECT |
---|
203 | |
---|
204 | ! |
---|
205 | !-- Output of spectra in NetCDF format |
---|
206 | !-- Output of x-spectra |
---|
207 | IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN |
---|
208 | CALL output_spectra_netcdf( m, 'x' ) |
---|
209 | ENDIF |
---|
210 | ! |
---|
211 | !-- Output of y-spectra |
---|
212 | IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN |
---|
213 | CALL output_spectra_netcdf( m, 'y' ) |
---|
214 | ENDIF |
---|
215 | |
---|
216 | ! |
---|
217 | !-- Increase counter for next spectrum |
---|
218 | m = m + 1 |
---|
219 | |
---|
220 | ENDDO |
---|
221 | |
---|
222 | ! |
---|
223 | !-- Reset spectra values |
---|
224 | spectrum_x = 0.0_wp; spectrum_y = 0.0_wp |
---|
225 | |
---|
226 | ENDIF |
---|
227 | |
---|
228 | CALL cpu_log( log_point(31), 'data_output_spectra', 'stop' ) |
---|
229 | |
---|
230 | #if defined( __parallel ) |
---|
231 | ! CALL MPI_BARRIER( comm2d, ierr ) ! really necessary |
---|
232 | #endif |
---|
233 | |
---|
234 | #endif |
---|
235 | END SUBROUTINE data_output_spectra |
---|
236 | |
---|
237 | |
---|
238 | !------------------------------------------------------------------------------! |
---|
239 | ! Description: |
---|
240 | ! ------------ |
---|
241 | !> @todo Missing subroutine description. |
---|
242 | !------------------------------------------------------------------------------! |
---|
243 | SUBROUTINE output_spectra_netcdf( nsp, direction ) |
---|
244 | #if defined( __netcdf ) |
---|
245 | |
---|
246 | USE basic_constants_and_equations_mod, & |
---|
247 | ONLY: pi |
---|
248 | |
---|
249 | USE grid_variables, & |
---|
250 | ONLY: dx, dy |
---|
251 | |
---|
252 | USE indices, & |
---|
253 | ONLY: nx, ny |
---|
254 | |
---|
255 | USE kinds |
---|
256 | |
---|
257 | USE NETCDF |
---|
258 | |
---|
259 | USE netcdf_interface, & |
---|
260 | ONLY: id_set_sp, id_var_dospx, id_var_dospy, nc_stat, & |
---|
261 | netcdf_handle_error |
---|
262 | |
---|
263 | USE spectra_mod, & |
---|
264 | ONLY: dosp_time_count, n_sp_x, n_sp_y, spectrum_x, spectrum_y |
---|
265 | |
---|
266 | |
---|
267 | IMPLICIT NONE |
---|
268 | |
---|
269 | CHARACTER (LEN=1), INTENT(IN) :: direction !< |
---|
270 | |
---|
271 | INTEGER(iwp), INTENT(IN) :: nsp !< |
---|
272 | |
---|
273 | INTEGER(iwp) :: i !< |
---|
274 | INTEGER(iwp) :: k !< |
---|
275 | |
---|
276 | REAL(wp) :: frequency !< |
---|
277 | |
---|
278 | REAL(wp), DIMENSION(nx/2) :: netcdf_data_x !< |
---|
279 | REAL(wp), DIMENSION(ny/2) :: netcdf_data_y !< |
---|
280 | |
---|
281 | |
---|
282 | IF ( direction == 'x' ) THEN |
---|
283 | |
---|
284 | DO k = 1, n_sp_x |
---|
285 | |
---|
286 | DO i = 1, nx/2 |
---|
287 | frequency = 2.0_wp * pi * i / ( dx * ( nx + 1 ) ) |
---|
288 | netcdf_data_x(i) = frequency * spectrum_x(i,k,nsp) |
---|
289 | ENDDO |
---|
290 | |
---|
291 | nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospx(nsp), netcdf_data_x, & |
---|
292 | start = (/ 1, k, dosp_time_count /), & |
---|
293 | count = (/ nx/2, 1, 1 /) ) |
---|
294 | CALL netcdf_handle_error( 'data_output_spectra', 348 ) |
---|
295 | |
---|
296 | ENDDO |
---|
297 | |
---|
298 | ENDIF |
---|
299 | |
---|
300 | IF ( direction == 'y' ) THEN |
---|
301 | |
---|
302 | DO k = 1, n_sp_y |
---|
303 | |
---|
304 | DO i = 1, ny/2 |
---|
305 | frequency = 2.0_wp * pi * i / ( dy * ( ny + 1 ) ) |
---|
306 | netcdf_data_y(i) = frequency * spectrum_y(i,k,nsp) |
---|
307 | ENDDO |
---|
308 | |
---|
309 | nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospy(nsp), netcdf_data_y, & |
---|
310 | start = (/ 1, k, dosp_time_count /), & |
---|
311 | count = (/ ny/2, 1, 1 /) ) |
---|
312 | CALL netcdf_handle_error( 'data_output_spectra', 349 ) |
---|
313 | |
---|
314 | ENDDO |
---|
315 | |
---|
316 | ENDIF |
---|
317 | |
---|
318 | #endif |
---|
319 | END SUBROUTINE output_spectra_netcdf |
---|