[1682] | 1 | !> @file data_output_spectra.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 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 | ! |
---|
[2718] | 17 | ! Copyright 1997-2018 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 2718 2018-01-02 08:49:38Z kanani $ |
---|
[2716] | 27 | ! Corrected "Former revisions" section |
---|
| 28 | ! |
---|
| 29 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
| 30 | ! Change in file header (GPL part) |
---|
[1321] | 31 | ! |
---|
[2716] | 32 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
| 33 | ! |
---|
[2001] | 34 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 35 | ! Forced header and separation lines into 80 columns |
---|
| 36 | ! |
---|
[1961] | 37 | ! 1960 2016-07-12 16:34:24Z suehring |
---|
| 38 | ! Additional default spectra for passive scalar |
---|
| 39 | ! |
---|
[1834] | 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 | ! |
---|
[1787] | 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 | ! |
---|
[1784] | 48 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
| 49 | ! name change of netcdf routines and module + related changes |
---|
| 50 | ! |
---|
[1683] | 51 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 52 | ! Code annotations made doxygen readable |
---|
| 53 | ! |
---|
[1354] | 54 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 55 | ! REAL constants provided with KIND-attribute |
---|
| 56 | ! |
---|
[1329] | 57 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
| 58 | ! -netcdf output queries |
---|
| 59 | ! |
---|
[1325] | 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 | ! |
---|
[1323] | 64 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
| 65 | ! REAL functions provided with KIND-attribute |
---|
| 66 | ! |
---|
[1321] | 67 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 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 |
---|
[1] | 74 | ! |
---|
[1319] | 75 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
| 76 | ! module interfaces removed |
---|
| 77 | ! |
---|
[1037] | 78 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 79 | ! code put under GPL (PALM 3.9) |
---|
| 80 | ! |
---|
[965] | 81 | ! 964 2012-07-26 09:14:24Z raasch |
---|
| 82 | ! code for profil-output removed |
---|
| 83 | ! |
---|
[1] | 84 | ! Revision 1.1 2001/01/05 15:14:20 raasch |
---|
| 85 | ! Initial revision |
---|
| 86 | ! |
---|
| 87 | ! |
---|
| 88 | ! Description: |
---|
| 89 | ! ------------ |
---|
[1682] | 90 | !> Writing spectra data on file, using a special format which allows |
---|
| 91 | !> plotting of these data with PROFIL-graphic-software |
---|
[1] | 92 | !------------------------------------------------------------------------------! |
---|
[1682] | 93 | SUBROUTINE data_output_spectra |
---|
| 94 | |
---|
[1783] | 95 | #if defined( __netcdf ) |
---|
[1320] | 96 | USE control_parameters, & |
---|
[1833] | 97 | ONLY: message_string, run_description_header, & |
---|
[1324] | 98 | time_since_reference_point |
---|
[1320] | 99 | |
---|
| 100 | USE cpulog, & |
---|
| 101 | ONLY: cpu_log, log_point |
---|
| 102 | |
---|
| 103 | USE kinds |
---|
| 104 | |
---|
[1783] | 105 | USE NETCDF |
---|
[1320] | 106 | |
---|
[1783] | 107 | USE netcdf_interface, & |
---|
| 108 | ONLY: id_set_sp, id_var_time_sp, nc_stat, netcdf_handle_error |
---|
| 109 | |
---|
[1] | 110 | USE pegrid |
---|
| 111 | |
---|
[1833] | 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 |
---|
[1] | 116 | |
---|
[1320] | 117 | |
---|
[1] | 118 | IMPLICIT NONE |
---|
| 119 | |
---|
[1682] | 120 | INTEGER(iwp) :: cranz_x !< |
---|
| 121 | INTEGER(iwp) :: cranz_y !< |
---|
| 122 | INTEGER(iwp) :: m !< |
---|
| 123 | INTEGER(iwp) :: pr !< |
---|
[1320] | 124 | |
---|
[1682] | 125 | LOGICAL :: frame_x !< |
---|
| 126 | LOGICAL :: frame_y !< |
---|
[1] | 127 | |
---|
| 128 | CALL cpu_log( log_point(31), 'data_output_spectra', 'start' ) |
---|
| 129 | |
---|
| 130 | ! |
---|
[1786] | 131 | !-- Check if user gave any levels for spectra to be calculated |
---|
| 132 | IF ( comp_spectra_level(1) == 999999 ) RETURN |
---|
| 133 | |
---|
| 134 | ! |
---|
[1] | 135 | !-- Output is only performed on PE0 |
---|
| 136 | IF ( myid == 0 ) THEN |
---|
| 137 | |
---|
| 138 | ! |
---|
| 139 | !-- Open file for spectra output in NetCDF format |
---|
[1327] | 140 | CALL check_open( 107 ) |
---|
[1] | 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 |
---|
[291] | 148 | nc_stat = NF90_PUT_VAR( id_set_sp, id_var_time_sp, & |
---|
| 149 | (/ time_since_reference_point /), & |
---|
[1] | 150 | start = (/ dosp_time_count /), count = (/ 1 /) ) |
---|
[1783] | 151 | CALL netcdf_handle_error( 'data_output_spectra', 47 ) |
---|
[1] | 152 | |
---|
| 153 | ! |
---|
| 154 | !-- If necessary, calculate time average and reset average counter |
---|
| 155 | IF ( average_count_sp == 0 ) THEN |
---|
[254] | 156 | message_string = 'no spectra data available' |
---|
| 157 | CALL message( 'data_output_spectra', 'PA0186', 0, 0, 0, 6, 0 ) |
---|
[1] | 158 | ENDIF |
---|
| 159 | IF ( average_count_sp /= 1 ) THEN |
---|
[1322] | 160 | spectrum_x = spectrum_x / REAL( average_count_sp, KIND=wp ) |
---|
| 161 | spectrum_y = spectrum_y / REAL( average_count_sp, KIND=wp ) |
---|
[1] | 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 | |
---|
[1960] | 187 | CASE ( 's' ) |
---|
| 188 | pr = 6 |
---|
| 189 | |
---|
[1] | 190 | CASE DEFAULT |
---|
[144] | 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 ) |
---|
[1] | 198 | |
---|
| 199 | END SELECT |
---|
| 200 | |
---|
| 201 | ! |
---|
| 202 | !-- Output of spectra in NetCDF format |
---|
[1327] | 203 | !-- Output of x-spectra |
---|
| 204 | IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN |
---|
| 205 | CALL output_spectra_netcdf( m, 'x' ) |
---|
| 206 | ENDIF |
---|
[1] | 207 | ! |
---|
[1327] | 208 | !-- Output of y-spectra |
---|
| 209 | IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN |
---|
| 210 | CALL output_spectra_netcdf( m, 'y' ) |
---|
[1] | 211 | ENDIF |
---|
| 212 | |
---|
| 213 | ! |
---|
| 214 | !-- Increase counter for next spectrum |
---|
| 215 | m = m + 1 |
---|
| 216 | |
---|
| 217 | ENDDO |
---|
| 218 | |
---|
| 219 | ! |
---|
| 220 | !-- Reset spectra values |
---|
[1353] | 221 | spectrum_x = 0.0_wp; spectrum_y = 0.0_wp |
---|
[1] | 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 | |
---|
[1682] | 235 | !------------------------------------------------------------------------------! |
---|
| 236 | ! Description: |
---|
| 237 | ! ------------ |
---|
| 238 | !> @todo Missing subroutine description. |
---|
| 239 | !------------------------------------------------------------------------------! |
---|
[1] | 240 | SUBROUTINE output_spectra_netcdf( nsp, direction ) |
---|
| 241 | #if defined( __netcdf ) |
---|
| 242 | |
---|
[1320] | 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 | |
---|
[1783] | 254 | USE NETCDF |
---|
[1] | 255 | |
---|
[1783] | 256 | USE netcdf_interface, & |
---|
| 257 | ONLY: id_set_sp, id_var_dospx, id_var_dospy, nc_stat, & |
---|
| 258 | netcdf_handle_error |
---|
| 259 | |
---|
[1833] | 260 | USE spectra_mod, & |
---|
| 261 | ONLY: dosp_time_count, n_sp_x, n_sp_y, spectrum_x, spectrum_y |
---|
[1320] | 262 | |
---|
| 263 | |
---|
[1] | 264 | IMPLICIT NONE |
---|
| 265 | |
---|
[1682] | 266 | CHARACTER (LEN=1), INTENT(IN) :: direction !< |
---|
[1] | 267 | |
---|
[1682] | 268 | INTEGER(iwp), INTENT(IN) :: nsp !< |
---|
[1] | 269 | |
---|
[1682] | 270 | INTEGER(iwp) :: i !< |
---|
| 271 | INTEGER(iwp) :: k !< |
---|
[1] | 272 | |
---|
[1682] | 273 | REAL(wp) :: frequency !< |
---|
[1] | 274 | |
---|
[1682] | 275 | REAL(wp), DIMENSION(nx/2) :: netcdf_data_x !< |
---|
| 276 | REAL(wp), DIMENSION(ny/2) :: netcdf_data_y !< |
---|
[1] | 277 | |
---|
| 278 | |
---|
| 279 | IF ( direction == 'x' ) THEN |
---|
| 280 | |
---|
| 281 | DO k = 1, n_sp_x |
---|
| 282 | |
---|
| 283 | DO i = 1, nx/2 |
---|
[1353] | 284 | frequency = 2.0_wp * pi * i / ( dx * ( nx + 1 ) ) |
---|
[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 /) ) |
---|
[1783] | 291 | CALL netcdf_handle_error( 'data_output_spectra', 348 ) |
---|
[1] | 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 |
---|
[1353] | 302 | frequency = 2.0_wp * pi * i / ( dy * ( ny + 1 ) ) |
---|
[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 /) ) |
---|
[1783] | 309 | CALL netcdf_handle_error( 'data_output_spectra', 349 ) |
---|
[1] | 310 | |
---|
| 311 | ENDDO |
---|
| 312 | |
---|
| 313 | ENDIF |
---|
| 314 | |
---|
| 315 | #endif |
---|
| 316 | END SUBROUTINE output_spectra_netcdf |
---|