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