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