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 3274 2018-09-24 15:42:55Z knoop $ |
---|
27 | ! Modularization of all bulk cloud physics code components |
---|
28 | ! |
---|
29 | ! 3241 2018-09-12 15:02:00Z raasch |
---|
30 | ! unused variables removed |
---|
31 | ! |
---|
32 | ! 2718 2018-01-02 08:49:38Z maronga |
---|
33 | ! Corrected "Former revisions" section |
---|
34 | ! |
---|
35 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
36 | ! Change in file header (GPL part) |
---|
37 | ! |
---|
38 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
39 | ! |
---|
40 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
41 | ! Forced header and separation lines into 80 columns |
---|
42 | ! |
---|
43 | ! 1960 2016-07-12 16:34:24Z suehring |
---|
44 | ! Additional default spectra for passive scalar |
---|
45 | ! |
---|
46 | ! 1833 2016-04-07 14:23:03Z raasch |
---|
47 | ! spectrum renamed spectra_mod, spectra related variables moved to spectra_mod, |
---|
48 | ! routines data_output_spectra_x/y removed |
---|
49 | ! |
---|
50 | ! 1786 2016-03-08 05:49:27Z raasch |
---|
51 | ! cpp-directives for spectra removed, immediate return if no spectra levels are |
---|
52 | ! given |
---|
53 | ! |
---|
54 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
55 | ! name change of netcdf routines and module + related changes |
---|
56 | ! |
---|
57 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
58 | ! Code annotations made doxygen readable |
---|
59 | ! |
---|
60 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
61 | ! REAL constants provided with KIND-attribute |
---|
62 | ! |
---|
63 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
64 | ! -netcdf output queries |
---|
65 | ! |
---|
66 | ! 1324 2014-03-21 09:13:16Z suehring |
---|
67 | ! Bugfix: module statistics and module spectrum added, missing variables in ONLY |
---|
68 | ! arguments added |
---|
69 | ! |
---|
70 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
71 | ! REAL functions provided with KIND-attribute |
---|
72 | ! |
---|
73 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
74 | ! ONLY-attribute added to USE-statements, |
---|
75 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
76 | ! kinds are defined in new module kinds, |
---|
77 | ! revision history before 2012 removed, |
---|
78 | ! comment fields (!:) to be used for variable explanations added to |
---|
79 | ! all variable declaration statements |
---|
80 | ! |
---|
81 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
82 | ! module interfaces removed |
---|
83 | ! |
---|
84 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
85 | ! code put under GPL (PALM 3.9) |
---|
86 | ! |
---|
87 | ! 964 2012-07-26 09:14:24Z raasch |
---|
88 | ! code for profil-output removed |
---|
89 | ! |
---|
90 | ! Revision 1.1 2001/01/05 15:14:20 raasch |
---|
91 | ! Initial revision |
---|
92 | ! |
---|
93 | ! |
---|
94 | ! Description: |
---|
95 | ! ------------ |
---|
96 | !> Writing spectra data on file, using a special format which allows |
---|
97 | !> plotting of these data with PROFIL-graphic-software |
---|
98 | !------------------------------------------------------------------------------! |
---|
99 | SUBROUTINE data_output_spectra |
---|
100 | |
---|
101 | #if defined( __netcdf ) |
---|
102 | USE control_parameters, & |
---|
103 | ONLY: message_string, time_since_reference_point |
---|
104 | |
---|
105 | USE cpulog, & |
---|
106 | ONLY: cpu_log, log_point |
---|
107 | |
---|
108 | USE kinds |
---|
109 | |
---|
110 | USE NETCDF |
---|
111 | |
---|
112 | USE netcdf_interface, & |
---|
113 | ONLY: id_set_sp, id_var_time_sp, nc_stat, netcdf_handle_error |
---|
114 | |
---|
115 | USE pegrid |
---|
116 | |
---|
117 | USE spectra_mod, & |
---|
118 | ONLY: average_count_sp, averaging_interval_sp, comp_spectra_level, & |
---|
119 | data_output_sp, dosp_time_count, spectra_direction, spectrum_x, & |
---|
120 | spectrum_y |
---|
121 | |
---|
122 | |
---|
123 | IMPLICIT NONE |
---|
124 | |
---|
125 | INTEGER(iwp) :: m !< |
---|
126 | INTEGER(iwp) :: pr !< |
---|
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 basic_constants_and_equations_mod, & |
---|
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 |
---|