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 terms of the GNU General |
---|
6 | ! Public License as published by the Free Software Foundation, either version 3 of the License, or |
---|
7 | ! (at your option) any later version. |
---|
8 | ! |
---|
9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
---|
10 | ! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
11 | ! Public License for more details. |
---|
12 | ! |
---|
13 | ! You should have received a copy of the GNU General Public License along with PALM. If not, see |
---|
14 | ! <http://www.gnu.org/licenses/>. |
---|
15 | ! |
---|
16 | ! Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ------------------ |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: data_output_spectra.f90 4577 2020-06-25 09:53:58Z maronga $ |
---|
26 | ! file re-formatted to follow the PALM coding standard |
---|
27 | ! |
---|
28 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
29 | ! Corrected "Former revisions" section |
---|
30 | ! |
---|
31 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
32 | ! variables documented |
---|
33 | ! |
---|
34 | ! Revision 1.1 2001/01/05 15:14:20 raasch |
---|
35 | ! Initial revision |
---|
36 | ! |
---|
37 | ! |
---|
38 | ! Description: |
---|
39 | ! ------------ |
---|
40 | !> Writing spectra data on file, using a special format which allows |
---|
41 | !> plotting of these data with PROFIL-graphic-software |
---|
42 | !--------------------------------------------------------------------------------------------------! |
---|
43 | SUBROUTINE data_output_spectra |
---|
44 | |
---|
45 | #if defined( __netcdf ) |
---|
46 | USE control_parameters, & |
---|
47 | ONLY: message_string, time_since_reference_point |
---|
48 | |
---|
49 | USE cpulog, & |
---|
50 | ONLY: cpu_log, log_point |
---|
51 | |
---|
52 | USE kinds |
---|
53 | |
---|
54 | USE NETCDF |
---|
55 | |
---|
56 | USE netcdf_interface, & |
---|
57 | ONLY: id_set_sp, id_var_time_sp, nc_stat, netcdf_handle_error |
---|
58 | |
---|
59 | USE pegrid |
---|
60 | |
---|
61 | USE spectra_mod, & |
---|
62 | ONLY: average_count_sp, averaging_interval_sp, comp_spectra_level, data_output_sp, & |
---|
63 | dosp_time_count, spectra_direction, spectrum_x, spectrum_y |
---|
64 | |
---|
65 | |
---|
66 | IMPLICIT NONE |
---|
67 | |
---|
68 | INTEGER(iwp) :: m !< running index over spectra output |
---|
69 | INTEGER(iwp) :: pr !< index used to assign default quantities to data output |
---|
70 | |
---|
71 | CALL cpu_log( log_point(31), 'data_output_spectra', 'start' ) |
---|
72 | |
---|
73 | ! |
---|
74 | !-- Check if user gave any levels for spectra to be calculated |
---|
75 | IF ( comp_spectra_level(1) == 999999 ) RETURN |
---|
76 | |
---|
77 | ! |
---|
78 | !-- Output is only performed on PE0 |
---|
79 | IF ( myid == 0 ) THEN |
---|
80 | |
---|
81 | ! |
---|
82 | !-- Open file for spectra output in NetCDF format |
---|
83 | CALL check_open( 107 ) |
---|
84 | |
---|
85 | ! |
---|
86 | !-- Increment the counter for number of output times |
---|
87 | dosp_time_count = dosp_time_count + 1 |
---|
88 | |
---|
89 | ! |
---|
90 | !-- Update the spectra time axis |
---|
91 | nc_stat = NF90_PUT_VAR( id_set_sp, id_var_time_sp, & |
---|
92 | (/ time_since_reference_point /), & |
---|
93 | start = (/ dosp_time_count /), count = (/ 1 /) ) |
---|
94 | CALL netcdf_handle_error( 'data_output_spectra', 47 ) |
---|
95 | |
---|
96 | ! |
---|
97 | !-- If necessary, calculate time average and reset average counter |
---|
98 | IF ( average_count_sp == 0 ) THEN |
---|
99 | message_string = 'no spectra data available' |
---|
100 | CALL message( 'data_output_spectra', 'PA0186', 0, 0, 0, 6, 0 ) |
---|
101 | ENDIF |
---|
102 | IF ( average_count_sp /= 1 ) THEN |
---|
103 | spectrum_x = spectrum_x / REAL( average_count_sp, KIND=wp ) |
---|
104 | spectrum_y = spectrum_y / REAL( average_count_sp, KIND=wp ) |
---|
105 | average_count_sp = 0 |
---|
106 | ENDIF |
---|
107 | |
---|
108 | ! |
---|
109 | !-- Loop over all spectra defined by the user |
---|
110 | m = 1 |
---|
111 | DO WHILE ( data_output_sp(m) /= ' ' .AND. m <= 10 ) |
---|
112 | |
---|
113 | SELECT CASE ( TRIM( data_output_sp(m) ) ) |
---|
114 | |
---|
115 | CASE ( 'u' ) |
---|
116 | pr = 1 |
---|
117 | |
---|
118 | CASE ( 'v' ) |
---|
119 | pr = 2 |
---|
120 | |
---|
121 | CASE ( 'w' ) |
---|
122 | pr = 3 |
---|
123 | |
---|
124 | CASE ( 'theta' ) |
---|
125 | pr = 4 |
---|
126 | |
---|
127 | CASE ( 'q' ) |
---|
128 | pr = 5 |
---|
129 | |
---|
130 | CASE ( 's' ) |
---|
131 | pr = 6 |
---|
132 | |
---|
133 | CASE DEFAULT |
---|
134 | ! |
---|
135 | !-- The DEFAULT case is reached either if the parameter data_output_sp(m) contains a |
---|
136 | !-- wrong character string or if the user has coded a special case in the user |
---|
137 | !-- interface. There, the subroutine user_spectra checks which of these two conditions |
---|
138 | !-- applies. |
---|
139 | CALL user_spectra( 'data_output', m, pr ) |
---|
140 | |
---|
141 | END SELECT |
---|
142 | |
---|
143 | ! |
---|
144 | !-- Output of spectra in NetCDF format |
---|
145 | !-- Output of x-spectra |
---|
146 | IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN |
---|
147 | CALL output_spectra_netcdf( m, 'x' ) |
---|
148 | ENDIF |
---|
149 | ! |
---|
150 | !-- Output of y-spectra |
---|
151 | IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN |
---|
152 | CALL output_spectra_netcdf( m, 'y' ) |
---|
153 | ENDIF |
---|
154 | |
---|
155 | ! |
---|
156 | !-- Increase counter for next spectrum |
---|
157 | m = m + 1 |
---|
158 | |
---|
159 | ENDDO |
---|
160 | |
---|
161 | ! |
---|
162 | !-- Reset spectra values |
---|
163 | spectrum_x = 0.0_wp; spectrum_y = 0.0_wp |
---|
164 | |
---|
165 | ENDIF |
---|
166 | |
---|
167 | CALL cpu_log( log_point(31), 'data_output_spectra', 'stop' ) |
---|
168 | |
---|
169 | #if defined( __parallel ) |
---|
170 | ! CALL MPI_BARRIER( comm2d, ierr ) ! really necessary |
---|
171 | #endif |
---|
172 | |
---|
173 | #endif |
---|
174 | END SUBROUTINE data_output_spectra |
---|
175 | |
---|
176 | |
---|
177 | !--------------------------------------------------------------------------------------------------! |
---|
178 | ! Description: |
---|
179 | ! ------------ |
---|
180 | !> @todo Missing subroutine description. |
---|
181 | !--------------------------------------------------------------------------------------------------! |
---|
182 | SUBROUTINE output_spectra_netcdf( nsp, direction ) |
---|
183 | #if defined( __netcdf ) |
---|
184 | |
---|
185 | USE basic_constants_and_equations_mod, & |
---|
186 | ONLY: pi |
---|
187 | |
---|
188 | USE grid_variables, & |
---|
189 | ONLY: dx, dy |
---|
190 | |
---|
191 | USE indices, & |
---|
192 | ONLY: nx, ny |
---|
193 | |
---|
194 | USE kinds |
---|
195 | |
---|
196 | USE NETCDF |
---|
197 | |
---|
198 | USE netcdf_interface, & |
---|
199 | ONLY: id_set_sp, id_var_dospx, id_var_dospy, nc_stat, netcdf_handle_error |
---|
200 | |
---|
201 | USE spectra_mod, & |
---|
202 | ONLY: dosp_time_count, n_sp_x, n_sp_y, spectrum_x, spectrum_y |
---|
203 | |
---|
204 | |
---|
205 | IMPLICIT NONE |
---|
206 | |
---|
207 | CHARACTER (LEN=1), INTENT(IN) :: direction !< directio of spectra evaluation |
---|
208 | |
---|
209 | INTEGER(iwp), INTENT(IN) :: nsp !< number of spectrum |
---|
210 | |
---|
211 | INTEGER(iwp) :: i !< running index in frequency space |
---|
212 | INTEGER(iwp) :: k !< running index over number of spectrum |
---|
213 | |
---|
214 | REAL(wp) :: frequency !< wavenumber |
---|
215 | |
---|
216 | REAL(wp), DIMENSION(nx/2) :: netcdf_data_x !< normalized wavenumber along x written into NetCDF file |
---|
217 | REAL(wp), DIMENSION(ny/2) :: netcdf_data_y !< normalized wavenumber along y written into NetCDF file |
---|
218 | |
---|
219 | |
---|
220 | IF ( direction == 'x' ) THEN |
---|
221 | |
---|
222 | DO k = 1, n_sp_x |
---|
223 | |
---|
224 | DO i = 1, nx/2 |
---|
225 | frequency = 2.0_wp * pi * i / ( dx * ( nx + 1 ) ) |
---|
226 | netcdf_data_x(i) = frequency * spectrum_x(i,k,nsp) |
---|
227 | ENDDO |
---|
228 | |
---|
229 | nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospx(nsp), netcdf_data_x, & |
---|
230 | start = (/ 1, k, dosp_time_count /), & |
---|
231 | count = (/ nx/2, 1, 1 /) ) |
---|
232 | CALL netcdf_handle_error( 'data_output_spectra', 348 ) |
---|
233 | |
---|
234 | ENDDO |
---|
235 | |
---|
236 | ENDIF |
---|
237 | |
---|
238 | IF ( direction == 'y' ) THEN |
---|
239 | |
---|
240 | DO k = 1, n_sp_y |
---|
241 | |
---|
242 | DO i = 1, ny/2 |
---|
243 | frequency = 2.0_wp * pi * i / ( dy * ( ny + 1 ) ) |
---|
244 | netcdf_data_y(i) = frequency * spectrum_y(i,k,nsp) |
---|
245 | ENDDO |
---|
246 | |
---|
247 | nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospy(nsp), netcdf_data_y, & |
---|
248 | start = (/ 1, k, dosp_time_count /), & |
---|
249 | count = (/ ny/2, 1, 1 /) ) |
---|
250 | CALL netcdf_handle_error( 'data_output_spectra', 349 ) |
---|
251 | |
---|
252 | ENDDO |
---|
253 | |
---|
254 | ENDIF |
---|
255 | |
---|
256 | #endif |
---|
257 | END SUBROUTINE output_spectra_netcdf |
---|