[2696] | 1 | !> @file src/inifor.f90 |
---|
| 2 | !------------------------------------------------------------------------------! |
---|
[2718] | 3 | ! This file is part of the PALM model system. |
---|
[2696] | 4 | ! |
---|
[2718] | 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 |
---|
[2696] | 8 | ! version. |
---|
| 9 | ! |
---|
[2718] | 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. |
---|
[2696] | 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 | ! |
---|
[3779] | 17 | ! Copyright 2017-2019 Leibniz Universitaet Hannover |
---|
| 18 | ! Copyright 2017-2019 Deutscher Wetterdienst Offenbach |
---|
[2696] | 19 | !------------------------------------------------------------------------------! |
---|
| 20 | ! |
---|
| 21 | ! Current revisions: |
---|
| 22 | ! ----------------- |
---|
[3183] | 23 | ! |
---|
| 24 | ! |
---|
| 25 | ! Former revisions: |
---|
| 26 | ! ----------------- |
---|
| 27 | ! $Id: inifor.f90 3997 2019-05-23 12:35:57Z banzhafs $ |
---|
[3997] | 28 | ! Alert user to warnings if any |
---|
| 29 | ! |
---|
| 30 | ! |
---|
| 31 | ! 3866 2019-04-05 14:25:01Z eckhard |
---|
[3866] | 32 | ! Use PALM's working precision |
---|
| 33 | ! Show error message if compiled without netCDF support |
---|
| 34 | ! Renamed run_control -> log_runtime |
---|
| 35 | ! Improved coding style added comments |
---|
| 36 | ! |
---|
| 37 | ! |
---|
| 38 | ! 3785 2019-03-06 10:41:14Z eckhard |
---|
[3779] | 39 | ! Average geostrophic wind components on coarse COSMO levels instead of fine PALM levels |
---|
| 40 | ! Remove --debug netCDF output of internal pressure profiles |
---|
| 41 | ! |
---|
| 42 | ! 3680 2019-01-18 14:54:12Z knoop |
---|
[3618] | 43 | ! Prefixed all INIFOR modules with inifor_ |
---|
| 44 | ! |
---|
| 45 | ! |
---|
| 46 | ! 3615 2018-12-10 07:21:03Z raasch |
---|
[3615] | 47 | ! bugfix: abort replaced by inifor_abort |
---|
| 48 | ! |
---|
| 49 | ! 3613 2018-12-07 18:20:37Z eckhard |
---|
[3613] | 50 | ! Moved version output to setup_parameters() |
---|
| 51 | ! |
---|
| 52 | ! 3557 2018-11-22 16:01:22Z eckhard |
---|
[3557] | 53 | ! Updated documentation |
---|
| 54 | ! |
---|
| 55 | ! 3537 2018-11-20 10:53:14Z eckhard |
---|
[3537] | 56 | ! Print version number on program start |
---|
| 57 | ! |
---|
| 58 | ! |
---|
| 59 | ! 3456 2018-10-30 14:29:54Z eckhard |
---|
[3456] | 60 | ! NetCDf output of internal arrays only with --debug option |
---|
| 61 | ! |
---|
| 62 | ! |
---|
| 63 | ! 3401 2018-10-23 09:33:31Z eckhard |
---|
[3401] | 64 | ! Re-compute geostrophic winds every time step |
---|
| 65 | ! |
---|
| 66 | ! 3395 2018-10-22 17:32:49Z eckhard |
---|
[3395] | 67 | ! Added main loop support for computation of geostrophic winds and surface |
---|
| 68 | ! pressure |
---|
| 69 | ! Cleaned up terminal output, show some meVssages only with --debug option |
---|
| 70 | ! |
---|
| 71 | ! 3183 2018-07-27 14:25:55Z suehring |
---|
[3182] | 72 | ! Introduced new PALM grid stretching |
---|
| 73 | ! Renamend initial-condition mode variable 'mode' to 'ic_mode' |
---|
| 74 | ! Improved log messages |
---|
[2696] | 75 | ! |
---|
| 76 | ! |
---|
[3183] | 77 | ! 3182 2018-07-27 13:36:03Z suehring |
---|
[2696] | 78 | ! Initial revision |
---|
| 79 | ! |
---|
| 80 | ! |
---|
| 81 | ! |
---|
| 82 | ! Authors: |
---|
| 83 | ! -------- |
---|
[3557] | 84 | !> @author Eckhard Kadasch, (Deutscher Wetterdienst, Offenbach) |
---|
[2696] | 85 | ! |
---|
| 86 | ! Description: |
---|
| 87 | ! ------------ |
---|
| 88 | !> INIFOR is an interpolation tool for generating meteorological initialization |
---|
| 89 | !> and forcing data for the urban climate model PALM-4U. The required |
---|
| 90 | !> meteorological fields are interpolated from output data of the mesoscale |
---|
[3779] | 91 | !> model COSMO. This is the main program file. |
---|
[2696] | 92 | !------------------------------------------------------------------------------! |
---|
| 93 | PROGRAM inifor |
---|
[3866] | 94 | |
---|
[3680] | 95 | #if defined ( __netcdf ) |
---|
[2696] | 96 | |
---|
[3618] | 97 | USE inifor_control |
---|
| 98 | USE inifor_defs |
---|
| 99 | USE inifor_grid, & |
---|
[3866] | 100 | ONLY: averaging_width_ns, & |
---|
| 101 | averaging_width_ew, & |
---|
| 102 | cfg, & |
---|
| 103 | cosmo_grid, & |
---|
| 104 | f3, & |
---|
| 105 | fini_grids, & |
---|
| 106 | fini_io_groups, & |
---|
| 107 | fini_variables, & |
---|
| 108 | fini_file_lists, & |
---|
| 109 | io_group_list, & |
---|
| 110 | lam_centre, & |
---|
| 111 | lambda_n, & |
---|
| 112 | nx, ny, nz, & |
---|
| 113 | origin_lat, & |
---|
| 114 | origin_lon, & |
---|
| 115 | output_file, & |
---|
| 116 | output_var_table, & |
---|
| 117 | p0, & |
---|
| 118 | phi_centre, & |
---|
| 119 | phi_n, & |
---|
| 120 | preprocess, & |
---|
| 121 | palm_grid, & |
---|
| 122 | setup_grids, & |
---|
| 123 | setup_parameters, & |
---|
| 124 | setup_variable_tables, & |
---|
| 125 | setup_io_groups |
---|
[3618] | 126 | USE inifor_io |
---|
| 127 | USE inifor_transform, & |
---|
[3866] | 128 | ONLY: average_pressure_perturbation, & |
---|
| 129 | average_profile, & |
---|
| 130 | extrapolate_density, & |
---|
| 131 | extrapolate_pressure, & |
---|
| 132 | geostrophic_winds, & |
---|
| 133 | get_surface_pressure, & |
---|
| 134 | interp_average_profile, & |
---|
| 135 | interpolate_1d, & |
---|
| 136 | interpolate_1d_arr, & |
---|
| 137 | interpolate_2d, & |
---|
| 138 | interpolate_3d |
---|
[3618] | 139 | USE inifor_types |
---|
[2696] | 140 | |
---|
| 141 | IMPLICIT NONE |
---|
| 142 | |
---|
[3557] | 143 | INTEGER :: igroup !< loop index for IO groups |
---|
| 144 | INTEGER :: ivar !< loop index for output variables |
---|
| 145 | INTEGER :: iter !< loop index for time steps |
---|
| 146 | |
---|
[3866] | 147 | REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: output_arr !< array buffer for interpolated quantities |
---|
| 148 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_centre !< density profile of the centre averaging domain |
---|
| 149 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: ug_cosmo !< profile of the geostrophic wind in x direction on COSMO levels |
---|
| 150 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: vg_cosmo !< profile of the geostrophic wind in y direction on COSMO levels |
---|
| 151 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: ug_palm !< profile of the geostrophic wind in x direction interpolated onto PALM levels |
---|
| 152 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: vg_palm !< profile of the geostrophic wind in y direction interpolated onto PALM levels |
---|
| 153 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_north !< density profile of the northern averaging domain |
---|
| 154 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_south !< density profile of the southern averaging domain |
---|
| 155 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_east !< density profile of the eastern averaging domain |
---|
| 156 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: rho_west !< density profile of the western averaging domain |
---|
| 157 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: p_north !< pressure profile of the northern averaging domain |
---|
| 158 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: p_south !< pressure profile of the southern averaging domain |
---|
| 159 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: p_east !< pressure profile of the eastern averaging domain |
---|
| 160 | REAL(wp), ALLOCATABLE, DIMENSION(:), TARGET :: p_west !< pressure profile of the western averaging domain |
---|
[3557] | 161 | |
---|
[3866] | 162 | REAL(wp), POINTER, DIMENSION(:) :: internal_arr !< pointer to the currently processed internal array (density, pressure) |
---|
| 163 | REAL(wp), POINTER, DIMENSION(:) :: ug_vg_palm !< pointer to the currently processed geostrophic wind component |
---|
[3557] | 164 | |
---|
| 165 | TYPE(nc_var), POINTER :: output_var !< pointer to the currently processed output variable |
---|
| 166 | TYPE(io_group), POINTER :: group !< pointer to the currently processed IO group |
---|
| 167 | TYPE(container), ALLOCATABLE :: input_buffer(:) !< buffer of the current IO group's input arrays |
---|
| 168 | |
---|
| 169 | LOGICAL, SAVE :: ug_vg_have_been_computed = .FALSE. !< flag for managing geostrophic wind allocation and computation |
---|
[3785] | 170 | !LOGICAL, SAVE :: debugging_output = .TRUE. !< flag controllging output of internal variables |
---|
[2696] | 171 | |
---|
| 172 | !> \mainpage About INIFOR |
---|
| 173 | !> ... |
---|
| 174 | ! |
---|
| 175 | !------------------------------------------------------------------------------ |
---|
| 176 | !- Section 1: Initialization |
---|
| 177 | !------------------------------------------------------------------------------ |
---|
[3866] | 178 | CALL log_runtime( 'init', 'void' ) |
---|
[2696] | 179 | |
---|
[3557] | 180 | ! |
---|
| 181 | !-- Initialize INIFOR's parameters from command-line interface and namelists |
---|
[3866] | 182 | CALL setup_parameters |
---|
[2696] | 183 | |
---|
[3557] | 184 | ! |
---|
| 185 | !-- Initialize all grids, including interpolation neighbours and weights |
---|
[3866] | 186 | CALL setup_grids |
---|
| 187 | CALL log_runtime( 'time', 'init' ) |
---|
[2696] | 188 | |
---|
[3557] | 189 | ! |
---|
| 190 | !-- Initialize the netCDF output file and define dimensions |
---|
[3997] | 191 | CALL setup_netcdf_dimensions( output_file, palm_grid, cfg%start_date, & |
---|
| 192 | origin_lon, origin_lat ) |
---|
[3866] | 193 | CALL log_runtime( 'time', 'write' ) |
---|
[2696] | 194 | |
---|
[3557] | 195 | ! |
---|
| 196 | !-- Set up the tables containing the input and output variables and set |
---|
| 197 | !-- the corresponding netCDF dimensions for each output variable |
---|
[3866] | 198 | CALL setup_variable_tables( cfg%ic_mode ) |
---|
| 199 | CALL log_runtime( 'time', 'write' ) |
---|
[2696] | 200 | |
---|
[3557] | 201 | ! |
---|
| 202 | !-- Add the output variables to the netCDF output file |
---|
[3866] | 203 | CALL setup_netcdf_variables( output_file%name, output_var_table ) |
---|
[2696] | 204 | |
---|
[3866] | 205 | CALL setup_io_groups |
---|
| 206 | CALL log_runtime( 'time', 'init' ) |
---|
[2696] | 207 | |
---|
| 208 | !------------------------------------------------------------------------------ |
---|
[3866] | 209 | !-- Section 2: Main loop |
---|
[2696] | 210 | !------------------------------------------------------------------------------ |
---|
[3866] | 211 | ! |
---|
| 212 | !-- Input and output variables are organized into IO groups. For instance, the |
---|
| 213 | !-- 'thermodynamics' IO group bundles the input variaebls T, P, QV and the |
---|
| 214 | !-- output variables p, theta, rho, and qv. |
---|
| 215 | !-- An IO group bunldes variables that are physically dependent on each other. |
---|
| 216 | !-- In case of the 'thermodynamics' group, theta = f(P,T), rho = f(P,T,QV). |
---|
| 217 | DO igroup = 1, SIZE( io_group_list ) |
---|
[2696] | 218 | |
---|
| 219 | group => io_group_list(igroup) |
---|
[3866] | 220 | IF ( group%to_be_processed ) THEN |
---|
[2696] | 221 | |
---|
[3866] | 222 | !-- Loop over all output time steps for the current group. |
---|
| 223 | DO iter = 1, group%nt |
---|
[2696] | 224 | |
---|
| 225 | !------------------------------------------------------------------------------ |
---|
[3866] | 226 | !-- Section 2.1: Read and preprocess input data |
---|
[2696] | 227 | !------------------------------------------------------------------------------ |
---|
[3866] | 228 | CALL read_input_variables( group, iter, input_buffer ) |
---|
| 229 | CALL log_runtime( 'time', 'read' ) |
---|
[2696] | 230 | |
---|
[3866] | 231 | !-- Carry out all required physical conversion of the input variables |
---|
| 232 | !-- of the current IO group on the input (COSMO) grid. For instance, |
---|
| 233 | !-- horizontal velocities are rotated to the PALM coordinate system and |
---|
| 234 | !-- potential temperature is computed from the absolute temperature and |
---|
| 235 | !-- pressure. |
---|
| 236 | CALL preprocess( group, input_buffer, cosmo_grid, iter ) |
---|
| 237 | CALL log_runtime( 'time', 'comp' ) |
---|
[2696] | 238 | |
---|
[3182] | 239 | !TODO: move this assertion into 'preprocess'. |
---|
[3866] | 240 | IF ( .NOT. ALL(input_buffer(:)%is_preprocessed .AND. .TRUE.) ) THEN |
---|
| 241 | message = "Input buffers for group '" // TRIM( group%kind ) // & |
---|
| 242 | "' could not be preprocessed sucessfully." |
---|
| 243 | CALL inifor_abort( 'main loop', message ) |
---|
[3785] | 244 | ENDIF |
---|
[2696] | 245 | |
---|
| 246 | !------------------------------------------------------------------------------ |
---|
[3866] | 247 | !-- Section 2.2: Interpolate each output variable of the group |
---|
[2696] | 248 | !------------------------------------------------------------------------------ |
---|
[3866] | 249 | DO ivar = 1, group%nv |
---|
[2696] | 250 | |
---|
[3866] | 251 | output_var => group%out_vars(ivar) |
---|
[2696] | 252 | |
---|
[3866] | 253 | IF ( output_var%to_be_processed .AND. & |
---|
| 254 | iter .LE. output_var%nt ) THEN |
---|
[2696] | 255 | |
---|
[3866] | 256 | message = "Processing '" // TRIM( output_var%name ) // & |
---|
| 257 | "' (" // TRIM( output_var%kind ) // & |
---|
| 258 | "), iteration " // TRIM( str( iter ) ) //" of " //& |
---|
| 259 | TRIM( str( output_var%nt ) ) |
---|
| 260 | CALL report( 'main loop', message ) |
---|
[2696] | 261 | |
---|
[3866] | 262 | SELECT CASE( TRIM( output_var%task ) ) |
---|
[2696] | 263 | |
---|
[3866] | 264 | !-- 2D horizontal interpolation |
---|
| 265 | CASE( 'interpolate_2d' ) |
---|
[2696] | 266 | |
---|
[3866] | 267 | SELECT CASE( TRIM( output_var%kind ) ) |
---|
| 268 | |
---|
| 269 | CASE( 'init soil' ) |
---|
| 270 | |
---|
| 271 | ALLOCATE( output_arr(0:output_var%grid%nx, & |
---|
| 272 | 0:output_var%grid%ny, & |
---|
| 273 | SIZE( output_var%grid%depths )) ) |
---|
| 274 | |
---|
| 275 | CASE ( 'surface forcing' ) |
---|
| 276 | |
---|
| 277 | ALLOCATE( output_arr(0:output_var%grid%nx, & |
---|
| 278 | 0:output_var%grid%ny, 1) ) |
---|
| 279 | |
---|
| 280 | CASE DEFAULT |
---|
| 281 | |
---|
| 282 | message = "'" // TRIM( output_var%kind ) // "' is not a soil variable" |
---|
| 283 | CALL inifor_abort( "main loop", message ) |
---|
| 284 | |
---|
| 285 | END SELECT |
---|
| 286 | CALL log_runtime( 'time', 'alloc' ) |
---|
| 287 | |
---|
| 288 | CALL interpolate_2d( input_buffer(output_var%input_id)%array(:,:,:), & |
---|
| 289 | output_arr(:,:,:), output_var%intermediate_grid, output_var ) |
---|
| 290 | CALL log_runtime( 'time', 'comp' ) |
---|
| 291 | |
---|
| 292 | |
---|
| 293 | !-- Interpolation in 3D, used for atmospheric initial and |
---|
| 294 | !-- boundary conditions. |
---|
| 295 | CASE ( 'interpolate_3d' ) |
---|
| 296 | |
---|
| 297 | ALLOCATE( output_arr(0:output_var%grid % nx, & |
---|
| 298 | 0:output_var%grid % ny, & |
---|
| 299 | 1:output_var%grid % nz) ) |
---|
| 300 | |
---|
| 301 | CALL log_runtime( 'time', 'alloc' ) |
---|
| 302 | CALL interpolate_3d( & |
---|
| 303 | input_buffer(output_var%input_id)%array(:,:,:), & |
---|
| 304 | output_arr(:,:,:), & |
---|
| 305 | output_var%intermediate_grid, & |
---|
| 306 | output_var%grid) |
---|
| 307 | CALL log_runtime( 'time', 'comp' ) |
---|
| 308 | |
---|
| 309 | !-- Compute initial avaerage profiles (if --init-mode profile |
---|
| 310 | !-- is used) |
---|
| 311 | CASE ( 'average profile' ) |
---|
| 312 | |
---|
| 313 | ALLOCATE( output_arr(0:output_var%grid%nx, & |
---|
| 314 | 0:output_var%grid%ny, & |
---|
| 315 | 1:output_var%grid%nz) ) |
---|
| 316 | CALL log_runtime( 'time', 'alloc' ) |
---|
| 317 | |
---|
| 318 | CALL interp_average_profile( & |
---|
| 319 | input_buffer(output_var%input_id)%array(:,:,:), & |
---|
| 320 | output_arr(0,0,:), & |
---|
| 321 | output_var%averaging_grid ) |
---|
| 322 | |
---|
| 323 | IF ( TRIM( output_var%name ) == & |
---|
| 324 | 'surface_forcing_surface_pressure' ) THEN |
---|
| 325 | |
---|
| 326 | IF ( cfg%p0_is_set ) THEN |
---|
| 327 | output_arr(0,0,1) = p0 |
---|
| 328 | ELSE |
---|
| 329 | CALL get_surface_pressure( & |
---|
| 330 | output_arr(0,0,:), rho_centre, & |
---|
| 331 | output_var%averaging_grid ) |
---|
| 332 | ENDIF |
---|
| 333 | |
---|
[3785] | 334 | ENDIF |
---|
[3866] | 335 | CALL log_runtime( 'time', 'comp' ) |
---|
| 336 | |
---|
| 337 | !-- Compute internal profiles, required for differentiation of |
---|
| 338 | !-- geostrophic wind |
---|
| 339 | CASE ( 'internal profile' ) |
---|
| 340 | |
---|
| 341 | message = "Averaging of internal profile for variable '" //& |
---|
| 342 | TRIM( output_var%name ) // "' is not supported." |
---|
| 343 | |
---|
| 344 | SELECT CASE ( TRIM( output_var%name ) ) |
---|
| 345 | |
---|
| 346 | CASE( 'internal_density_centre' ) |
---|
| 347 | ALLOCATE( rho_centre(1:cosmo_grid%nz) ) |
---|
| 348 | internal_arr => rho_centre |
---|
| 349 | |
---|
| 350 | CASE( 'internal_density_north' ) |
---|
| 351 | ALLOCATE( rho_north(1:cosmo_grid%nz) ) |
---|
| 352 | internal_arr => rho_north |
---|
| 353 | |
---|
| 354 | CASE( 'internal_density_south' ) |
---|
| 355 | ALLOCATE( rho_south(1:cosmo_grid%nz) ) |
---|
| 356 | internal_arr => rho_south |
---|
| 357 | |
---|
| 358 | CASE( 'internal_density_east' ) |
---|
| 359 | ALLOCATE( rho_east(1:cosmo_grid%nz) ) |
---|
| 360 | internal_arr => rho_east |
---|
| 361 | |
---|
| 362 | CASE( 'internal_density_west' ) |
---|
| 363 | ALLOCATE( rho_west(1:cosmo_grid%nz) ) |
---|
| 364 | internal_arr => rho_west |
---|
| 365 | |
---|
| 366 | CASE( 'internal_pressure_north' ) |
---|
| 367 | ALLOCATE( p_north(1:cosmo_grid%nz) ) |
---|
| 368 | internal_arr => p_north |
---|
| 369 | |
---|
| 370 | CASE( 'internal_pressure_south' ) |
---|
| 371 | ALLOCATE( p_south(1:cosmo_grid%nz) ) |
---|
| 372 | internal_arr => p_south |
---|
| 373 | |
---|
| 374 | CASE( 'internal_pressure_east' ) |
---|
| 375 | ALLOCATE( p_east(1:cosmo_grid%nz) ) |
---|
| 376 | internal_arr => p_east |
---|
| 377 | |
---|
| 378 | CASE( 'internal_pressure_west' ) |
---|
| 379 | ALLOCATE( p_west(1:cosmo_grid%nz) ) |
---|
| 380 | internal_arr => p_west |
---|
| 381 | |
---|
| 382 | CASE DEFAULT |
---|
| 383 | CALL inifor_abort( 'main loop', message ) |
---|
| 384 | |
---|
| 385 | END SELECT |
---|
| 386 | CALL log_runtime( 'time', 'alloc' ) |
---|
| 387 | |
---|
| 388 | |
---|
| 389 | SELECT CASE( TRIM( output_var%name ) ) |
---|
| 390 | |
---|
| 391 | CASE( 'internal_pressure_north', & |
---|
| 392 | 'internal_pressure_south', & |
---|
| 393 | 'internal_pressure_east', & |
---|
| 394 | 'internal_pressure_west' ) |
---|
| 395 | |
---|
| 396 | CALL average_pressure_perturbation( & |
---|
| 397 | input_buffer(output_var%input_id) % array(:,:,:),& |
---|
| 398 | internal_arr(:), & |
---|
| 399 | cosmo_grid, output_var%averaging_grid & |
---|
| 400 | ) |
---|
| 401 | |
---|
| 402 | CASE DEFAULT |
---|
| 403 | |
---|
| 404 | CALL average_profile( & |
---|
| 405 | input_buffer(output_var%input_id) % array(:,:,:),& |
---|
| 406 | internal_arr(:), & |
---|
| 407 | output_var%averaging_grid & |
---|
| 408 | ) |
---|
[3395] | 409 | |
---|
| 410 | END SELECT |
---|
| 411 | |
---|
| 412 | |
---|
[3779] | 413 | ! |
---|
| 414 | !-- Output of geostrophic pressure profiles (with --debug |
---|
| 415 | !-- option) is currently deactivated, since they are now |
---|
| 416 | !-- defined on averaged COSMO levels instead of PALM levels |
---|
| 417 | !-- (requires definiton of COSMO levels in netCDF output.) |
---|
| 418 | !IF (.TRUE.) THEN |
---|
[3866] | 419 | ! ALLOCATE( output_arr(1,1,1:output_var%grid % nz) ) |
---|
[3779] | 420 | ! output_arr(1,1,:) = internal_arr(:) |
---|
[3785] | 421 | !ENDIF |
---|
[3866] | 422 | CALL log_runtime( 'time', 'comp' ) |
---|
[3395] | 423 | |
---|
[3557] | 424 | ! |
---|
| 425 | !-- This case gets called twice, the first time for ug, the |
---|
| 426 | !-- second time for vg. We compute ug and vg at the first call |
---|
[3779] | 427 | !-- and keep both of them around for the second call. |
---|
[3395] | 428 | CASE ( 'geostrophic winds' ) |
---|
| 429 | |
---|
| 430 | IF (.NOT. ug_vg_have_been_computed ) THEN |
---|
[3866] | 431 | ALLOCATE( ug_palm(output_var%grid%nz) ) |
---|
| 432 | ALLOCATE( vg_palm(output_var%grid%nz) ) |
---|
| 433 | ALLOCATE( ug_cosmo(cosmo_grid%nz) ) |
---|
| 434 | ALLOCATE( vg_cosmo(cosmo_grid%nz) ) |
---|
[3395] | 435 | |
---|
[3866] | 436 | IF ( cfg%ug_defined_by_user ) THEN |
---|
| 437 | ug_palm = cfg%ug |
---|
| 438 | vg_palm = cfg%vg |
---|
[3395] | 439 | ELSE |
---|
[3557] | 440 | CALL geostrophic_winds( p_north, p_south, p_east, & |
---|
| 441 | p_west, rho_centre, f3, & |
---|
| 442 | averaging_width_ew, & |
---|
| 443 | averaging_width_ns, & |
---|
| 444 | phi_n, lambda_n, & |
---|
| 445 | phi_centre, lam_centre, & |
---|
[3779] | 446 | ug_cosmo, vg_cosmo ) |
---|
| 447 | |
---|
| 448 | CALL interpolate_1d( ug_cosmo, ug_palm, & |
---|
[3866] | 449 | output_var%grid ) |
---|
[3779] | 450 | |
---|
| 451 | CALL interpolate_1d( vg_cosmo, vg_palm, & |
---|
[3866] | 452 | output_var%grid ) |
---|
[3785] | 453 | ENDIF |
---|
[3395] | 454 | |
---|
| 455 | ug_vg_have_been_computed = .TRUE. |
---|
| 456 | |
---|
[3785] | 457 | ENDIF |
---|
[3395] | 458 | |
---|
[3557] | 459 | ! |
---|
[3779] | 460 | !-- Select output array of current geostrophic wind component |
---|
[3866] | 461 | SELECT CASE( TRIM( output_var%name ) ) |
---|
| 462 | CASE ( 'ls_forcing_ug' ) |
---|
[3779] | 463 | ug_vg_palm => ug_palm |
---|
[3866] | 464 | CASE ( 'ls_forcing_vg' ) |
---|
[3779] | 465 | ug_vg_palm => vg_palm |
---|
[3395] | 466 | END SELECT |
---|
| 467 | |
---|
[3866] | 468 | ALLOCATE( output_arr(1,1,output_var%grid%nz) ) |
---|
[3779] | 469 | output_arr(1,1,:) = ug_vg_palm(:) |
---|
[3395] | 470 | |
---|
[3866] | 471 | !-- User defined constant profiles |
---|
[3182] | 472 | CASE ( 'set profile' ) |
---|
[2696] | 473 | |
---|
[3866] | 474 | ALLOCATE( output_arr(1,1,1:nz) ) |
---|
| 475 | CALL log_runtime( 'time', 'alloc' ) |
---|
[2696] | 476 | |
---|
[3866] | 477 | SELECT CASE ( TRIM( output_var%name ) ) |
---|
[2696] | 478 | |
---|
[3866] | 479 | CASE ( 'nudging_tau' ) |
---|
[3182] | 480 | output_arr(1, 1, :) = NUDGING_TAU |
---|
| 481 | |
---|
[2696] | 482 | CASE DEFAULT |
---|
[3866] | 483 | message = "'" // TRIM( output_var%name ) // & |
---|
| 484 | "' is not a valid '" // TRIM( output_var%kind ) //& |
---|
[2696] | 485 | "' variable kind." |
---|
[3866] | 486 | CALL inifor_abort( 'main loop', message ) |
---|
[2696] | 487 | END SELECT |
---|
[3866] | 488 | CALL log_runtime( 'time', 'comp' ) |
---|
[2696] | 489 | |
---|
| 490 | CASE DEFAULT |
---|
[3866] | 491 | message = "Processing task '" // TRIM( output_var%task ) //& |
---|
[2696] | 492 | "' not recognized." |
---|
[3866] | 493 | CALL inifor_abort( '', message ) |
---|
[2696] | 494 | |
---|
| 495 | END SELECT |
---|
[3866] | 496 | CALL log_runtime( 'time', 'comp' ) |
---|
[2696] | 497 | |
---|
| 498 | !------------------------------------------------------------------------------ |
---|
| 499 | !- Section 2.3: Write current time step of current variable |
---|
| 500 | !------------------------------------------------------------------------------ |
---|
[3779] | 501 | ! |
---|
| 502 | !-- Output of geostrophic pressure profiles (with --debug |
---|
| 503 | !-- option) is currently deactivated, since they are now |
---|
| 504 | !-- defined on averaged COSMO levels instead of PALM levels |
---|
| 505 | !-- (requires definiton of COSMO levels in netCDF output.) |
---|
[3866] | 506 | !IF (.NOT. output_var%is_internal .OR. debugging_output) THEN |
---|
[3779] | 507 | |
---|
[3866] | 508 | IF ( .NOT. output_var%is_internal ) THEN |
---|
| 509 | message = "Writing variable '" // TRIM( output_var%name ) // "'." |
---|
| 510 | CALL report( 'main loop', message ) |
---|
| 511 | CALL update_output( output_var, output_arr, iter, & |
---|
| 512 | output_file, cfg ) |
---|
| 513 | CALL log_runtime( 'time', 'write' ) |
---|
[3785] | 514 | ENDIF |
---|
[2696] | 515 | |
---|
[3866] | 516 | IF ( ALLOCATED( output_arr ) ) DEALLOCATE( output_arr ) |
---|
| 517 | CALL log_runtime( 'time', 'alloc' ) |
---|
[2696] | 518 | |
---|
[3785] | 519 | ENDIF |
---|
[2696] | 520 | |
---|
[3557] | 521 | ! |
---|
| 522 | !-- output variable loop |
---|
[3785] | 523 | ENDDO |
---|
[2696] | 524 | |
---|
[3401] | 525 | ug_vg_have_been_computed = .FALSE. |
---|
[3866] | 526 | IF ( group%kind == 'thermodynamics' ) THEN |
---|
[3395] | 527 | DEALLOCATE( rho_centre ) |
---|
[3779] | 528 | DEALLOCATE( ug_palm ) |
---|
| 529 | DEALLOCATE( vg_palm ) |
---|
| 530 | DEALLOCATE( ug_cosmo ) |
---|
| 531 | DEALLOCATE( vg_cosmo ) |
---|
[3866] | 532 | IF ( .NOT. cfg%ug_defined_by_user ) THEN |
---|
[3395] | 533 | DEALLOCATE( rho_north ) |
---|
| 534 | DEALLOCATE( rho_south ) |
---|
| 535 | DEALLOCATE( rho_east ) |
---|
| 536 | DEALLOCATE( rho_west ) |
---|
| 537 | DEALLOCATE( p_north ) |
---|
| 538 | DEALLOCATE( p_south ) |
---|
| 539 | DEALLOCATE( p_east ) |
---|
| 540 | DEALLOCATE( p_west ) |
---|
[3785] | 541 | ENDIF |
---|
| 542 | ENDIF |
---|
[3395] | 543 | |
---|
[3557] | 544 | ! |
---|
| 545 | !-- Keep input buffer around for averaged (radiation) and |
---|
| 546 | !-- accumulated COSMO quantities (precipitation). |
---|
[3866] | 547 | IF ( group%kind == 'running average' .OR. & |
---|
| 548 | group%kind == 'accumulated' ) THEN |
---|
[2696] | 549 | ELSE |
---|
[3866] | 550 | CALL report( 'main loop', 'Deallocating input buffer', cfg%debug ) |
---|
| 551 | DEALLOCATE( input_buffer ) |
---|
[3785] | 552 | ENDIF |
---|
[3866] | 553 | CALL log_runtime( 'time', 'alloc' ) |
---|
[2696] | 554 | |
---|
[3557] | 555 | ! |
---|
| 556 | !-- time steps / input files loop |
---|
[3785] | 557 | ENDDO |
---|
[2696] | 558 | |
---|
[3866] | 559 | IF ( ALLOCATED( input_buffer ) ) THEN |
---|
| 560 | CALL report( 'main loop', 'Deallocating input buffer', cfg%debug ) |
---|
| 561 | DEALLOCATE( input_buffer ) |
---|
[3785] | 562 | ENDIF |
---|
[3866] | 563 | CALL log_runtime( 'time', 'alloc' ) |
---|
[2696] | 564 | |
---|
| 565 | ELSE |
---|
| 566 | |
---|
[3866] | 567 | message = "Skipping IO group " // TRIM( str( igroup ) ) // " '" // TRIM( group%kind ) // "'" |
---|
| 568 | IF ( ALLOCATED( group%in_var_list ) ) THEN |
---|
| 569 | message = TRIM( message ) // " with input variable '" // & |
---|
| 570 | TRIM( group%in_var_list(1)%name ) // "'." |
---|
[3785] | 571 | ENDIF |
---|
[2696] | 572 | |
---|
[3866] | 573 | CALL report( 'main loop', message, cfg%debug ) |
---|
[2696] | 574 | |
---|
[3557] | 575 | ! |
---|
[3866] | 576 | !-- IO group%to_be_processed conditional |
---|
[3785] | 577 | ENDIF |
---|
[2696] | 578 | |
---|
[3557] | 579 | ! |
---|
| 580 | !-- IO groups loop |
---|
[3785] | 581 | ENDDO |
---|
[2696] | 582 | |
---|
| 583 | !------------------------------------------------------------------------------ |
---|
| 584 | !- Section 3: Clean up. |
---|
| 585 | !------------------------------------------------------------------------------ |
---|
[3866] | 586 | CALL fini_file_lists |
---|
| 587 | CALL fini_io_groups |
---|
| 588 | CALL fini_variables |
---|
| 589 | !CALL fini_grids |
---|
| 590 | CALL log_runtime( 'time', 'alloc' ) |
---|
| 591 | CALL log_runtime( 'report', 'void' ) |
---|
[2696] | 592 | |
---|
[3997] | 593 | message = "Finished writing dynamic driver '" // TRIM( output_file%name ) |
---|
| 594 | |
---|
| 595 | IF ( n_wrngs > 0 ) THEN |
---|
| 596 | message = TRIM( message ) // "' with " // TRIM( str( n_wrngs ) ) // & |
---|
| 597 | " warning(s). Please see logfile '" // LOG_FILE_NAME // "'." |
---|
| 598 | ELSE |
---|
| 599 | message = TRIM( message ) // "' successfully." |
---|
| 600 | END IF |
---|
| 601 | |
---|
[3866] | 602 | CALL report( 'main loop', message ) |
---|
| 603 | CALL close_log |
---|
[2696] | 604 | |
---|
[3866] | 605 | #else |
---|
[2696] | 606 | |
---|
[3866] | 607 | USE inifor_control |
---|
| 608 | IMPLICIT NONE |
---|
| 609 | |
---|
| 610 | message = "INIFOR was compiled without netCDF support, which is required for it to run. " // & |
---|
| 611 | "To use INIFOR, recompile PALM with netCDF support by adding the -D__netcdf " // & |
---|
| 612 | "precompiler flag to your .palm.config file." |
---|
| 613 | CALL inifor_abort( 'main loop', message ) |
---|
| 614 | |
---|
[3680] | 615 | #endif |
---|
[3866] | 616 | |
---|
[2696] | 617 | END PROGRAM inifor |
---|