source: palm/trunk/SOURCE/check_parameters.f90 @ 4633

Last change on this file since 4633 was 4633, checked in by suehring, 4 years ago

Biomet: bugfix in check for humidity

  • Property svn:keywords set to Id
  • Property svn:mergeinfo set to (toggle deleted branches)
    /palm/branches/chemistry/SOURCE/check_parameters.f902047-3190,​3218-3297
    /palm/branches/rans/SOURCE/check_parameters.f902078-3128
    /palm/branches/resler/SOURCE/check_parameters.f902023-4492
    /palm/branches/salsa/SOURCE/check_parameters.f902503-3581
    /palm/branches/forwind/SOURCE/check_parameters.f901564-1913
    /palm/branches/mosaik_M2/check_parameters.f902360-3471
    /palm/branches/palm4u/SOURCE/check_parameters.f902540-2692
File size: 139.6 KB
Line 
1!> @file check_parameters.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: check_parameters.f90 4633 2020-08-05 14:21:14Z suehring $
26! todo added
27!
28! 4565 2020-06-15 08:30:38Z oliver.maas
29! added check for pt_surface_heating_rate
30!
31! 4564 2020-06-12 14:03:36Z raasch
32! Vertical nesting method of Huq et al. (2019) removed
33!
34! 4562 2020-06-12 08:38:47Z raasch
35! bugfix: revised error message for exceeding allow number of time series
36!
37! 4559 2020-06-11 08:51:48Z raasch
38! file re-formatted to follow the PALM coding standard
39!
40! 4536 2020-05-17 17:24:13Z raasch
41! unneccessary query for restart data format removed
42!
43! 4534 2020-05-14 18:35:22Z raasch
44! adjustments for I/O on reduced number of cores using shared memory MPI
45!
46! 4514 2020-04-30 16:29:59Z suehring
47! Enable output of qsurf and ssurf
48!
49! 4513 2020-04-30 13:45:47Z raasch
50! unused modules removed
51!
52! 4511 2020-04-30 12:20:40Z raasch
53! call of chem_boundary_conds removed (respective settings are now done in the chemistry module)
54!
55! 4495 2020-04-13 20:11:20Z raasch
56! check new restart_data_format parameters
57!
58! 4493 2020-04-10 09:49:43Z pavelkrc
59! Kolmogorov length scale eta added to profile output
60!
61! 4444 2020-03-05 15:59:50Z raasch
62! bugfix: cpp-directives for serial mode added
63!
64! 4392 2020-01-31 16:14:57Z pavelkrc
65! Some error numbers revised to prevent double usage
66!
67! 11:55:33Z oliver.maas
68! Checks for closed channel flow implemented
69!
70! 11:55:33Z oliver.maas
71! Move 2-m potential temperature output to diagnostic_output_quantities
72!
73! 11:55:33Z oliver.maas
74! removed message PA0421, concerning old parameter recycling_yshift
75!
76! 11:55:33Z oliver.maas
77! adjust message to the modified parameter recycling_yshift
78!
79! 11:55:33Z oliver.maas
80! Check if a cross section is specified if any output cross-section quantity
81! is given
82!
83! 11:55:33Z oliver.maas
84! Overwrite rotation_angle from namelist by value from static driver
85!
86! 11:55:33Z oliver.maas
87! removed conversion from recycle_absolute_quantities to raq, added check and
88! error message for correct input of recycling_method_for_thermodynamic_quantities
89!
90! 11:55:33Z oliver.maas
91! Corrected "Former revisions" section
92!
93! 11:55:33Z oliver.maas
94! bugfix error message: replaced PA184 by PA0184
95!
96! 11:55:33Z oliver.maas
97! added conversion from recycle_absolute_quantities to raq for recycling of
98! absolute quantities and added error message PA184 for not implemented quantities
99!
100! 4142 2019-08-05 12:38:31Z suehring
101! Consider spinup in number of output timesteps for averaged 2D output (merge
102! from branch resler).
103!
104! 4069 2019-07-01 14:05:51Z Giersch
105! Masked output running index mid has been introduced as a local variable to
106! avoid runtime error (Loop variable has been modified) in time_integration
107!
108! 4048 2019-06-21 21:00:21Z knoop
109! Moved tcm_check_data_output to module_interface
110!
111! 4039 2019-06-18 10:32:41Z suehring
112! Modularize diagnostic output
113!
114! 4017 2019-06-06 12:16:46Z schwenkel
115! output of turbulence intensity added
116!
117! 3933 2019-04-25 12:33:20Z kanani
118! Alphabetical resorting in CASE, condense settings for theta_2m* into one IF clause
119!
120! 3885 2019-04-11 11:29:34Z kanani
121! Changes related to global restructuring of location messages and introduction
122! of additional debug messages
123!
124! 3766 2019-02-26 16:23:41Z raasch
125! trim added to avoid truncation compiler warnings
126!
127! 3761 2019-02-25 15:31:42Z raasch
128! unused variables removed
129!
130! 3735 2019-02-12 09:52:40Z dom_dwd_user
131! Passing variable j (averaged output?) to
132! module_interface.f90:chem_check_data_output.
133!
134! 3705 2019-01-29 19:56:39Z suehring
135! bugfix: renamed thetav_t to vtheta_t
136!
137! 3702 2019-01-28 13:19:30Z gronemeier
138! most_method removed
139!
140! 3655 2019-01-07 16:51:22Z knoop
141! Formatting
142!
143! Revision 1.1  1997/08/26 06:29:23  raasch
144! Initial revision
145!
146!
147! Description:
148! ------------
149!> Check control parameters and deduce further quantities.
150!
151!> @todo Increase character length of unit and corresponding characters to LEN>=8 in order to allow
152!>       units like degree_C (05.08.2020)
153!--------------------------------------------------------------------------------------------------!
154 SUBROUTINE check_parameters
155
156
157    USE arrays_3d
158
159    USE basic_constants_and_equations_mod
160
161    USE bulk_cloud_model_mod,                                                                      &
162        ONLY:  bulk_cloud_model
163
164    USE control_parameters
165
166    USE grid_variables
167
168    USE kinds
169
170    USE indices
171
172    USE model_1d_mod,                                                                              &
173        ONLY:  damp_level_1d, damp_level_ind_1d
174
175    USE module_interface,                                                                          &
176        ONLY:  module_interface_check_data_output,                                                 &
177               module_interface_check_data_output_pr,                                              &
178               module_interface_check_data_output_ts,                                              &
179               module_interface_check_parameters
180
181    USE netcdf_data_input_mod,                                                                     &
182        ONLY:  init_model, input_pids_static, netcdf_data_input_check_dynamic,                     &
183               netcdf_data_input_check_static
184
185    USE netcdf_interface,                                                                          &
186        ONLY:  do2d_unit, do3d_unit, dopr_unit, dots_label, dots_max, dots_num, dots_unit,         &
187               heatflux_output_unit, momentumflux_output_unit, netcdf_data_format,                 &
188               netcdf_data_format_string, waterflux_output_unit
189
190    USE particle_attributes,                                                                       &
191        ONLY:  particle_advection, use_sgs_for_particles
192
193    USE pegrid
194
195    USE pmc_interface,                                                                             &
196        ONLY:  cpl_id, nested_run
197
198    USE profil_parameter
199
200    USE statistics
201
202    USE subsidence_mod
203
204    USE transpose_indices
205
206    IMPLICIT NONE
207
208    CHARACTER (LEN=varnamelength)  ::  var           !< variable name
209    CHARACTER (LEN=7)   ::  unit                     !< unit of variable
210    CHARACTER (LEN=8)   ::  date                     !< current date string
211    CHARACTER (LEN=10)  ::  time                     !< current time string
212    CHARACTER (LEN=20)  ::  ensemble_string          !< string containing number of ensemble member
213    CHARACTER (LEN=15)  ::  nest_string              !< string containing id of nested domain
214    CHARACTER (LEN=40)  ::  coupling_string          !< string containing type of coupling
215    CHARACTER (LEN=100) ::  action                   !< flag string
216
217    INTEGER(iwp) ::  i                               !< loop index
218    INTEGER(iwp) ::  ilen                            !< string length
219    INTEGER(iwp) ::  j                               !< loop index
220    INTEGER(iwp) ::  k                               !< loop index
221    INTEGER(iwp) ::  kk                              !< loop index
222    INTEGER(iwp) ::  mid                             !< masked output running index
223    INTEGER(iwp) ::  netcdf_data_format_save         !< initial value of netcdf_data_format
224    INTEGER(iwp) ::  position                        !< index position of string
225
226    LOGICAL     ::  found                            !< flag, true if output variable is already marked for averaging
227
228    REAL(wp)    ::  gradient                         !< local gradient
229#if defined( __parallel )
230    REAL(wp)    ::  dt_spinup_max                    !< maximum spinup timestep in nested domains
231    REAL(wp)    ::  remote = 0.0_wp                  !< MPI id of remote processor
232    REAL(wp)    ::  spinup_time_max                  !< maximum spinup time in nested domains
233    REAL(wp)    ::  time_to_be_simulated_from_reference_point  !< time to be simulated from reference point
234#endif
235
236
237    CALL location_message( 'checking parameters', 'start' )
238!
239!-- At first, check static and dynamic input for consistency.
240    CALL netcdf_data_input_check_dynamic
241    CALL netcdf_data_input_check_static
242!
243!-- Check for overlap combinations, which are not realized yet
244    IF ( transpose_compute_overlap  .AND. numprocs == 1 )  THEN
245          message_string = 'transpose-compute-overlap not implemented for single PE runs'
246          CALL message( 'check_parameters', 'PA0000', 1, 2, 0, 6, 0 )
247    ENDIF
248
249!
250!-- Check the coupling mode
251    IF ( coupling_mode /= 'uncoupled'            .AND.                                             &
252         coupling_mode /= 'precursor_atmos'      .AND.                                             &
253         coupling_mode /= 'precursor_ocean'      .AND.                                             &
254         coupling_mode /= 'atmosphere_to_ocean'  .AND.                                             &
255         coupling_mode /= 'ocean_to_atmosphere' )  THEN
256       message_string = 'illegal coupling mode: ' // TRIM( coupling_mode )
257       CALL message( 'check_parameters', 'PA0002', 1, 2, 0, 6, 0 )
258    ENDIF
259
260!
261!-- Check if humidity is set to .TRUE. in case of the atmospheric run (for coupled runs)
262    IF ( coupling_mode == 'atmosphere_to_ocean' .AND. .NOT. humidity) THEN
263       message_string = ' Humidity has to be set to .T. in the _p3d file ' //                      &
264                        'for coupled runs between ocean and atmosphere.'
265       CALL message( 'check_parameters', 'PA0476', 1, 2, 0, 6, 0 )
266    ENDIF
267
268!
269!-- Check and set the restart data format variables
270    IF ( TRIM( restart_data_format ) /= 'fortran_binary'  .AND.                                    &
271         TRIM( restart_data_format ) /= 'mpi'             .AND.                                    &
272         TRIM( restart_data_format ) /= 'mpi_shared_memory' )  THEN
273       message_string = 'illegal restart data format "' // TRIM( restart_data_format ) // '"'
274       CALL message( 'check_parameters', 'PA0724', 1, 2, 0, 6, 0 )
275    ENDIF
276
277    IF ( TRIM( restart_data_format_input ) == 'undefined' )  THEN
278       restart_data_format_input = restart_data_format
279    ENDIF
280    IF ( TRIM( restart_data_format_output ) == 'undefined' )  THEN
281       restart_data_format_output = restart_data_format
282    ENDIF
283
284    IF ( TRIM( restart_data_format_input ) /= 'fortran_binary'  .AND.                              &
285         TRIM( restart_data_format_input ) /= 'mpi'             .AND.                              &
286         TRIM( restart_data_format_input ) /= 'mpi_shared_memory' )  THEN
287       message_string = 'illegal restart input data format "' //                                   &
288                        TRIM( restart_data_format_input ) // '"'
289       CALL message( 'check_parameters', 'PA0725', 1, 2, 0, 6, 0 )
290    ENDIF
291    IF ( TRIM( restart_data_format_output ) /= 'fortran_binary'  .AND.                             &
292         TRIM( restart_data_format_output ) /= 'mpi'             .AND.                             &
293         TRIM( restart_data_format_output ) /= 'mpi_shared_memory' )  THEN
294       message_string = 'illegal restart output data format "' //                                  &
295                        TRIM( restart_data_format_output ) // '"'
296       CALL message( 'check_parameters', 'PA0726', 1, 2, 0, 6, 0 )
297    ENDIF
298
299!
300!-- Set flag for including total domain boundaries in the restart data (MPI-IO) in case of
301!-- non-cyclic boundary conditions
302    include_total_domain_boundaries = .NOT. ( bc_lr_cyc  .AND.  bc_ns_cyc )
303
304!
305!-- Check dt_coupling, restart_time, dt_restart, end_time, dx, dy, nx and ny
306    IF ( coupling_mode /= 'uncoupled'        .AND.                                                 &
307         coupling_mode /= 'precursor_atmos'  .AND.                                                 &
308         coupling_mode /= 'precursor_ocean' )  THEN
309
310       IF ( dt_coupling == 9999999.9_wp )  THEN
311          message_string = 'dt_coupling is not set but required for coupling mode "' //            &
312                           TRIM( coupling_mode ) // '"'
313          CALL message( 'check_parameters', 'PA0003', 1, 2, 0, 6, 0 )
314       ENDIF
315
316#if defined( __parallel )
317
318
319       IF ( myid == 0 ) THEN
320          CALL MPI_SEND( dt_coupling, 1, MPI_REAL, target_id, 11, comm_inter, ierr )
321          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 11, comm_inter, status, ierr )
322       ENDIF
323       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
324
325       IF ( dt_coupling /= remote )  THEN
326          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ), '": dt_coupling = ',&
327                 dt_coupling, '& is not equal to ', 'dt_coupling_remote = ', remote
328          CALL message( 'check_parameters', 'PA0004', 1, 2, 0, 6, 0 )
329       ENDIF
330       IF ( dt_coupling <= 0.0_wp )  THEN
331
332          IF ( myid == 0  ) THEN
333             CALL MPI_SEND( dt_max, 1, MPI_REAL, target_id, 19, comm_inter, ierr )
334             CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 19, comm_inter, status, ierr )
335          ENDIF
336          CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
337
338          dt_coupling = MAX( dt_max, remote )
339          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                     &
340                 '": dt_coupling <= 0.0 & is not allowed and is reset to ', 'MAX(dt_max(A,O)) = ', &
341                 dt_coupling
342          CALL message( 'check_parameters', 'PA0005', 0, 1, 0, 6, 0 )
343       ENDIF
344
345       IF ( myid == 0 ) THEN
346          CALL MPI_SEND( restart_time, 1, MPI_REAL, target_id, 12, comm_inter, ierr )
347          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 12, comm_inter, status, ierr )
348       ENDIF
349       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
350
351       IF ( restart_time /= remote )  THEN
352          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                     &
353                 '": restart_time = ', restart_time, '& is not equal to ',                         &
354                 'restart_time_remote = ', remote
355          CALL message( 'check_parameters', 'PA0006', 1, 2, 0, 6, 0 )
356       ENDIF
357
358       IF ( myid == 0 ) THEN
359          CALL MPI_SEND( dt_restart, 1, MPI_REAL, target_id, 13, comm_inter, ierr )
360          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 13, comm_inter, status, ierr )
361       ENDIF
362       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
363
364       IF ( dt_restart /= remote )  THEN
365          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ), '": dt_restart = ', &
366                 dt_restart, '& is not equal to ', 'dt_restart_remote = ', remote
367          CALL message( 'check_parameters', 'PA0007', 1, 2, 0, 6, 0 )
368       ENDIF
369
370       time_to_be_simulated_from_reference_point = end_time-coupling_start_time
371
372       IF ( myid == 0 ) THEN
373          CALL MPI_SEND( time_to_be_simulated_from_reference_point, 1, MPI_REAL, target_id, 14,    &
374                         comm_inter, ierr )
375          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 14, comm_inter, status, ierr )
376       ENDIF
377       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
378
379       IF ( time_to_be_simulated_from_reference_point /= remote )  THEN
380          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                     &
381                 '": time_to_be_simulated_from_reference_point = ',                                &
382                 time_to_be_simulated_from_reference_point, '& is not equal ',                     &
383                 'to time_to_be_simulated_from_reference_point_remote = ',                         &
384                 remote
385          CALL message( 'check_parameters', 'PA0008', 1, 2, 0, 6, 0 )
386       ENDIF
387
388       IF ( myid == 0 ) THEN
389          CALL MPI_SEND( dx, 1, MPI_REAL, target_id, 15, comm_inter, ierr )
390          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 15, comm_inter, status, ierr )
391       ENDIF
392       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
393
394
395       IF ( coupling_mode == 'atmosphere_to_ocean') THEN
396
397          IF ( dx < remote ) THEN
398             WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                  &
399                    '": dx in Atmosphere is not equal to or not larger than dx in ocean'
400             CALL message( 'check_parameters', 'PA0009', 1, 2, 0, 6, 0 )
401          ENDIF
402
403          IF ( (nx_a+1)*dx /= (nx_o+1)*remote )  THEN
404             WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                  &
405                    '": Domain size in x-direction is not equal in ocean and atmosphere'
406             CALL message( 'check_parameters', 'PA0010', 1, 2, 0, 6, 0 )
407          ENDIF
408
409       ENDIF
410
411       IF ( myid == 0) THEN
412          CALL MPI_SEND( dy, 1, MPI_REAL, target_id, 16, comm_inter, ierr )
413          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 16, comm_inter, status, ierr )
414       ENDIF
415       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
416
417       IF ( coupling_mode == 'atmosphere_to_ocean') THEN
418
419          IF ( dy < remote )  THEN
420             WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                  &
421                    '": dy in Atmosphere is not equal to or not larger than dy in ocean'
422             CALL message( 'check_parameters', 'PA0011', 1, 2, 0, 6, 0 )
423          ENDIF
424
425          IF ( (ny_a+1)*dy /= (ny_o+1)*remote )  THEN
426             WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                  &
427                    '": Domain size in y-direction is not equal in ocean and atmosphere'
428             CALL message( 'check_parameters', 'PA0012', 1, 2, 0, 6, 0 )
429          ENDIF
430
431          IF ( MOD( nx_o+1, nx_a+1 ) /= 0 )  THEN
432             WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                  &
433                    '": nx+1 in ocean is not divisible by nx+1 in', ' atmosphere without remainder'
434             CALL message( 'check_parameters', 'PA0339', 1, 2, 0, 6, 0 )
435          ENDIF
436
437          IF ( MOD(ny_o+1,ny_a+1) /= 0 )  THEN
438             WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ),                  &
439                    '": ny+1 in ocean is not divisible by ny+1 in', ' atmosphere without remainder'
440
441             CALL message( 'check_parameters', 'PA0340', 1, 2, 0, 6, 0 )
442          ENDIF
443
444       ENDIF
445#else
446       WRITE( message_string, * ) 'coupling requires PALM to be compiled with',                    &
447              ' cpp-option "-D__parallel"'
448       CALL message( 'check_parameters', 'PA0141', 1, 2, 0, 6, 0 )
449#endif
450    ENDIF
451
452#if defined( __parallel )
453!
454!-- Exchange via intercommunicator
455    IF ( coupling_mode == 'atmosphere_to_ocean'  .AND.  myid == 0 )  THEN
456       CALL MPI_SEND( humidity, 1, MPI_LOGICAL, target_id, 19, comm_inter, ierr )
457    ELSEIF ( coupling_mode == 'ocean_to_atmosphere'  .AND.  myid == 0)  THEN
458       CALL MPI_RECV( humidity_remote, 1, MPI_LOGICAL, target_id, 19, comm_inter, status, ierr )
459    ENDIF
460    CALL MPI_BCAST( humidity_remote, 1, MPI_LOGICAL, 0, comm2d, ierr)
461
462#endif
463
464!
465!-- User settings for restart times requires that "restart" has been given as file activation
466!-- string. Otherwise, binary output would not be saved by palmrun.
467    IF ( ( restart_time /= 9999999.9_wp  .OR.  dt_restart /= 9999999.9_wp )                        &
468         .AND.  .NOT. write_binary )  THEN
469       WRITE( message_string, * ) 'manual restart settings requires file ',                        &
470                                  'activation string "restart"'
471       CALL message( 'check_parameters', 'PA0001', 1, 2, 0, 6, 0 )
472    ENDIF
473
474
475!
476!-- Generate the file header which is used as a header for most of PALM's output files
477    CALL DATE_AND_TIME( date, time, run_zone )
478    run_date = date(1:4) // '-' // date(5:6) // '-' // date(7:8)
479    run_time = time(1:2) // ':' // time(3:4) // ':' // time(5:6)
480    IF ( coupling_mode == 'uncoupled' )  THEN
481       coupling_string = ''
482    ELSEIF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
483       coupling_string = ' coupled (atmosphere)'
484    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
485       coupling_string = ' coupled (ocean)'
486    ENDIF
487    IF ( ensemble_member_nr /= 0 )  THEN
488       WRITE( ensemble_string, '(2X,A,I2.2)' )  'en-no: ', ensemble_member_nr
489    ELSE
490       ensemble_string = ''
491    ENDIF
492    IF ( nested_run )  THEN
493       WRITE( nest_string, '(2X,A,I2.2)' )  'nest-id: ', cpl_id
494    ELSE
495       nest_string = ''
496    ENDIF
497
498    WRITE ( run_description_header, '(A,2X,A,2X,A,A,A,I2.2,A,A,A,2X,A,A,2X,A,1X,A)' )              &
499          TRIM( version ), TRIM( revision ), 'run: ', TRIM( run_identifier ), '.', runnr,          &
500          TRIM( coupling_string ), TRIM( nest_string ), TRIM( ensemble_string), 'host: ',          &
501          TRIM( host ), run_date, run_time
502
503!
504!-- Check the general loop optimization method
505    SELECT CASE ( TRIM( loop_optimization ) )
506
507       CASE ( 'cache', 'vector' )
508          CONTINUE
509
510       CASE DEFAULT
511          message_string = 'illegal value given for loop_optimization: "' //                       &
512                           TRIM( loop_optimization ) // '"'
513          CALL message( 'check_parameters', 'PA0013', 1, 2, 0, 6, 0 )
514
515    END SELECT
516
517!
518!-- Check topography setting (check for illegal parameter combinations)
519    IF ( topography /= 'flat' )  THEN
520       action = ' '
521       IF ( scalar_advec /= 'pw-scheme'  .AND.  scalar_advec /= 'ws-scheme' )  THEN
522          WRITE( action, '(A,A)' )  'scalar_advec = ', scalar_advec
523       ENDIF
524       IF ( momentum_advec /= 'pw-scheme'  .AND.  momentum_advec /= 'ws-scheme' )  THEN
525          WRITE( action, '(A,A)' )  'momentum_advec = ', momentum_advec
526       ENDIF
527       IF ( psolver == 'sor' )  THEN
528          WRITE( action, '(A,A)' )  'psolver = ', psolver
529       ENDIF
530       IF ( sloping_surface )  THEN
531          WRITE( action, '(A)' )  'sloping surface = .TRUE.'
532       ENDIF
533       IF ( galilei_transformation )  THEN
534          WRITE( action, '(A)' )  'galilei_transformation = .TRUE.'
535       ENDIF
536       IF ( cloud_droplets )  THEN
537          WRITE( action, '(A)' )  'cloud_droplets = .TRUE.'
538       ENDIF
539       IF ( .NOT. constant_flux_layer  .AND.  topography /= 'closed_channel' )  THEN
540          WRITE( action, '(A)' )  'constant_flux_layer = .FALSE.'
541       ENDIF
542       IF ( action /= ' ' )  THEN
543          message_string = 'The specified topography does not allow ' // TRIM( action )
544          CALL message( 'check_parameters', 'PA0014', 1, 2, 0, 6, 0 )
545       ENDIF
546!
547!--    Check illegal/untested parameter combinations for closed channel
548       If ( topography == 'closed_channel' )  THEN
549          symmetry_flag = 1
550          message_string = 'Bottom and top boundary are treated equal'
551          CALL message( 'check_parameters', 'PA0699', 0, 0, 0, 6, 0 )
552
553          IF ( dz(1) /= dz(COUNT( dz /= -1.0_wp ))  .OR.  dz_stretch_level /= -9999999.9_wp)  THEN
554             WRITE( message_string, * )  'dz should be equal close to the ' //                     &
555                                         'boundaries due to symmetrical problem'
556             CALL message( 'check_parameters', 'PA0700', 1, 2, 0, 6, 0 )
557          ENDIF
558
559          IF ( constant_flux_layer )  THEN
560             WRITE( message_string, * )  'A constant flux layer is not ' //                        &
561                                         'allowed if a closed channel shall be used'
562             CALL message( 'check_parameters', 'PA0701', 1, 2, 0, 6, 0 )
563          ENDIF
564
565          IF ( ocean_mode )  THEN
566             WRITE( message_string, * )  'The ocean mode is not allowed if ' //                    &
567                                         'a closed channel shall be used'
568             CALL message( 'check_parameters', 'PA0702', 1, 2, 0, 6, 0 )
569          ENDIF
570
571          IF ( momentum_advec /= 'ws-scheme'  .OR.                                                 &
572               scalar_advec /= 'ws-scheme' )  THEN
573             WRITE( message_string, * )  'A closed channel require the upwind scheme of Wicker' // &
574                                         ' and Skamarock as the advection scheme'
575             CALL message( 'check_parameters', 'PA0703', 1, 2, 0, 6, 0 )
576          ENDIF
577       ENDIF
578    ENDIF
579
580!
581!-- Check approximation
582    IF ( TRIM( approximation ) /= 'boussinesq'  .AND.  TRIM( approximation ) /= 'anelastic' )  THEN
583       message_string = 'unknown approximation: approximation = "' // TRIM( approximation ) // '"'
584       CALL message( 'check_parameters', 'PA0446', 1, 2, 0, 6, 0 )
585    ENDIF
586
587!
588!-- Check approximation requirements
589    IF ( TRIM( approximation ) == 'anelastic'  .AND.  TRIM( momentum_advec ) /= 'ws-scheme' )  THEN
590       message_string = 'Anelastic approximation requires momentum_advec = "ws-scheme"'
591       CALL message( 'check_parameters', 'PA0447', 1, 2, 0, 6, 0 )
592    ENDIF
593    IF ( TRIM( approximation ) == 'anelastic'  .AND.  TRIM( psolver ) == 'multigrid' )  THEN
594       message_string = 'Anelastic approximation currently only supports psolver = "poisfft", ' // &
595                        'psolver = "sor" and psolver = "multigrid_noopt"'
596       CALL message( 'check_parameters', 'PA0448', 1, 2, 0, 6, 0 )
597    ENDIF
598    IF ( TRIM( approximation ) == 'anelastic'  .AND.  conserve_volume_flow )  THEN
599       message_string = 'Anelastic approximation is not allowed with ' //                          &
600                        'conserve_volume_flow = .TRUE.'
601       CALL message( 'check_parameters', 'PA0449', 1, 2, 0, 6, 0 )
602    ENDIF
603
604!
605!-- Check flux input mode
606    IF ( TRIM( flux_input_mode ) /= 'dynamic'  .AND.  TRIM( flux_input_mode ) /= 'kinematic'       &
607         .AND.  TRIM( flux_input_mode ) /= 'approximation-specific' )  THEN
608       message_string = 'unknown flux input mode: flux_input_mode = "' //                          &
609                        TRIM( flux_input_mode ) // '"'
610       CALL message( 'check_parameters', 'PA0450', 1, 2, 0, 6, 0 )
611    ENDIF
612!
613!-- Set flux input mode according to approximation if applicable
614    IF ( TRIM( flux_input_mode ) == 'approximation-specific' )  THEN
615       IF ( TRIM( approximation ) == 'anelastic' )  THEN
616          flux_input_mode = 'dynamic'
617       ELSEIF ( TRIM( approximation ) == 'boussinesq' )  THEN
618          flux_input_mode = 'kinematic'
619       ENDIF
620    ENDIF
621
622!
623!-- Check flux output mode
624    IF ( TRIM( flux_output_mode ) /= 'dynamic'  .AND.  TRIM( flux_output_mode ) /= 'kinematic'     &
625         .AND.  TRIM( flux_output_mode ) /= 'approximation-specific' )  THEN
626       message_string = 'unknown flux output mode: flux_output_mode = "' //                        &
627                        TRIM( flux_output_mode ) // '"'
628       CALL message( 'check_parameters', 'PA0451', 1, 2, 0, 6, 0 )
629    ENDIF
630!
631!-- Set flux output mode according to approximation if applicable
632    IF ( TRIM( flux_output_mode ) == 'approximation-specific' )  THEN
633       IF ( TRIM( approximation ) == 'anelastic' )  THEN
634          flux_output_mode = 'dynamic'
635       ELSEIF ( TRIM( approximation ) == 'boussinesq' )  THEN
636          flux_output_mode = 'kinematic'
637       ENDIF
638    ENDIF
639
640
641!
642!-- When the land- or urban-surface model is used, the flux output must be dynamic.
643    IF ( land_surface  .OR.  urban_surface )  THEN
644       flux_output_mode = 'dynamic'
645    ENDIF
646
647!
648!-- Set the flux output units according to flux_output_mode
649    IF ( TRIM( flux_output_mode ) == 'kinematic' )  THEN
650        heatflux_output_unit              = 'K m/s'
651        waterflux_output_unit             = 'kg/kg m/s'
652        momentumflux_output_unit          = 'm2/s2'
653    ELSEIF ( TRIM( flux_output_mode ) == 'dynamic' )  THEN
654        heatflux_output_unit              = 'W/m2'
655        waterflux_output_unit             = 'W/m2'
656        momentumflux_output_unit          = 'N/m2'
657    ENDIF
658
659!
660!-- set time series output units for fluxes
661    dots_unit(14:16) = TRIM( heatflux_output_unit )
662    dots_unit(21)    = TRIM( waterflux_output_unit )
663    dots_unit(19:20) = TRIM( momentumflux_output_unit )
664
665!
666!-- Add other module specific timeseries
667    CALL module_interface_check_data_output_ts( dots_max, dots_num, dots_label, dots_unit )
668
669!
670!-- Check if maximum number of allowed timeseries is exceeded
671    IF ( dots_num > dots_max )  THEN
672       WRITE( message_string, * ) 'number of time series quantities exceeds',                      &
673                                  ' its maximum of dots_max = ', dots_max,                         &
674                                  '&Please increase dots_max in netcdf_interface_mod.f90.'
675       CALL message( 'check_parameters', 'PA0194', 1, 2, 0, 6, 0 )
676    ENDIF
677
678!
679!-- Check whether there are any illegal values
680!-- Pressure solver:
681    IF ( psolver /= 'poisfft'  .AND.  psolver /= 'sor'  .AND.  psolver /= 'multigrid'  .AND.       &
682         psolver /= 'multigrid_noopt' )  THEN
683       message_string = 'unknown solver for perturbation pressure: psolver' //                     &
684                        ' = "' // TRIM( psolver ) // '"'
685       CALL message( 'check_parameters', 'PA0016', 1, 2, 0, 6, 0 )
686    ENDIF
687
688    IF ( psolver(1:9) == 'multigrid' )  THEN
689       IF ( cycle_mg == 'w' )  THEN
690          gamma_mg = 2
691       ELSEIF ( cycle_mg == 'v' )  THEN
692          gamma_mg = 1
693       ELSE
694          message_string = 'unknown multigrid cycle: cycle_mg = "' //  TRIM( cycle_mg ) // '"'
695          CALL message( 'check_parameters', 'PA0020', 1, 2, 0, 6, 0 )
696       ENDIF
697    ENDIF
698
699    IF ( fft_method /= 'singleton-algorithm'  .AND.  fft_method /= 'temperton-algorithm'  .AND.    &
700         fft_method /= 'fftw'                 .AND.  fft_method /= 'system-specific' )  THEN
701       message_string = 'unknown fft-algorithm: fft_method = "' // TRIM( fft_method ) // '"'
702       CALL message( 'check_parameters', 'PA0021', 1, 2, 0, 6, 0 )
703    ENDIF
704
705    IF( momentum_advec == 'ws-scheme' .AND.  .NOT. call_psolver_at_all_substeps  ) THEN
706        message_string = 'psolver must be called at each RK3 substep when "'//                     &
707                         TRIM(momentum_advec) // ' "is used for momentum_advec'
708        CALL message( 'check_parameters', 'PA0344', 1, 2, 0, 6, 0 )
709    END IF
710!
711!-- Advection schemes:
712    IF ( momentum_advec /= 'pw-scheme'  .AND.  momentum_advec /= 'ws-scheme'  .AND.                &
713         momentum_advec /= 'up-scheme' )  THEN
714       message_string = 'unknown advection scheme: momentum_advec = "' //                          &
715                        TRIM( momentum_advec ) // '"'
716       CALL message( 'check_parameters', 'PA0022', 1, 2, 0, 6, 0 )
717    ENDIF
718    IF ( ( momentum_advec == 'ws-scheme' .OR. scalar_advec == 'ws-scheme' )                        &
719         .AND. ( timestep_scheme == 'euler' .OR.  timestep_scheme == 'runge-kutta-2' ) )  THEN
720       message_string = 'momentum_advec or scalar_advec = "' // TRIM( momentum_advec ) //          &
721                        '" is not allowed with timestep_scheme = "' //                             &
722                        TRIM( timestep_scheme ) // '"'
723       CALL message( 'check_parameters', 'PA0023', 1, 2, 0, 6, 0 )
724    ENDIF
725    IF ( scalar_advec /= 'pw-scheme'  .AND.  scalar_advec /= 'ws-scheme'  .AND.                    &
726         scalar_advec /= 'bc-scheme'  .AND.  scalar_advec /= 'up-scheme' )  THEN
727       message_string = 'unknown advection scheme: scalar_advec = "' // TRIM( scalar_advec ) // '"'
728       CALL message( 'check_parameters', 'PA0024', 1, 2, 0, 6, 0 )
729    ENDIF
730    IF ( scalar_advec == 'bc-scheme'  .AND.  loop_optimization == 'cache' )  THEN
731       message_string = 'advection_scheme scalar_advec = "' // TRIM( scalar_advec ) //             &
732                        '" not implemented for loop_optimization = "' //                           &
733                        TRIM( loop_optimization ) // '"'
734       CALL message( 'check_parameters', 'PA0026', 1, 2, 0, 6, 0 )
735    ENDIF
736
737    IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets  .AND.  .NOT. use_upstream_for_tke     &
738         .AND.  scalar_advec /= 'ws-scheme' )  THEN
739       use_upstream_for_tke = .TRUE.
740       message_string = 'use_upstream_for_tke is set to .TRUE. because ' //                        &
741                        'use_sgs_for_particles = .TRUE. and scalar_advec /= ws-scheme'
742       CALL message( 'check_parameters', 'PA0025', 0, 1, 0, 6, 0 )
743    ENDIF
744
745!
746!-- Set LOGICAL switches to enhance performance
747    IF ( momentum_advec == 'ws-scheme' )  ws_scheme_mom = .TRUE.
748    IF ( scalar_advec   == 'ws-scheme' )  ws_scheme_sca = .TRUE.
749
750
751!
752!-- Timestep schemes:
753    SELECT CASE ( TRIM( timestep_scheme ) )
754
755       CASE ( 'euler' )
756          intermediate_timestep_count_max = 1
757
758       CASE ( 'runge-kutta-2' )
759          intermediate_timestep_count_max = 2
760
761       CASE ( 'runge-kutta-3' )
762          intermediate_timestep_count_max = 3
763
764       CASE DEFAULT
765          message_string = 'unknown timestep scheme: timestep_scheme = "' //                       &
766                           TRIM( timestep_scheme ) // '"'
767          CALL message( 'check_parameters', 'PA0027', 1, 2, 0, 6, 0 )
768
769    END SELECT
770
771    IF ( ( momentum_advec /= 'pw-scheme' .AND. momentum_advec /= 'ws-scheme' )                     &
772         .AND.  timestep_scheme(1:5) == 'runge' ) THEN
773       message_string = 'momentum advection scheme "' // TRIM( momentum_advec ) //                 &
774                        '" & does not work with timestep_scheme "' // TRIM( timestep_scheme )      &
775                        // '"'
776       CALL message( 'check_parameters', 'PA0029', 1, 2, 0, 6, 0 )
777    ENDIF
778!
779!-- Check for proper settings for microphysics
780    IF ( bulk_cloud_model  .AND.  cloud_droplets )  THEN
781       message_string = 'bulk_cloud_model = .TRUE. is not allowed with cloud_droplets = .TRUE.'
782       CALL message( 'check_parameters', 'PA0442', 1, 2, 0, 6, 0 )
783    ENDIF
784
785!
786!-- Initializing actions must have been set by the user
787    IF ( TRIM( initializing_actions ) == '' )  THEN
788       message_string = 'no value specified for initializing_actions'
789       CALL message( 'check_parameters', 'PA0149', 1, 2, 0, 6, 0 )
790    ENDIF
791
792    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.                                &
793         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
794!
795!--    No restart run: several initialising actions are possible
796       action = initializing_actions
797       DO  WHILE ( TRIM( action ) /= '' )
798          position = INDEX( action, ' ' )
799          SELECT CASE ( action(1:position-1) )
800
801             CASE ( 'set_constant_profiles', 'set_1d-model_profiles', 'by_user',                   &
802                    'initialize_vortex', 'initialize_ptanom', 'initialize_bubble', 'inifor' )
803                action = action(position+1:)
804
805             CASE DEFAULT
806                message_string = 'initializing_action = "' //                                      &
807                                 TRIM( action ) // '" unknown or not allowed'
808                CALL message( 'check_parameters', 'PA0030', 1, 2, 0, 6, 0 )
809
810          END SELECT
811       ENDDO
812    ENDIF
813
814    IF ( TRIM( initializing_actions ) == 'initialize_vortex'  .AND.  conserve_volume_flow ) THEN
815         message_string = 'initializing_actions = "initialize_vortex"' //                          &
816                          ' is not allowed with conserve_volume_flow = .T.'
817       CALL message( 'check_parameters', 'PA0343', 1, 2, 0, 6, 0 )
818    ENDIF
819
820
821    IF ( INDEX( initializing_actions, 'set_constant_profiles' ) /= 0  .AND.                        &
822         INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
823       message_string = 'initializing_actions = "set_constant_profiles"' //                        &
824                        ' and "set_1d-model_profiles" are not allowed simultaneously'
825       CALL message( 'check_parameters', 'PA0031', 1, 2, 0, 6, 0 )
826    ENDIF
827
828    IF ( INDEX( initializing_actions, 'set_constant_profiles' ) /= 0  .AND.                        &
829         INDEX( initializing_actions, 'by_user' ) /= 0 )  THEN
830       message_string = 'initializing_actions = "set_constant_profiles"' //                        &
831                        ' and "by_user" are not allowed simultaneously'
832       CALL message( 'check_parameters', 'PA0032', 1, 2, 0, 6, 0 )
833    ENDIF
834
835    IF ( INDEX( initializing_actions, 'by_user' ) /= 0  .AND.                                      &
836         INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
837       message_string = 'initializing_actions = "by_user" and ' //                                 &
838                        '"set_1d-model_profiles" are not allowed simultaneously'
839       CALL message( 'check_parameters', 'PA0033', 1, 2, 0, 6, 0 )
840    ENDIF
841!
842!-- In case of spinup and nested run, spinup end time must be identical in order to have
843!-- synchronously running simulations.
844    IF ( nested_run )  THEN
845#if defined( __parallel )
846       CALL MPI_ALLREDUCE( spinup_time, spinup_time_max, 1, MPI_REAL, MPI_MAX, MPI_COMM_WORLD,     &
847                           ierr )
848       CALL MPI_ALLREDUCE( dt_spinup,   dt_spinup_max,   1, MPI_REAL, MPI_MAX, MPI_COMM_WORLD,     &
849                           ierr )
850
851       IF ( spinup_time /= spinup_time_max  .OR.  dt_spinup /= dt_spinup_max )  THEN
852          message_string = 'In case of nesting, spinup_time and ' //                               &
853                           'dt_spinup must be identical in all parent and child domains.'
854          CALL message( 'check_parameters', 'PA0489', 3, 2, 0, 6, 0 )
855       ENDIF
856#endif
857    ENDIF
858
859    IF ( bulk_cloud_model  .AND.  .NOT. humidity )  THEN
860       WRITE( message_string, * ) 'bulk_cloud_model = ', bulk_cloud_model,                         &
861              ' is not allowed with humidity = ', humidity
862       CALL message( 'check_parameters', 'PA0034', 1, 2, 0, 6, 0 )
863    ENDIF
864
865    IF ( humidity  .AND.  sloping_surface )  THEN
866       message_string = 'humidity = .TRUE. and sloping_surface = .TRUE. ' //                       &
867                        'are not allowed simultaneously'
868       CALL message( 'check_parameters', 'PA0036', 1, 2, 0, 6, 0 )
869    ENDIF
870
871!-- Check the module settings
872    CALL module_interface_check_parameters
873
874!
875!-- In case of no restart run, check initialising parameters and calculate further quantities
876    IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
877
878!
879!--    Initial profiles for 1D and 3D model, respectively (u,v further below)
880       pt_init = pt_surface
881       IF ( humidity       )  q_init  = q_surface
882       IF ( passive_scalar )  s_init  = s_surface
883
884!--
885!--    If required, compute initial profile of the geostrophic wind (component ug)
886       i = 1
887       gradient = 0.0_wp
888
889       IF ( .NOT. ocean_mode )  THEN
890
891          ug_vertical_gradient_level_ind(1) = 0
892          ug(0) = ug_surface
893          DO  k = 1, nzt+1
894             IF ( i < 11 )  THEN
895                IF ( ug_vertical_gradient_level(i) < zu(k)  .AND.                                  &
896                     ug_vertical_gradient_level(i) >= 0.0_wp )  THEN
897                   gradient = ug_vertical_gradient(i) / 100.0_wp
898                   ug_vertical_gradient_level_ind(i) = k - 1
899                   i = i + 1
900                ENDIF
901             ENDIF
902             IF ( gradient /= 0.0_wp )  THEN
903                IF ( k /= 1 )  THEN
904                   ug(k) = ug(k-1) + dzu(k) * gradient
905                ELSE
906                   ug(k) = ug_surface + dzu(k) * gradient
907                ENDIF
908             ELSE
909                ug(k) = ug(k-1)
910             ENDIF
911          ENDDO
912
913       ELSE
914
915          ug_vertical_gradient_level_ind(1) = nzt+1
916          ug(nzt+1) = ug_surface
917          DO  k = nzt, nzb, -1
918             IF ( i < 11 )  THEN
919                IF ( ug_vertical_gradient_level(i) > zu(k)  .AND.                                  &
920                     ug_vertical_gradient_level(i) <= 0.0_wp )  THEN
921                   gradient = ug_vertical_gradient(i) / 100.0_wp
922                   ug_vertical_gradient_level_ind(i) = k + 1
923                   i = i + 1
924                ENDIF
925             ENDIF
926             IF ( gradient /= 0.0_wp )  THEN
927                IF ( k /= nzt )  THEN
928                   ug(k) = ug(k+1) - dzu(k+1) * gradient
929                ELSE
930                   ug(k)   = ug_surface - 0.5_wp * dzu(k+1) * gradient
931                   ug(k+1) = ug_surface + 0.5_wp * dzu(k+1) * gradient
932                ENDIF
933             ELSE
934                ug(k) = ug(k+1)
935             ENDIF
936          ENDDO
937
938       ENDIF
939
940!
941!--    In case of no given gradients for ug, choose a zero gradient
942       IF ( ug_vertical_gradient_level(1) == -9999999.9_wp )  THEN
943          ug_vertical_gradient_level(1) = 0.0_wp
944       ENDIF
945
946!
947!--
948!--    If required, compute initial profile of the geostrophic wind (component vg)
949       i = 1
950       gradient = 0.0_wp
951
952       IF ( .NOT. ocean_mode )  THEN
953
954          vg_vertical_gradient_level_ind(1) = 0
955          vg(0) = vg_surface
956          DO  k = 1, nzt+1
957             IF ( i < 11 )  THEN
958                IF ( vg_vertical_gradient_level(i) < zu(k)  .AND.                                  &
959                     vg_vertical_gradient_level(i) >= 0.0_wp )  THEN
960                   gradient = vg_vertical_gradient(i) / 100.0_wp
961                   vg_vertical_gradient_level_ind(i) = k - 1
962                   i = i + 1
963                ENDIF
964             ENDIF
965             IF ( gradient /= 0.0_wp )  THEN
966                IF ( k /= 1 )  THEN
967                   vg(k) = vg(k-1) + dzu(k) * gradient
968                ELSE
969                   vg(k) = vg_surface + dzu(k) * gradient
970                ENDIF
971             ELSE
972                vg(k) = vg(k-1)
973             ENDIF
974          ENDDO
975
976       ELSE
977
978          vg_vertical_gradient_level_ind(1) = nzt+1
979          vg(nzt+1) = vg_surface
980          DO  k = nzt, nzb, -1
981             IF ( i < 11 )  THEN
982                IF ( vg_vertical_gradient_level(i) > zu(k)  .AND.                                  &
983                     vg_vertical_gradient_level(i) <= 0.0_wp )  THEN
984                   gradient = vg_vertical_gradient(i) / 100.0_wp
985                   vg_vertical_gradient_level_ind(i) = k + 1
986                   i = i + 1
987                ENDIF
988             ENDIF
989             IF ( gradient /= 0.0_wp )  THEN
990                IF ( k /= nzt )  THEN
991                   vg(k) = vg(k+1) - dzu(k+1) * gradient
992                ELSE
993                   vg(k)   = vg_surface - 0.5_wp * dzu(k+1) * gradient
994                   vg(k+1) = vg_surface + 0.5_wp * dzu(k+1) * gradient
995                ENDIF
996             ELSE
997                vg(k) = vg(k+1)
998             ENDIF
999          ENDDO
1000
1001       ENDIF
1002
1003!
1004!--    In case of no given gradients for vg, choose a zero gradient
1005       IF ( vg_vertical_gradient_level(1) == -9999999.9_wp )  THEN
1006          vg_vertical_gradient_level(1) = 0.0_wp
1007       ENDIF
1008
1009!
1010!--    Let the initial wind profiles be the calculated ug/vg profiles or interpolate them from wind
1011!--    profile data (if given)
1012       IF ( u_profile(1) == 9999999.9_wp  .AND.  v_profile(1) == 9999999.9_wp )  THEN
1013
1014          u_init = ug
1015          v_init = vg
1016
1017       ELSEIF ( u_profile(1) == 0.0_wp  .AND.  v_profile(1) == 0.0_wp )  THEN
1018
1019          IF ( uv_heights(1) /= 0.0_wp )  THEN
1020             message_string = 'uv_heights(1) must be 0.0'
1021             CALL message( 'check_parameters', 'PA0345', 1, 2, 0, 6, 0 )
1022          ENDIF
1023
1024          IF ( omega /= 0.0_wp )  THEN
1025             message_string = 'Coriolis force must be switched off (by setting omega=0.0)' //      &
1026                              ' when prescribing the forcing by u_profile and v_profile'
1027             CALL message( 'check_parameters', 'PA0347', 1, 2, 0, 6, 0 )
1028          ENDIF
1029
1030          use_prescribed_profile_data = .TRUE.
1031
1032          kk = 1
1033          u_init(0) = 0.0_wp
1034          v_init(0) = 0.0_wp
1035
1036          DO  k = 1, nz+1
1037
1038             IF ( kk < 200 )  THEN
1039                DO  WHILE ( uv_heights(kk+1) <= zu(k) )
1040                   kk = kk + 1
1041                   IF ( kk == 200 )  EXIT
1042                ENDDO
1043             ENDIF
1044
1045             IF ( kk < 200  .AND.  uv_heights(kk+1) /= 9999999.9_wp )  THEN
1046                u_init(k) = u_profile(kk) + ( zu(k) - uv_heights(kk) ) /                           &
1047                                            ( uv_heights(kk+1) - uv_heights(kk) ) *                &
1048                                            ( u_profile(kk+1) - u_profile(kk) )
1049                v_init(k) = v_profile(kk) + ( zu(k) - uv_heights(kk) ) /                           &
1050                                            ( uv_heights(kk+1) - uv_heights(kk) ) *                &
1051                                            ( v_profile(kk+1) - v_profile(kk) )
1052             ELSE
1053                u_init(k) = u_profile(kk)
1054                v_init(k) = v_profile(kk)
1055             ENDIF
1056
1057          ENDDO
1058
1059       ELSE
1060
1061          message_string = 'u_profile(1) and v_profile(1) must be 0.0'
1062          CALL message( 'check_parameters', 'PA0346', 1, 2, 0, 6, 0 )
1063
1064       ENDIF
1065
1066!
1067!--    Compute initial temperature profile using the given temperature gradients
1068       IF (  .NOT.  neutral )  THEN
1069          CALL init_vertical_profiles( pt_vertical_gradient_level_ind, pt_vertical_gradient_level, &
1070                                       pt_vertical_gradient, pt_init, pt_surface, bc_pt_t_val )
1071       ENDIF
1072!
1073!--    Compute initial humidity profile using the given humidity gradients
1074       IF ( humidity )  THEN
1075          CALL init_vertical_profiles( q_vertical_gradient_level_ind, q_vertical_gradient_level,   &
1076                                       q_vertical_gradient, q_init, q_surface, bc_q_t_val )
1077       ENDIF
1078!
1079!--    Compute initial scalar profile using the given scalar gradients
1080       IF ( passive_scalar )  THEN
1081          CALL init_vertical_profiles( s_vertical_gradient_level_ind, s_vertical_gradient_level,   &
1082                                       s_vertical_gradient, s_init, s_surface, bc_s_t_val )
1083       ENDIF
1084!
1085!--    TODO
1086!--    Compute initial chemistry profile using the given chemical species gradients
1087!--    Russo: Is done in chem_init --> kanani: Revise
1088
1089    ENDIF
1090
1091!
1092!-- Check if the control parameter use_subsidence_tendencies is used correctly
1093    IF ( use_subsidence_tendencies  .AND.  .NOT.  large_scale_subsidence )  THEN
1094       message_string = 'The usage of use_subsidence_tendencies ' //                               &
1095                        'requires large_scale_subsidence = .T..'
1096       CALL message( 'check_parameters', 'PA0396', 1, 2, 0, 6, 0 )
1097    ELSEIF ( use_subsidence_tendencies  .AND.  .NOT. large_scale_forcing )  THEN
1098       message_string = 'The usage of use_subsidence_tendencies ' //           &
1099                        'requires large_scale_forcing = .T..'
1100       CALL message( 'check_parameters', 'PA0397', 1, 2, 0, 6, 0 )
1101    ENDIF
1102
1103!
1104!-- Initialize large scale subsidence if required
1105    If ( large_scale_subsidence )  THEN
1106       IF ( subs_vertical_gradient_level(1) /= -9999999.9_wp  .AND. .NOT. large_scale_forcing )    &
1107       THEN
1108          CALL init_w_subsidence
1109       ENDIF
1110!
1111!--    In case large_scale_forcing is used, profiles for subsidence velocity are read in from file
1112!--    LSF_DATA
1113
1114       IF ( subs_vertical_gradient_level(1) == -9999999.9_wp  .AND. .NOT. large_scale_forcing )    &
1115       THEN
1116          message_string = 'There is no default large scale vertical velocity profile set. ' //    &
1117                           'Specify the subsidence velocity profile via subs_vertical_gradient' // &
1118                           ' and subs_vertical_gradient_level.'
1119          CALL message( 'check_parameters', 'PA0380', 1, 2, 0, 6, 0 )
1120       ENDIF
1121    ELSE
1122        IF ( subs_vertical_gradient_level(1) /= -9999999.9_wp )  THEN
1123           message_string = 'Enable usage of large scale subsidence by ' //                        &
1124                            'setting large_scale_subsidence = .T..'
1125          CALL message( 'check_parameters', 'PA0381', 1, 2, 0, 6, 0 )
1126        ENDIF
1127    ENDIF
1128
1129!
1130!-- Overwrite parameters from namelist if necessary and compute Coriolis parameter.
1131!-- @todo - move initialization of f and fs to coriolis_mod.
1132    IF ( input_pids_static )  THEN
1133       latitude       = init_model%latitude
1134       longitude      = init_model%longitude
1135       rotation_angle = init_model%rotation_angle
1136    ENDIF
1137
1138    f  = 2.0_wp * omega * SIN( latitude / 180.0_wp * pi )
1139    fs = 2.0_wp * omega * COS( latitude / 180.0_wp * pi )
1140
1141!
1142!-- Check and set buoyancy related parameters and switches
1143    IF ( reference_state == 'horizontal_average' )  THEN
1144       CONTINUE
1145    ELSEIF ( reference_state == 'initial_profile' )  THEN
1146       use_initial_profile_as_reference = .TRUE.
1147    ELSEIF ( reference_state == 'single_value' )  THEN
1148       use_single_reference_value = .TRUE.
1149       IF ( pt_reference == 9999999.9_wp )  pt_reference = pt_surface
1150       vpt_reference = pt_reference * ( 1.0_wp + 0.61_wp * q_surface )
1151    ELSE
1152       message_string = 'illegal value for reference_state: "' // TRIM( reference_state ) // '"'
1153       CALL message( 'check_parameters', 'PA0056', 1, 2, 0, 6, 0 )
1154    ENDIF
1155
1156!
1157!-- In case of a given slope, compute the relevant quantities
1158    IF ( alpha_surface /= 0.0_wp )  THEN
1159       IF ( ABS( alpha_surface ) > 90.0_wp )  THEN
1160          WRITE( message_string, * ) 'ABS( alpha_surface = ', alpha_surface, ' ) must be < 90.0'
1161          CALL message( 'check_parameters', 'PA0043', 1, 2, 0, 6, 0 )
1162       ENDIF
1163       sloping_surface = .TRUE.
1164       cos_alpha_surface = COS( alpha_surface / 180.0_wp * pi )
1165       sin_alpha_surface = SIN( alpha_surface / 180.0_wp * pi )
1166    ENDIF
1167
1168!
1169!-- Check time step and cfl_factor
1170    IF ( dt /= -1.0_wp )  THEN
1171       IF ( dt <= 0.0_wp )  THEN
1172          WRITE( message_string, * ) 'dt = ', dt , ' <= 0.0'
1173          CALL message( 'check_parameters', 'PA0044', 1, 2, 0, 6, 0 )
1174       ENDIF
1175       dt_3d = dt
1176       dt_fixed = .TRUE.
1177    ENDIF
1178
1179    IF ( cfl_factor <= 0.0_wp  .OR.  cfl_factor > 1.0_wp )  THEN
1180       IF ( cfl_factor == -1.0_wp )  THEN
1181          IF ( timestep_scheme == 'runge-kutta-2' )  THEN
1182             cfl_factor = 0.8_wp
1183          ELSEIF ( timestep_scheme == 'runge-kutta-3' )  THEN
1184             cfl_factor = 0.9_wp
1185          ELSE
1186             cfl_factor = 0.9_wp
1187          ENDIF
1188       ELSE
1189          WRITE( message_string, * ) 'cfl_factor = ', cfl_factor,                                  &
1190                 ' out of range &0.0 < cfl_factor <= 1.0 is required'
1191          CALL message( 'check_parameters', 'PA0045', 1, 2, 0, 6, 0 )
1192       ENDIF
1193    ENDIF
1194
1195!
1196!-- Store simulated time at begin
1197    simulated_time_at_begin = simulated_time
1198
1199!
1200!-- Store reference time for coupled runs and change the coupling flag, if ...
1201    IF ( simulated_time == 0.0_wp )  THEN
1202       IF ( coupling_start_time == 0.0_wp )  THEN
1203          time_since_reference_point = 0.0_wp
1204       ELSEIF ( time_since_reference_point < 0.0_wp )  THEN
1205          run_coupled = .FALSE.
1206       ENDIF
1207    ENDIF
1208
1209!
1210!-- Set wind speed in the Galilei-transformed system
1211    IF ( galilei_transformation )  THEN
1212       IF ( use_ug_for_galilei_tr                    .AND.                                         &
1213            ug_vertical_gradient_level(1) == 0.0_wp  .AND.                                         &
1214            ug_vertical_gradient(1)       == 0.0_wp  .AND.                                         &
1215            vg_vertical_gradient_level(1) == 0.0_wp  .AND.                                         &
1216            vg_vertical_gradient(1)       == 0.0_wp )  THEN
1217          u_gtrans = ug_surface * 0.6_wp
1218          v_gtrans = vg_surface * 0.6_wp
1219       ELSEIF ( use_ug_for_galilei_tr  .AND.  ( ug_vertical_gradient_level(1) /= 0.0_wp .OR.       &
1220                                                ug_vertical_gradient(1) /= 0.0_wp ) )  THEN
1221          message_string = 'baroclinity (ug) not allowed simultaneously' //                        &
1222                           ' with galilei transformation'
1223          CALL message( 'check_parameters', 'PA0046', 1, 2, 0, 6, 0 )
1224       ELSEIF ( use_ug_for_galilei_tr  .AND.  ( vg_vertical_gradient_level(1) /= 0.0_wp  .OR.      &
1225                                                vg_vertical_gradient(1) /= 0.0_wp ) )  THEN
1226          message_string = 'baroclinity (vg) not allowed simultaneously' //                        &
1227                           ' with galilei transformation'
1228          CALL message( 'check_parameters', 'PA0047', 1, 2, 0, 6, 0 )
1229       ELSE
1230          message_string = 'variable translation speed used for Galilei-transformation, which ' // &
1231                           'may cause & instabilities in stably stratified regions'
1232          CALL message( 'check_parameters', 'PA0048', 0, 1, 0, 6, 0 )
1233       ENDIF
1234    ENDIF
1235
1236!
1237!-- In case of using a prandtl-layer, calculated (or prescribed) surface fluxes have to be used in
1238!-- the diffusion-terms
1239    IF ( constant_flux_layer )  use_surface_fluxes = .TRUE.
1240
1241!
1242!-- Check boundary conditions and set internal variables:
1243!-- Attention: the lateral boundary conditions have been already checked in parin
1244!
1245!-- Non-cyclic lateral boundaries require the multigrid method and Piascek-Willimas or
1246!-- Wicker - Skamarock advection scheme. Several schemes and tools do not work with non-cyclic
1247!-- boundary conditions.
1248    IF ( bc_lr /= 'cyclic'  .OR.  bc_ns /= 'cyclic' )  THEN
1249       IF ( psolver(1:9) /= 'multigrid' )  THEN
1250          message_string = 'non-cyclic lateral boundaries do not allow ' // 'psolver = "' //       &
1251                           TRIM( psolver ) // '"'
1252          CALL message( 'check_parameters', 'PA0051', 1, 2, 0, 6, 0 )
1253       ENDIF
1254       IF ( momentum_advec /= 'pw-scheme'  .AND.  momentum_advec /= 'ws-scheme' )  THEN
1255
1256          message_string = 'non-cyclic lateral boundaries do not allow momentum_advec = "' //      &
1257                           TRIM( momentum_advec ) // '"'
1258          CALL message( 'check_parameters', 'PA0052', 1, 2, 0, 6, 0 )
1259       ENDIF
1260       IF ( scalar_advec /= 'pw-scheme'  .AND.  scalar_advec /= 'ws-scheme' )  THEN
1261          message_string = 'non-cyclic lateral boundaries do not allow scalar_advec = "' //        &
1262                           TRIM( scalar_advec ) // '"'
1263          CALL message( 'check_parameters', 'PA0053', 1, 2, 0, 6, 0 )
1264       ENDIF
1265       IF ( galilei_transformation )  THEN
1266          message_string = 'non-cyclic lateral boundaries do not allow galilei_transformation = .T.'
1267          CALL message( 'check_parameters', 'PA0054', 1, 2, 0, 6, 0 )
1268       ENDIF
1269    ENDIF
1270
1271!
1272!-- Bottom boundary condition for the turbulent Kinetic energy
1273    IF ( bc_e_b == 'neumann' )  THEN
1274       ibc_e_b = 1
1275    ELSEIF ( bc_e_b == '(u*)**2+neumann' )  THEN
1276       ibc_e_b = 2
1277       IF ( .NOT. constant_flux_layer )  THEN
1278          bc_e_b = 'neumann'
1279          ibc_e_b = 1
1280          message_string = 'boundary condition bc_e_b changed to "' // TRIM( bc_e_b ) // '"'
1281          CALL message( 'check_parameters', 'PA0057', 0, 1, 0, 6, 0 )
1282       ENDIF
1283    ELSE
1284       message_string = 'unknown boundary condition: bc_e_b = "' // TRIM( bc_e_b ) // '"'
1285       CALL message( 'check_parameters', 'PA0058', 1, 2, 0, 6, 0 )
1286    ENDIF
1287
1288!
1289!-- Boundary conditions for perturbation pressure
1290    IF ( bc_p_b == 'dirichlet' )  THEN
1291       ibc_p_b = 0
1292    ELSEIF ( bc_p_b == 'neumann' )  THEN
1293       ibc_p_b = 1
1294    ELSE
1295       message_string = 'unknown boundary condition: bc_p_b = "' // TRIM( bc_p_b ) // '"'
1296       CALL message( 'check_parameters', 'PA0059', 1, 2, 0, 6, 0 )
1297    ENDIF
1298
1299    IF ( bc_p_t == 'dirichlet' )  THEN
1300       ibc_p_t = 0
1301!-- TO_DO: later set bc_p_t to neumann before, in case of nested domain
1302    ELSEIF ( bc_p_t == 'neumann' .OR. bc_p_t == 'nested' )  THEN
1303       ibc_p_t = 1
1304    ELSE
1305       message_string = 'unknown boundary condition: bc_p_t = "' // TRIM( bc_p_t ) // '"'
1306       CALL message( 'check_parameters', 'PA0061', 1, 2, 0, 6, 0 )
1307    ENDIF
1308
1309!
1310!-- Boundary conditions for potential temperature
1311    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
1312       ibc_pt_b = 2
1313    ELSE
1314       IF ( bc_pt_b == 'dirichlet' )  THEN
1315          ibc_pt_b = 0
1316       ELSEIF ( bc_pt_b == 'neumann' )  THEN
1317          ibc_pt_b = 1
1318       ELSE
1319          message_string = 'unknown boundary condition: bc_pt_b = "' // TRIM( bc_pt_b ) // '"'
1320          CALL message( 'check_parameters', 'PA0062', 1, 2, 0, 6, 0 )
1321       ENDIF
1322    ENDIF
1323
1324    IF ( bc_pt_t == 'dirichlet' )  THEN
1325       ibc_pt_t = 0
1326    ELSEIF ( bc_pt_t == 'neumann' )  THEN
1327       ibc_pt_t = 1
1328    ELSEIF ( bc_pt_t == 'initial_gradient' )  THEN
1329       ibc_pt_t = 2
1330    ELSEIF ( bc_pt_t == 'nested'  .OR.  bc_pt_t == 'nesting_offline' )  THEN
1331       ibc_pt_t = 3
1332    ELSE
1333       message_string = 'unknown boundary condition: bc_pt_t = "' // TRIM( bc_pt_t ) // '"'
1334       CALL message( 'check_parameters', 'PA0063', 1, 2, 0, 6, 0 )
1335    ENDIF
1336
1337    IF ( ANY( wall_heatflux /= 0.0_wp )  .AND.  surface_heatflux == 9999999.9_wp )  THEN
1338       message_string = 'wall_heatflux additionally requires setting of surface_heatflux'
1339       CALL message( 'check_parameters', 'PA0443', 1, 2, 0, 6, 0 )
1340    ENDIF
1341
1342!
1343!   This IF clause needs revision, got too complex!!
1344    IF ( surface_heatflux == 9999999.9_wp  )  THEN
1345       constant_heatflux = .FALSE.
1346       IF ( large_scale_forcing  .OR.  land_surface  .OR.  urban_surface )  THEN
1347          IF ( ibc_pt_b == 0 )  THEN
1348             constant_heatflux = .FALSE.
1349          ELSEIF ( ibc_pt_b == 1 )  THEN
1350             constant_heatflux = .TRUE.
1351             surface_heatflux = 0.0_wp
1352          ENDIF
1353       ENDIF
1354    ELSE
1355       constant_heatflux = .TRUE.
1356    ENDIF
1357
1358    IF ( top_heatflux     == 9999999.9_wp )  constant_top_heatflux = .FALSE.
1359
1360    IF ( neutral )  THEN
1361
1362       IF ( surface_heatflux /= 0.0_wp  .AND.  surface_heatflux /= 9999999.9_wp )  THEN
1363          message_string = 'heatflux must not be set for pure neutral flow'
1364          CALL message( 'check_parameters', 'PA0351', 1, 2, 0, 6, 0 )
1365       ENDIF
1366
1367       IF ( top_heatflux /= 0.0_wp  .AND.  top_heatflux /= 9999999.9_wp )  THEN
1368          message_string = 'heatflux must not be set for pure neutral flow'
1369          CALL message( 'check_parameters', 'PA0351', 1, 2, 0, 6, 0 )
1370       ENDIF
1371
1372    ENDIF
1373
1374    IF ( top_momentumflux_u /= 9999999.9_wp  .AND.  top_momentumflux_v /= 9999999.9_wp )  THEN
1375       constant_top_momentumflux = .TRUE.
1376    ELSEIF ( .NOT. ( top_momentumflux_u == 9999999.9_wp  .AND.                                     &
1377           top_momentumflux_v == 9999999.9_wp ) )  THEN
1378       message_string = 'both, top_momentumflux_u AND top_momentumflux_v must be set'
1379       CALL message( 'check_parameters', 'PA0064', 1, 2, 0, 6, 0 )
1380    ENDIF
1381
1382!
1383!-- A given surface temperature implies Dirichlet boundary condition for temperature. In this case
1384!-- specification of a constant heat flux is forbidden.
1385    IF ( ibc_pt_b == 0  .AND.  constant_heatflux  .AND.  surface_heatflux /= 0.0_wp )  THEN
1386       message_string = 'boundary_condition: bc_pt_b = "' // TRIM( bc_pt_b ) //                    &
1387                        '& is not allowed with constant_heatflux = .TRUE.'
1388       CALL message( 'check_parameters', 'PA0065', 1, 2, 0, 6, 0 )
1389    ENDIF
1390    IF ( constant_heatflux  .AND.  pt_surface_initial_change /= 0.0_wp )  THEN
1391       WRITE ( message_string, * )  'constant_heatflux = .TRUE. is not allo',                      &
1392               'wed with pt_surface_initial_change (/=0) = ', pt_surface_initial_change
1393       CALL message( 'check_parameters', 'PA0066', 1, 2, 0, 6, 0 )
1394    ENDIF
1395    IF ( constant_heatflux  .AND.  pt_surface_heating_rate /= 0.0_wp )  THEN
1396       WRITE ( message_string, * )  'constant_heatflux = .TRUE. is not allo',                      &
1397               'wed with pt_surface_heating_rate (/=0) = ', pt_surface_heating_rate
1398       CALL message( 'check_parameters', 'PA0497', 1, 2, 0, 6, 0 )
1399    ENDIF
1400
1401!
1402!-- A given temperature at the top implies Dirichlet boundary condition for temperature. In this
1403!-- case specification of a constant heat flux is forbidden.
1404    IF ( ibc_pt_t == 0  .AND.  constant_top_heatflux  .AND.  top_heatflux /= 0.0_wp )  THEN
1405       message_string = 'boundary_condition: bc_pt_t = "' // TRIM( bc_pt_t ) //                    &
1406                        '" is not allowed with constant_top_heatflux = .TRUE.'
1407       CALL message( 'check_parameters', 'PA0067', 1, 2, 0, 6, 0 )
1408    ENDIF
1409
1410!
1411!-- Set boundary conditions for total water content
1412    IF ( humidity )  THEN
1413
1414       IF ( ANY( wall_humidityflux /= 0.0_wp )  .AND.  surface_waterflux == 9999999.9_wp )  THEN
1415          message_string = 'wall_humidityflux additionally requires setting of surface_waterflux'
1416          CALL message( 'check_parameters', 'PA0444', 1, 2, 0, 6, 0 )
1417       ENDIF
1418
1419       CALL set_bc_scalars( 'q', bc_q_b, bc_q_t, ibc_q_b, ibc_q_t, 'PA0071', 'PA0072' )
1420
1421       IF ( surface_waterflux == 9999999.9_wp  )  THEN
1422          constant_waterflux = .FALSE.
1423          IF ( large_scale_forcing .OR. land_surface )  THEN
1424             IF ( ibc_q_b == 0 )  THEN
1425                constant_waterflux = .FALSE.
1426             ELSEIF ( ibc_q_b == 1 )  THEN
1427                constant_waterflux = .TRUE.
1428             ENDIF
1429          ENDIF
1430       ELSE
1431          constant_waterflux = .TRUE.
1432       ENDIF
1433
1434       CALL check_bc_scalars( 'q', bc_q_b, ibc_q_b, 'PA0073', 'PA0074', constant_waterflux,        &
1435                              q_surface_initial_change )
1436
1437    ENDIF
1438
1439    IF ( passive_scalar )  THEN
1440
1441       IF ( ANY( wall_scalarflux /= 0.0_wp )  .AND.  surface_scalarflux == 9999999.9_wp )  THEN
1442          message_string = 'wall_scalarflux additionally requires setting of surface_scalarflux'
1443          CALL message( 'check_parameters', 'PA0445', 1, 2, 0, 6, 0 )
1444       ENDIF
1445
1446       IF ( surface_scalarflux == 9999999.9_wp )  constant_scalarflux = .FALSE.
1447
1448       CALL set_bc_scalars( 's', bc_s_b, bc_s_t, ibc_s_b, ibc_s_t, 'PA0071', 'PA0072' )
1449
1450       CALL check_bc_scalars( 's', bc_s_b, ibc_s_b, 'PA0073', 'PA0074', constant_scalarflux,       &
1451                              s_surface_initial_change )
1452
1453       IF ( top_scalarflux == 9999999.9_wp )  constant_top_scalarflux = .FALSE.
1454!
1455!--    A fixed scalar concentration at the top implies Dirichlet boundary condition for scalar.
1456!--    Hence, in this case specification of a constant scalar flux is forbidden.
1457       IF ( ( ibc_s_t == 0 .OR. ibc_s_t == 2 )  .AND.  constant_top_scalarflux  .AND.              &
1458              top_scalarflux /= 0.0_wp )  THEN
1459          message_string = 'boundary condition: bc_s_t = "' // TRIM( bc_s_t ) //                   &
1460                           '" is not allowed with top_scalarflux /= 0.0'
1461          CALL message( 'check_parameters', 'PA0441', 1, 2, 0, 6, 0 )
1462       ENDIF
1463    ENDIF
1464
1465!
1466!-- Boundary conditions for horizontal components of wind speed
1467    IF ( bc_uv_b == 'dirichlet' )  THEN
1468       ibc_uv_b = 0
1469    ELSEIF ( bc_uv_b == 'neumann' )  THEN
1470       ibc_uv_b = 1
1471       IF ( constant_flux_layer )  THEN
1472          message_string = 'boundary condition: bc_uv_b = "' // TRIM( bc_uv_b ) //                 &
1473                           '" is not allowed with constant_flux_layer = .TRUE.'
1474          CALL message( 'check_parameters', 'PA0075', 1, 2, 0, 6, 0 )
1475       ENDIF
1476    ELSE
1477       message_string = 'unknown boundary condition: bc_uv_b = "' // TRIM( bc_uv_b ) // '"'
1478       CALL message( 'check_parameters', 'PA0076', 1, 2, 0, 6, 0 )
1479    ENDIF
1480!
1481!-- In case of coupled simulations u and v at the ground in atmosphere will be assigned with the u
1482!-- and v values of the ocean surface
1483    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
1484       ibc_uv_b = 2
1485    ENDIF
1486
1487    IF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
1488       bc_uv_t = 'neumann'
1489       ibc_uv_t = 1
1490    ELSE
1491       IF ( bc_uv_t == 'dirichlet' .OR. bc_uv_t == 'dirichlet_0' )  THEN
1492          ibc_uv_t = 0
1493          IF ( bc_uv_t == 'dirichlet_0' )  THEN
1494!
1495!--          Velocities for the initial u,v-profiles are set zero at the top in case of dirichlet_0
1496!--          conditions
1497             u_init(nzt+1)    = 0.0_wp
1498             v_init(nzt+1)    = 0.0_wp
1499          ENDIF
1500       ELSEIF ( bc_uv_t == 'neumann' )  THEN
1501          ibc_uv_t = 1
1502       ELSEIF ( bc_uv_t == 'nested'  .OR.  bc_uv_t == 'nesting_offline' )  THEN
1503          ibc_uv_t = 3
1504       ELSE
1505          message_string = 'unknown boundary condition: bc_uv_t = "' // TRIM( bc_uv_t ) // '"'
1506          CALL message( 'check_parameters', 'PA0077', 1, 2, 0, 6, 0 )
1507       ENDIF
1508    ENDIF
1509
1510!
1511!-- Compute and check, respectively, the Rayleigh Damping parameter
1512    IF ( rayleigh_damping_factor == -1.0_wp )  THEN
1513       rayleigh_damping_factor = 0.0_wp
1514    ELSE
1515       IF ( rayleigh_damping_factor < 0.0_wp  .OR.  rayleigh_damping_factor > 1.0_wp )  THEN
1516          WRITE( message_string, * )  'rayleigh_damping_factor = ', rayleigh_damping_factor,       &
1517                 ' out of range [0.0,1.0]'
1518          CALL message( 'check_parameters', 'PA0078', 1, 2, 0, 6, 0 )
1519       ENDIF
1520    ENDIF
1521
1522    IF ( rayleigh_damping_height == -1.0_wp )  THEN
1523       IF ( .NOT. ocean_mode )  THEN
1524          rayleigh_damping_height = 0.66666666666_wp * zu(nzt)
1525       ELSE
1526          rayleigh_damping_height = 0.66666666666_wp * zu(nzb)
1527       ENDIF
1528    ELSE
1529       IF ( .NOT. ocean_mode )  THEN
1530          IF ( rayleigh_damping_height < 0.0_wp  .OR.  rayleigh_damping_height > zu(nzt) )  THEN
1531             WRITE( message_string, * )  'rayleigh_damping_height = ',  rayleigh_damping_height,   &
1532                    ' out of range [0.0,', zu(nzt), ']'
1533             CALL message( 'check_parameters', 'PA0079', 1, 2, 0, 6, 0 )
1534          ENDIF
1535       ELSE
1536          IF ( rayleigh_damping_height > 0.0_wp  .OR.  rayleigh_damping_height < zu(nzb) )  THEN
1537             WRITE( message_string, * )  'rayleigh_damping_height = ', rayleigh_damping_height,    &
1538                    ' out of range [0.0,', zu(nzb), ']'
1539             CALL message( 'check_parameters', 'PA0079', 1, 2, 0, 6, 0 )
1540          ENDIF
1541       ENDIF
1542    ENDIF
1543
1544!
1545!-- Check number of chosen statistic regions
1546    IF ( statistic_regions < 0 )  THEN
1547       WRITE ( message_string, * ) 'number of statistic_regions = ', statistic_regions+1,          &
1548               ' is not allowed'
1549       CALL message( 'check_parameters', 'PA0082', 1, 2, 0, 6, 0 )
1550    ENDIF
1551    IF ( normalizing_region > statistic_regions  .OR.  normalizing_region < 0)  THEN
1552       WRITE ( message_string, * ) 'normalizing_region = ', normalizing_region,                    &
1553               ' must be >= 0 and <= ',statistic_regions, ' (value of statistic_regions)'
1554       CALL message( 'check_parameters', 'PA0083', 1, 2, 0, 6, 0 )
1555    ENDIF
1556
1557!
1558!-- Set the default intervals for data output, if necessary
1559!-- NOTE: dt_dosp has already been set in spectra_parin
1560    IF ( dt_data_output /= 9999999.9_wp )  THEN
1561       IF ( dt_dopr           == 9999999.9_wp )  dt_dopr           = dt_data_output
1562       IF ( dt_dopts          == 9999999.9_wp )  dt_dopts          = dt_data_output
1563       IF ( dt_do2d_xy        == 9999999.9_wp )  dt_do2d_xy        = dt_data_output
1564       IF ( dt_do2d_xz        == 9999999.9_wp )  dt_do2d_xz        = dt_data_output
1565       IF ( dt_do2d_yz        == 9999999.9_wp )  dt_do2d_yz        = dt_data_output
1566       IF ( dt_do3d           == 9999999.9_wp )  dt_do3d           = dt_data_output
1567       IF ( dt_data_output_av == 9999999.9_wp )  dt_data_output_av = dt_data_output
1568       DO  mid = 1, max_masks
1569          IF ( dt_domask(mid) == 9999999.9_wp )  dt_domask(mid)    = dt_data_output
1570       ENDDO
1571    ENDIF
1572
1573!
1574!-- Set the default skip time intervals for data output, if necessary
1575    IF ( skip_time_dopr    == 9999999.9_wp )  skip_time_dopr    = skip_time_data_output
1576    IF ( skip_time_do2d_xy == 9999999.9_wp )  skip_time_do2d_xy = skip_time_data_output
1577    IF ( skip_time_do2d_xz == 9999999.9_wp )  skip_time_do2d_xz = skip_time_data_output
1578    IF ( skip_time_do2d_yz == 9999999.9_wp )  skip_time_do2d_yz = skip_time_data_output
1579    IF ( skip_time_do3d    == 9999999.9_wp )  skip_time_do3d    = skip_time_data_output
1580    IF ( skip_time_data_output_av == 9999999.9_wp )                                                &
1581                                       skip_time_data_output_av = skip_time_data_output
1582    DO  mid = 1, max_masks
1583       IF ( skip_time_domask(mid) == 9999999.9_wp )                                                &
1584                                       skip_time_domask(mid)    = skip_time_data_output
1585    ENDDO
1586
1587!
1588!-- Check the average intervals (first for 3d-data, then for profiles)
1589    IF ( averaging_interval > dt_data_output_av )  THEN
1590       WRITE( message_string, * )  'averaging_interval = ', averaging_interval,                    &
1591              ' must be <= dt_data_output_av = ', dt_data_output_av
1592       CALL message( 'check_parameters', 'PA0085', 1, 2, 0, 6, 0 )
1593    ENDIF
1594
1595    IF ( averaging_interval_pr == 9999999.9_wp )  THEN
1596       averaging_interval_pr = averaging_interval
1597    ENDIF
1598
1599    IF ( averaging_interval_pr > dt_dopr )  THEN
1600       WRITE( message_string, * )  'averaging_interval_pr = ', averaging_interval_pr,              &
1601              ' must be <= dt_dopr = ', dt_dopr
1602       CALL message( 'check_parameters', 'PA0086', 1, 2, 0, 6, 0 )
1603    ENDIF
1604
1605!
1606!-- Set the default interval for profiles entering the temporal average
1607    IF ( dt_averaging_input_pr == 9999999.9_wp )  THEN
1608       dt_averaging_input_pr = dt_averaging_input
1609    ENDIF
1610
1611!
1612!-- Set the default interval for the output of timeseries to a reasonable value (tries to minimize
1613!-- the number of calls of flow_statistics)
1614    IF ( dt_dots == 9999999.9_wp )  THEN
1615       IF ( averaging_interval_pr == 0.0_wp )  THEN
1616          dt_dots = MIN( dt_run_control, dt_dopr )
1617       ELSE
1618          dt_dots = MIN( dt_run_control, dt_averaging_input_pr )
1619       ENDIF
1620    ENDIF
1621
1622!
1623!-- Check the sample rate for averaging (first for 3d-data, then for profiles)
1624    IF ( dt_averaging_input > averaging_interval )  THEN
1625       WRITE( message_string, * )  'dt_averaging_input = ', dt_averaging_input,                    &
1626              ' must be <= averaging_interval = ', averaging_interval
1627       CALL message( 'check_parameters', 'PA0088', 1, 2, 0, 6, 0 )
1628    ENDIF
1629
1630    IF ( dt_averaging_input_pr > averaging_interval_pr )  THEN
1631       WRITE( message_string, * )  'dt_averaging_input_pr = ', dt_averaging_input_pr,              &
1632              ' must be <= averaging_interval_pr = ', averaging_interval_pr
1633       CALL message( 'check_parameters', 'PA0089', 1, 2, 0, 6, 0 )
1634    ENDIF
1635
1636!
1637!-- Determine the number of output profiles and check whether they are permissible
1638    DO  WHILE ( data_output_pr(dopr_n+1) /= '          ' )
1639
1640       dopr_n = dopr_n + 1
1641       i = dopr_n
1642
1643!
1644!--    Determine internal profile number (for hom, homs) and store height levels
1645       SELECT CASE ( TRIM( data_output_pr(i) ) )
1646
1647          CASE ( 'u', '#u' )
1648             dopr_index(i) = 1
1649             dopr_unit(i)  = 'm/s'
1650             hom(:,2,1,:)  = SPREAD( zu, 2, statistic_regions+1 )
1651             IF ( data_output_pr(i)(1:1) == '#' )  THEN
1652                dopr_initial_index(i) = 5
1653                hom(:,2,5,:)          = SPREAD( zu, 2, statistic_regions+1 )
1654                data_output_pr(i)     = data_output_pr(i)(2:)
1655             ENDIF
1656
1657          CASE ( 'v', '#v' )
1658             dopr_index(i) = 2
1659             dopr_unit(i)  = 'm/s'
1660             hom(:,2,2,:)  = SPREAD( zu, 2, statistic_regions+1 )
1661             IF ( data_output_pr(i)(1:1) == '#' )  THEN
1662                dopr_initial_index(i) = 6
1663                hom(:,2,6,:)          = SPREAD( zu, 2, statistic_regions+1 )
1664                data_output_pr(i)     = data_output_pr(i)(2:)
1665             ENDIF
1666
1667          CASE ( 'w' )
1668             dopr_index(i) = 3
1669             dopr_unit(i)  = 'm/s'
1670             hom(:,2,3,:)  = SPREAD( zw, 2, statistic_regions+1 )
1671
1672          CASE ( 'theta', '#theta' )
1673             IF ( .NOT. bulk_cloud_model )  THEN
1674                dopr_index(i) = 4
1675                dopr_unit(i)  = 'K'
1676                hom(:,2,4,:)  = SPREAD( zu, 2, statistic_regions+1 )
1677                IF ( data_output_pr(i)(1:1) == '#' )  THEN
1678                   dopr_initial_index(i) = 7
1679                   hom(:,2,7,:)          = SPREAD( zu, 2, statistic_regions+1 )
1680                   hom(nzb,2,7,:)        = 0.0_wp    ! because zu(nzb) is negative
1681                   data_output_pr(i)     = data_output_pr(i)(2:)
1682                ENDIF
1683             ELSE
1684                dopr_index(i) = 43
1685                dopr_unit(i)  = 'K'
1686                hom(:,2,43,:)  = SPREAD( zu, 2, statistic_regions+1 )
1687                IF ( data_output_pr(i)(1:1) == '#' )  THEN
1688                   dopr_initial_index(i) = 28
1689                   hom(:,2,28,:)         = SPREAD( zu, 2, statistic_regions+1 )
1690                   hom(nzb,2,28,:)       = 0.0_wp    ! because zu(nzb) is negative
1691                   data_output_pr(i)     = data_output_pr(i)(2:)
1692                ENDIF
1693             ENDIF
1694
1695          CASE ( 'e', '#e' )
1696             dopr_index(i)  = 8
1697             dopr_unit(i)   = 'm2/s2'
1698             hom(:,2,8,:)   = SPREAD( zu, 2, statistic_regions+1 )
1699             hom(nzb,2,8,:) = 0.0_wp
1700             IF ( data_output_pr(i)(1:1) == '#' )  THEN
1701                dopr_initial_index(i) = 8
1702                hom(:,2,8,:)          = SPREAD( zu, 2, statistic_regions+1 )
1703                data_output_pr(i)     = data_output_pr(i)(2:)
1704             ENDIF
1705
1706          CASE ( 'km', '#km' )
1707             dopr_index(i)  = 9
1708             dopr_unit(i)   = 'm2/s'
1709             hom(:,2,9,:)   = SPREAD( zu, 2, statistic_regions+1 )
1710             hom(nzb,2,9,:) = 0.0_wp
1711             IF ( data_output_pr(i)(1:1) == '#' )  THEN
1712                dopr_initial_index(i) = 23
1713                hom(:,2,23,:)         = hom(:,2,9,:)
1714                data_output_pr(i)     = data_output_pr(i)(2:)
1715             ENDIF
1716
1717          CASE ( 'kh', '#kh' )
1718             dopr_index(i)   = 10
1719             dopr_unit(i)    = 'm2/s'
1720             hom(:,2,10,:)   = SPREAD( zu, 2, statistic_regions+1 )
1721             hom(nzb,2,10,:) = 0.0_wp
1722             IF ( data_output_pr(i)(1:1) == '#' )  THEN
1723                dopr_initial_index(i) = 24
1724                hom(:,2,24,:)         = hom(:,2,10,:)
1725                data_output_pr(i)     = data_output_pr(i)(2:)
1726             ENDIF
1727
1728          CASE ( 'l', '#l' )
1729             dopr_index(i)   = 11
1730             dopr_unit(i)    = 'm'
1731             hom(:,2,11,:)   = SPREAD( zu, 2, statistic_regions+1 )
1732             hom(nzb,2,11,:) = 0.0_wp
1733             IF ( data_output_pr(i)(1:1) == '#' )  THEN
1734                dopr_initial_index(i) = 25
1735                hom(:,2,25,:)         = hom(:,2,11,:)
1736                data_output_pr(i)     = data_output_pr(i)(2:)
1737             ENDIF
1738
1739          CASE ( 'w"u"' )
1740             dopr_index(i) = 12
1741             dopr_unit(i)  = TRIM ( momentumflux_output_unit )
1742             hom(:,2,12,:) = SPREAD( zw, 2, statistic_regions+1 )
1743             IF ( constant_flux_layer )  hom(nzb,2,12,:) = zu(1)
1744
1745          CASE ( 'w*u*' )
1746             dopr_index(i) = 13
1747             dopr_unit(i)  = TRIM ( momentumflux_output_unit )
1748             hom(:,2,13,:) = SPREAD( zw, 2, statistic_regions+1 )
1749
1750          CASE ( 'w"v"' )
1751             dopr_index(i) = 14
1752             dopr_unit(i)  = TRIM ( momentumflux_output_unit )
1753             hom(:,2,14,:) = SPREAD( zw, 2, statistic_regions+1 )
1754             IF ( constant_flux_layer )  hom(nzb,2,14,:) = zu(1)
1755
1756          CASE ( 'w*v*' )
1757             dopr_index(i) = 15
1758             dopr_unit(i)  = TRIM ( momentumflux_output_unit )
1759             hom(:,2,15,:) = SPREAD( zw, 2, statistic_regions+1 )
1760
1761          CASE ( 'w"theta"' )
1762             dopr_index(i) = 16
1763             dopr_unit(i)  = TRIM ( heatflux_output_unit )
1764             hom(:,2,16,:) = SPREAD( zw, 2, statistic_regions+1 )
1765
1766          CASE ( 'w*theta*' )
1767             dopr_index(i) = 17
1768             dopr_unit(i)  = TRIM ( heatflux_output_unit )
1769             hom(:,2,17,:) = SPREAD( zw, 2, statistic_regions+1 )
1770
1771          CASE ( 'wtheta' )
1772             dopr_index(i) = 18
1773             dopr_unit(i)  = TRIM ( heatflux_output_unit )
1774             hom(:,2,18,:) = SPREAD( zw, 2, statistic_regions+1 )
1775
1776          CASE ( 'wu' )
1777             dopr_index(i) = 19
1778             dopr_unit(i)  = TRIM ( momentumflux_output_unit )
1779             hom(:,2,19,:) = SPREAD( zw, 2, statistic_regions+1 )
1780             IF ( constant_flux_layer )  hom(nzb,2,19,:) = zu(1)
1781
1782          CASE ( 'wv' )
1783             dopr_index(i) = 20
1784             dopr_unit(i)  = TRIM ( momentumflux_output_unit )
1785             hom(:,2,20,:) = SPREAD( zw, 2, statistic_regions+1 )
1786             IF ( constant_flux_layer )  hom(nzb,2,20,:) = zu(1)
1787
1788          CASE ( 'w*theta*BC' )
1789             dopr_index(i) = 21
1790             dopr_unit(i)  = TRIM ( heatflux_output_unit )
1791             hom(:,2,21,:) = SPREAD( zw, 2, statistic_regions+1 )
1792
1793          CASE ( 'wthetaBC' )
1794             dopr_index(i) = 22
1795             dopr_unit(i)  = TRIM ( heatflux_output_unit )
1796             hom(:,2,22,:) = SPREAD( zw, 2, statistic_regions+1 )
1797
1798          CASE ( 'u*2' )
1799             dopr_index(i) = 30
1800             dopr_unit(i)  = 'm2/s2'
1801             hom(:,2,30,:) = SPREAD( zu, 2, statistic_regions+1 )
1802
1803          CASE ( 'v*2' )
1804             dopr_index(i) = 31
1805             dopr_unit(i)  = 'm2/s2'
1806             hom(:,2,31,:) = SPREAD( zu, 2, statistic_regions+1 )
1807
1808          CASE ( 'w*2' )
1809             dopr_index(i) = 32
1810             dopr_unit(i)  = 'm2/s2'
1811             hom(:,2,32,:) = SPREAD( zw, 2, statistic_regions+1 )
1812
1813          CASE ( 'theta*2' )
1814             dopr_index(i) = 33
1815             dopr_unit(i)  = 'K2'
1816             hom(:,2,33,:) = SPREAD( zu, 2, statistic_regions+1 )
1817
1818          CASE ( 'e*' )
1819             dopr_index(i) = 34
1820             dopr_unit(i)  = 'm2/s2'
1821             hom(:,2,34,:) = SPREAD( zu, 2, statistic_regions+1 )
1822
1823          CASE ( 'w*2theta*' )
1824             dopr_index(i) = 35
1825             dopr_unit(i)  = 'K m2/s2'
1826             hom(:,2,35,:) = SPREAD( zw, 2, statistic_regions+1 )
1827
1828          CASE ( 'w*theta*2' )
1829             dopr_index(i) = 36
1830             dopr_unit(i)  = 'K2 m/s'
1831             hom(:,2,36,:) = SPREAD( zw, 2, statistic_regions+1 )
1832
1833          CASE ( 'w*e*' )
1834             dopr_index(i) = 37
1835             dopr_unit(i)  = 'm3/s3'
1836             hom(:,2,37,:) = SPREAD( zw, 2, statistic_regions+1 )
1837
1838          CASE ( 'w*3' )
1839             dopr_index(i) = 38
1840             dopr_unit(i)  = 'm3/s3'
1841             hom(:,2,38,:) = SPREAD( zw, 2, statistic_regions+1 )
1842
1843          CASE ( 'Sw' )
1844             dopr_index(i) = 39
1845             dopr_unit(i)  = 'none'
1846             hom(:,2,39,:) = SPREAD( zw, 2, statistic_regions+1 )
1847
1848          CASE ( 'p' )
1849             dopr_index(i) = 40
1850             dopr_unit(i)  = 'Pa'
1851             hom(:,2,40,:) = SPREAD( zu, 2, statistic_regions+1 )
1852
1853          CASE ( 'q', '#q' )
1854             IF ( .NOT. humidity )  THEN
1855                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
1856                                 ' is not implemented for humidity = .FALSE.'
1857                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
1858             ELSE
1859                dopr_index(i) = 41
1860                dopr_unit(i)  = 'kg/kg'
1861                hom(:,2,41,:) = SPREAD( zu, 2, statistic_regions+1 )
1862                IF ( data_output_pr(i)(1:1) == '#' )  THEN
1863                   dopr_initial_index(i) = 26
1864                   hom(:,2,26,:)         = SPREAD( zu, 2, statistic_regions+1 )
1865                   hom(nzb,2,26,:)       = 0.0_wp    ! because zu(nzb) is negative
1866                   data_output_pr(i)     = data_output_pr(i)(2:)
1867                ENDIF
1868             ENDIF
1869
1870          CASE ( 's', '#s' )
1871             IF ( .NOT. passive_scalar )  THEN
1872                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
1873                                 ' is not implemented for passive_scalar = .FALSE.'
1874                CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
1875             ELSE
1876                dopr_index(i) = 115
1877                dopr_unit(i)  = 'kg/m3'
1878                hom(:,2,115,:) = SPREAD( zu, 2, statistic_regions+1 )
1879                IF ( data_output_pr(i)(1:1) == '#' )  THEN
1880                   dopr_initial_index(i) = 121
1881                   hom(:,2,121,:)        = SPREAD( zu, 2, statistic_regions+1 )
1882                   hom(nzb,2,121,:)      = 0.0_wp    ! because zu(nzb) is negative
1883                   data_output_pr(i)     = data_output_pr(i)(2:)
1884                ENDIF
1885             ENDIF
1886
1887          CASE ( 'qv', '#qv' )
1888             IF ( .NOT. bulk_cloud_model ) THEN
1889                dopr_index(i) = 41
1890                dopr_unit(i)  = 'kg/kg'
1891                hom(:,2,41,:) = SPREAD( zu, 2, statistic_regions+1 )
1892                IF ( data_output_pr(i)(1:1) == '#' )  THEN
1893                   dopr_initial_index(i) = 26
1894                   hom(:,2,26,:)         = SPREAD( zu, 2, statistic_regions+1 )
1895                   hom(nzb,2,26,:)       = 0.0_wp    ! because zu(nzb) is negative
1896                   data_output_pr(i)     = data_output_pr(i)(2:)
1897                ENDIF
1898             ELSE
1899                dopr_index(i) = 42
1900                dopr_unit(i)  = 'kg/kg'
1901                hom(:,2,42,:) = SPREAD( zu, 2, statistic_regions+1 )
1902                IF ( data_output_pr(i)(1:1) == '#' )  THEN
1903                   dopr_initial_index(i) = 27
1904                   hom(:,2,27,:)         = SPREAD( zu, 2, statistic_regions+1 )
1905                   hom(nzb,2,27,:)       = 0.0_wp   ! because zu(nzb) is negative
1906                   data_output_pr(i)     = data_output_pr(i)(2:)
1907                ENDIF
1908             ENDIF
1909
1910          CASE ( 'thetal', '#thetal' )
1911             IF ( .NOT. bulk_cloud_model ) THEN
1912                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
1913                                 ' is not implemented for bulk_cloud_model = .FALSE.'
1914                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
1915             ELSE
1916                dopr_index(i) = 4
1917                dopr_unit(i)  = 'K'
1918                hom(:,2,4,:)  = SPREAD( zu, 2, statistic_regions+1 )
1919                IF ( data_output_pr(i)(1:1) == '#' )  THEN
1920                   dopr_initial_index(i) = 7
1921                   hom(:,2,7,:)          = SPREAD( zu, 2, statistic_regions+1 )
1922                   hom(nzb,2,7,:)        = 0.0_wp    ! because zu(nzb) is negative
1923                   data_output_pr(i)     = data_output_pr(i)(2:)
1924                ENDIF
1925             ENDIF
1926
1927          CASE ( 'thetav', '#thetav' )
1928             dopr_index(i) = 44
1929             dopr_unit(i)  = 'K'
1930             hom(:,2,44,:) = SPREAD( zu, 2, statistic_regions+1 )
1931             IF ( data_output_pr(i)(1:1) == '#' )  THEN
1932                dopr_initial_index(i) = 29
1933                hom(:,2,29,:)         = SPREAD( zu, 2, statistic_regions+1 )
1934                hom(nzb,2,29,:)       = 0.0_wp    ! because zu(nzb) is negative
1935                data_output_pr(i)     = data_output_pr(i)(2:)
1936             ENDIF
1937
1938          CASE ( 'w"thetav"' )
1939             dopr_index(i) = 45
1940             dopr_unit(i)  = TRIM ( heatflux_output_unit )
1941             hom(:,2,45,:) = SPREAD( zw, 2, statistic_regions+1 )
1942
1943          CASE ( 'w*thetav*' )
1944             dopr_index(i) = 46
1945             dopr_unit(i)  = TRIM ( heatflux_output_unit )
1946             hom(:,2,46,:) = SPREAD( zw, 2, statistic_regions+1 )
1947
1948          CASE ( 'wthetav' )
1949             dopr_index(i) = 47
1950             dopr_unit(i)  = TRIM ( heatflux_output_unit )
1951             hom(:,2,47,:) = SPREAD( zw, 2, statistic_regions+1 )
1952
1953          CASE ( 'w"q"' )
1954             IF ( .NOT. humidity )  THEN
1955                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
1956                                 ' is not implemented for humidity = .FALSE.'
1957                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
1958             ELSE
1959                dopr_index(i) = 48
1960                dopr_unit(i)  = TRIM ( waterflux_output_unit )
1961                hom(:,2,48,:) = SPREAD( zw, 2, statistic_regions+1 )
1962             ENDIF
1963
1964          CASE ( 'w*q*' )
1965             IF ( .NOT. humidity )  THEN
1966                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
1967                                 ' is not implemented for humidity = .FALSE.'
1968                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
1969             ELSE
1970                dopr_index(i) = 49
1971                dopr_unit(i)  = TRIM ( waterflux_output_unit )
1972                hom(:,2,49,:) = SPREAD( zw, 2, statistic_regions+1 )
1973             ENDIF
1974
1975          CASE ( 'wq' )
1976             IF ( .NOT. humidity )  THEN
1977                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
1978                                 ' is not implemented for humidity = .FALSE.'
1979                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
1980             ELSE
1981                dopr_index(i) = 50
1982                dopr_unit(i)  = TRIM ( waterflux_output_unit )
1983                hom(:,2,50,:) = SPREAD( zw, 2, statistic_regions+1 )
1984             ENDIF
1985
1986          CASE ( 'w"s"' )
1987             IF ( .NOT. passive_scalar )  THEN
1988                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
1989                                 ' is not implemented for passive_scalar = .FALSE.'
1990                CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
1991             ELSE
1992                dopr_index(i) = 117
1993                dopr_unit(i)  = 'kg/m3 m/s'
1994                hom(:,2,117,:) = SPREAD( zw, 2, statistic_regions+1 )
1995             ENDIF
1996
1997          CASE ( 'w*s*' )
1998             IF ( .NOT. passive_scalar )  THEN
1999                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2000                                 ' is not implemented for passive_scalar = .FALSE.'
2001                CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
2002             ELSE
2003                dopr_index(i) = 114
2004                dopr_unit(i)  = 'kg/m3 m/s'
2005                hom(:,2,114,:) = SPREAD( zw, 2, statistic_regions+1 )
2006             ENDIF
2007
2008          CASE ( 'ws' )
2009             IF ( .NOT. passive_scalar )  THEN
2010                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2011                                 ' is not implemented for passive_scalar = .FALSE.'
2012                CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
2013             ELSE
2014                dopr_index(i) = 118
2015                dopr_unit(i)  = 'kg/m3 m/s'
2016                hom(:,2,118,:) = SPREAD( zw, 2, statistic_regions+1 )
2017             ENDIF
2018
2019          CASE ( 'w"qv"' )
2020             IF ( humidity  .AND.  .NOT. bulk_cloud_model )  THEN
2021                dopr_index(i) = 48
2022                dopr_unit(i)  = TRIM ( waterflux_output_unit )
2023                hom(:,2,48,:) = SPREAD( zw, 2, statistic_regions+1 )
2024             ELSEIF ( humidity  .AND.  bulk_cloud_model )  THEN
2025                dopr_index(i) = 51
2026                dopr_unit(i)  = TRIM ( waterflux_output_unit )
2027                hom(:,2,51,:) = SPREAD( zw, 2, statistic_regions+1 )
2028             ELSE
2029                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2030                                 ' is not implemented for bulk_cloud_model = .FALSE. ' //          &
2031                                 'and humidity = .FALSE.'
2032                CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
2033             ENDIF
2034
2035          CASE ( 'w*qv*' )
2036             IF ( humidity  .AND.  .NOT. bulk_cloud_model )  THEN
2037                dopr_index(i) = 49
2038                dopr_unit(i)  = TRIM ( waterflux_output_unit )
2039                hom(:,2,49,:) = SPREAD( zw, 2, statistic_regions+1 )
2040             ELSEIF( humidity  .AND.  bulk_cloud_model )  THEN
2041                dopr_index(i) = 52
2042                dopr_unit(i)  = TRIM ( waterflux_output_unit )
2043                hom(:,2,52,:) = SPREAD( zw, 2, statistic_regions+1 )
2044             ELSE
2045                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2046                                 ' is not implemented for bulk_cloud_model = .FALSE. ' //          &
2047                                 'and humidity = .FALSE.'
2048                CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
2049             ENDIF
2050
2051          CASE ( 'wqv' )
2052             IF ( humidity  .AND.  .NOT. bulk_cloud_model )  THEN
2053                dopr_index(i) = 50
2054                dopr_unit(i)  = TRIM ( waterflux_output_unit )
2055                hom(:,2,50,:) = SPREAD( zw, 2, statistic_regions+1 )
2056             ELSEIF ( humidity  .AND.  bulk_cloud_model )  THEN
2057                dopr_index(i) = 53
2058                dopr_unit(i)  = TRIM ( waterflux_output_unit )
2059                hom(:,2,53,:) = SPREAD( zw, 2, statistic_regions+1 )
2060             ELSE
2061                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2062                                 ' is not implemented for bulk_cloud_model = .FALSE. ' //          &
2063                                 'and humidity = .FALSE.'
2064                CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
2065             ENDIF
2066
2067          CASE ( 'ql' )
2068             IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
2069                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2070                                 ' is not implemented for bulk_cloud_model = .FALSE. ' //          &
2071                                 'and cloud_droplets = .FALSE.'
2072                CALL message( 'check_parameters', 'PA0096', 1, 2, 0, 6, 0 )
2073             ELSE
2074                dopr_index(i) = 54
2075                dopr_unit(i)  = 'kg/kg'
2076                hom(:,2,54,:)  = SPREAD( zu, 2, statistic_regions+1 )
2077             ENDIF
2078
2079          CASE ( 'w*u*u*:dz' )
2080             dopr_index(i) = 55
2081             dopr_unit(i)  = 'm2/s3'
2082             hom(:,2,55,:) = SPREAD( zu, 2, statistic_regions+1 )
2083
2084          CASE ( 'w*p*:dz' )
2085             dopr_index(i) = 56
2086             dopr_unit(i)  = 'm2/s3'
2087             hom(:,2,56,:) = SPREAD( zw, 2, statistic_regions+1 )
2088
2089          CASE ( 'w"e:dz' )
2090             dopr_index(i) = 57
2091             dopr_unit(i)  = 'm2/s3'
2092             hom(:,2,57,:) = SPREAD( zu, 2, statistic_regions+1 )
2093
2094          CASE ( 'u"theta"' )
2095             dopr_index(i) = 58
2096             dopr_unit(i)  = TRIM ( heatflux_output_unit )
2097             hom(:,2,58,:) = SPREAD( zu, 2, statistic_regions+1 )
2098
2099          CASE ( 'u*theta*' )
2100             dopr_index(i) = 59
2101             dopr_unit(i)  = TRIM ( heatflux_output_unit )
2102             hom(:,2,59,:) = SPREAD( zu, 2, statistic_regions+1 )
2103
2104          CASE ( 'utheta_t' )
2105             dopr_index(i) = 60
2106             dopr_unit(i)  = TRIM ( heatflux_output_unit )
2107             hom(:,2,60,:) = SPREAD( zu, 2, statistic_regions+1 )
2108
2109          CASE ( 'v"theta"' )
2110             dopr_index(i) = 61
2111             dopr_unit(i)  = TRIM ( heatflux_output_unit )
2112             hom(:,2,61,:) = SPREAD( zu, 2, statistic_regions+1 )
2113
2114          CASE ( 'v*theta*' )
2115             dopr_index(i) = 62
2116             dopr_unit(i)  = TRIM ( heatflux_output_unit )
2117             hom(:,2,62,:) = SPREAD( zu, 2, statistic_regions+1 )
2118
2119          CASE ( 'vtheta_t' )
2120             dopr_index(i) = 63
2121             dopr_unit(i)  = TRIM ( heatflux_output_unit )
2122             hom(:,2,63,:) = SPREAD( zu, 2, statistic_regions+1 )
2123
2124          CASE ( 'w*p*' )
2125             dopr_index(i) = 68
2126             dopr_unit(i)  = 'm3/s3'
2127             hom(:,2,68,:) = SPREAD( zu, 2, statistic_regions+1 )
2128
2129          CASE ( 'w"e' )
2130             dopr_index(i) = 69
2131             dopr_unit(i)  = 'm3/s3'
2132             hom(:,2,69,:) = SPREAD( zu, 2, statistic_regions+1 )
2133
2134          CASE ( 'q*2' )
2135             IF (  .NOT.  humidity )  THEN
2136                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2137                                 ' is not implemented for humidity = .FALSE.'
2138                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
2139             ELSE
2140                dopr_index(i) = 70
2141                dopr_unit(i)  = 'kg2/kg2'
2142                hom(:,2,70,:) = SPREAD( zu, 2, statistic_regions+1 )
2143             ENDIF
2144
2145          CASE ( 'hyp' )
2146             dopr_index(i) = 72
2147             dopr_unit(i)  = 'hPa'
2148             hom(:,2,72,:) = SPREAD( zu, 2, statistic_regions+1 )
2149
2150          CASE ( 'rho' )
2151             dopr_index(i)  = 119
2152             dopr_unit(i)   = 'kg/m3'
2153             hom(:,2,119,:) = SPREAD( zu, 2, statistic_regions+1 )
2154
2155          CASE ( 'rho_zw' )
2156             dopr_index(i)  = 120
2157             dopr_unit(i)   = 'kg/m3'
2158             hom(:,2,120,:) = SPREAD( zw, 2, statistic_regions+1 )
2159
2160          CASE ( 'ug' )
2161             dopr_index(i) = 78
2162             dopr_unit(i)  = 'm/s'
2163             hom(:,2,78,:) = SPREAD( zu, 2, statistic_regions+1 )
2164
2165          CASE ( 'vg' )
2166             dopr_index(i) = 79
2167             dopr_unit(i)  = 'm/s'
2168             hom(:,2,79,:) = SPREAD( zu, 2, statistic_regions+1 )
2169
2170          CASE ( 'w_subs' )
2171             IF (  .NOT.  large_scale_subsidence )  THEN
2172                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2173                                 ' is not implemented for large_scale_subsidence = .FALSE.'
2174                CALL message( 'check_parameters', 'PA0382', 1, 2, 0, 6, 0 )
2175             ELSE
2176                dopr_index(i) = 80
2177                dopr_unit(i)  = 'm/s'
2178                hom(:,2,80,:) = SPREAD( zu, 2, statistic_regions+1 )
2179             ENDIF
2180
2181          CASE ( 's*2' )
2182             IF (  .NOT.  passive_scalar )  THEN
2183                message_string = 'data_output_pr = ' // TRIM( data_output_pr(i) ) //               &
2184                                 ' is not implemented for passive_scalar = .FALSE.'
2185                CALL message( 'check_parameters', 'PA0185', 1, 2, 0, 6, 0 )
2186             ELSE
2187                dopr_index(i) = 116
2188                dopr_unit(i)  = 'kg2/m6'
2189                hom(:,2,116,:) = SPREAD( zu, 2, statistic_regions+1 )
2190             ENDIF
2191
2192           CASE ( 'eta' )
2193              dopr_index(i) = 121
2194              dopr_unit(i)  = 'mm'
2195              hom(:,2,121,:) = SPREAD( zu, 2, statistic_regions+1 )
2196
2197              kolmogorov_length_scale = .TRUE.
2198
2199          CASE DEFAULT
2200             unit = 'illegal'
2201!
2202!--          Check for other modules
2203             CALL module_interface_check_data_output_pr( data_output_pr(i), i, unit, dopr_unit(i) )
2204
2205!
2206!--          No valid quantity found
2207             IF ( unit == 'illegal' )  THEN
2208                IF ( data_output_pr_user(1) /= ' ' )  THEN
2209                   message_string = 'illegal value for data_output_pr or ' //                      &
2210                                    'data_output_pr_user = "' // TRIM( data_output_pr(i) ) // '"'
2211                   CALL message( 'check_parameters', 'PA0097', 1, 2, 0, 6, 0 )
2212                ELSE
2213                   message_string = 'illegal value for data_output_pr = "' //                      &
2214                                    TRIM( data_output_pr(i) ) // '"'
2215                   CALL message( 'check_parameters', 'PA0098', 1, 2, 0, 6, 0 )
2216                ENDIF
2217             ENDIF
2218
2219       END SELECT
2220
2221    ENDDO
2222
2223
2224!
2225!-- Append user-defined data output variables to the standard data output
2226    IF ( data_output_user(1) /= ' ' )  THEN
2227       i = 1
2228       DO  WHILE ( data_output(i) /= ' '  .AND.  i <= 500 )
2229          i = i + 1
2230       ENDDO
2231       j = 1
2232       DO  WHILE ( data_output_user(j) /= ' '  .AND.  j <= 500 )
2233          IF ( i > 500 )  THEN
2234             message_string = 'number of output quantitities given by data' //                     &
2235                              '_output and data_output_user exceeds the limit of 500'
2236             CALL message( 'check_parameters', 'PA0102', 1, 2, 0, 6, 0 )
2237          ENDIF
2238          data_output(i) = data_output_user(j)
2239          i = i + 1
2240          j = j + 1
2241       ENDDO
2242    ENDIF
2243
2244!
2245!-- Check and set steering parameters for 2d/3d data output and averaging
2246    i   = 1
2247    DO  WHILE ( data_output(i) /= ' '  .AND.  i <= 500 )
2248!
2249!--    Check for data averaging
2250       ilen = LEN_TRIM( data_output(i) )
2251       j = 0                                                 ! no data averaging
2252       IF ( ilen > 3 )  THEN
2253          IF ( data_output(i)(ilen-2:ilen) == '_av' )  THEN
2254             j = 1                                           ! data averaging
2255             data_output(i) = data_output(i)(1:ilen-3)
2256          ENDIF
2257       ENDIF
2258!
2259!--    Check for cross section or volume data
2260       ilen = LEN_TRIM( data_output(i) )
2261       k = 0                                                   ! 3d data
2262       var = data_output(i)(1:ilen)
2263       IF ( ilen > 3 )  THEN
2264          IF ( data_output(i)(ilen-2:ilen) == '_xy'  .OR.  data_output(i)(ilen-2:ilen) == '_xz'    &
2265               .OR.  data_output(i)(ilen-2:ilen) == '_yz' )  THEN
2266             k = 1                                             ! 2d data
2267             var = data_output(i)(1:ilen-3)
2268          ENDIF
2269       ENDIF
2270
2271!
2272!--    Check for allowed value and set units
2273       SELECT CASE ( TRIM( var ) )
2274
2275          CASE ( 'e' )
2276             IF ( constant_diffusion )  THEN
2277                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2278                                 'constant_diffusion = .FALSE.'
2279                CALL message( 'check_parameters', 'PA0103', 1, 2, 0, 6, 0 )
2280             ENDIF
2281             unit = 'm2/s2'
2282
2283          CASE ( 'thetal' )
2284             IF ( .NOT. bulk_cloud_model )  THEN
2285                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2286                                 'bulk_cloud_model = .TRUE.'
2287                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
2288             ENDIF
2289             unit = 'K'
2290
2291          CASE ( 'pc', 'pr' )
2292             IF ( .NOT. particle_advection )  THEN
2293                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2294                                 'a "particle_parameters"-NAMELIST in the parameter file (PARIN)'
2295                CALL message( 'check_parameters', 'PA0104', 1, 2, 0, 6, 0 )
2296             ENDIF
2297             IF ( TRIM( var ) == 'pc' )  unit = 'number'
2298             IF ( TRIM( var ) == 'pr' )  unit = 'm'
2299
2300          CASE ( 'q', 'thetav' )
2301             IF ( .NOT. humidity )  THEN
2302                message_string = 'output of "' // TRIM( var ) // '" requires humidity = .TRUE.'
2303                CALL message( 'check_parameters', 'PA0105', 1, 2, 0, 6, 0 )
2304             ENDIF
2305             IF ( TRIM( var ) == 'q'   )  unit = 'kg/kg'
2306             IF ( TRIM( var ) == 'thetav' )  unit = 'K'
2307
2308          CASE ( 'ql' )
2309             IF ( .NOT.  ( bulk_cloud_model  .OR.  cloud_droplets ) )  THEN
2310                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2311                                 'bulk_cloud_model = .TRUE. or cloud_droplets = .TRUE.'
2312                CALL message( 'check_parameters', 'PA0106', 1, 2, 0, 6, 0 )
2313             ENDIF
2314             unit = 'kg/kg'
2315
2316          CASE ( 'ql_c', 'ql_v', 'ql_vp' )
2317             IF ( .NOT. cloud_droplets )  THEN
2318                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2319                                 'cloud_droplets = .TRUE.'
2320                CALL message( 'check_parameters', 'PA0107', 1, 2, 0, 6, 0 )
2321             ENDIF
2322             IF ( TRIM( var ) == 'ql_c'  )  unit = 'kg/kg'
2323             IF ( TRIM( var ) == 'ql_v'  )  unit = 'm3'
2324             IF ( TRIM( var ) == 'ql_vp' )  unit = 'none'
2325
2326          CASE ( 'qv' )
2327             IF ( .NOT. bulk_cloud_model )  THEN
2328                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2329                                 'bulk_cloud_model = .TRUE.'
2330                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
2331             ENDIF
2332             unit = 'kg/kg'
2333
2334          CASE ( 's' )
2335             IF ( .NOT. passive_scalar )  THEN
2336                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2337                                 'passive_scalar = .TRUE.'
2338                CALL message( 'check_parameters', 'PA0110', 1, 2, 0, 6, 0 )
2339             ENDIF
2340             unit = 'kg/m3'
2341
2342          CASE ( 'p', 'theta', 'u', 'v', 'w' )
2343             IF ( TRIM( var ) == 'p'  )  unit = 'Pa'
2344             IF ( TRIM( var ) == 'theta' )  unit = 'K'
2345             IF ( TRIM( var ) == 'u'  )  unit = 'm/s'
2346             IF ( TRIM( var ) == 'v'  )  unit = 'm/s'
2347             IF ( TRIM( var ) == 'w'  )  unit = 'm/s'
2348             CONTINUE
2349
2350          CASE ( 'ghf*', 'lwp*', 'ol*', 'qsurf*', 'qsws*', 'r_a*', 'shf*', 'ssurf*', 'ssws*', 't*',&
2351                 'tsurf*', 'us*', 'z0*', 'z0h*', 'z0q*' )
2352             IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
2353                message_string = 'illegal value for data_output: "' // TRIM( var ) //              &
2354                                 '" & only 2d-horizontal cross sections are allowed for this value'
2355                CALL message( 'check_parameters', 'PA0111', 1, 2, 0, 6, 0 )
2356             ENDIF
2357
2358             IF ( TRIM( var ) == 'lwp*'  .AND.  .NOT. bulk_cloud_model )  THEN
2359                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2360                                 'bulk_cloud_model = .TRUE.'
2361                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
2362             ENDIF
2363             IF ( TRIM( var ) == 'qsws*'  .AND.  .NOT.  humidity )  THEN
2364                message_string = 'output of "' // TRIM( var ) // '" requires humidity = .TRUE.'
2365                CALL message( 'check_parameters', 'PA0322', 1, 2, 0, 6, 0 )
2366             ENDIF
2367
2368             IF ( TRIM( var ) == 'ghf*'  .AND.  .NOT.  land_surface )  THEN
2369                message_string = 'output of "' // TRIM( var ) // '" requires land_surface = .TRUE.'
2370                CALL message( 'check_parameters', 'PA0404', 1, 2, 0, 6, 0 )
2371             ENDIF
2372
2373             IF ( (  TRIM( var ) == 'r_a*' .OR. TRIM( var ) == 'ghf*' )  .AND.  .NOT. land_surface &
2374                   .AND.  .NOT. urban_surface )  THEN
2375                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2376                                 'land_surface = .TRUE. or ' // 'urban_surface = .TRUE.'
2377                CALL message( 'check_parameters', 'PA0404', 1, 2, 0, 6, 0 )
2378             ENDIF
2379
2380             IF ( TRIM( var ) == 'ssws*'  .AND.  .NOT. passive_scalar )  THEN
2381                message_string = 'output of "' // TRIM( var ) // '" requires ' //                  &
2382                                 'passive_scalar = .TRUE.'
2383                CALL message( 'check_parameters', 'PA0361', 1, 2, 0, 6, 0 )
2384             ENDIF
2385
2386             IF ( TRIM( var ) == 'ghf*'   )  unit = 'W/m2'
2387             IF ( TRIM( var ) == 'lwp*'   )  unit = 'kg/m2'
2388             IF ( TRIM( var ) == 'ol*'    )  unit = 'm'
2389             IF ( TRIM( var ) == 'qsurf*' )  unit = 'kg/kg'
2390             IF ( TRIM( var ) == 'qsws*'  )  unit = 'kgm/kgs'
2391             IF ( TRIM( var ) == 'r_a*'   )  unit = 's/m'
2392             IF ( TRIM( var ) == 'shf*'   )  unit = 'K*m/s'
2393             IF ( TRIM( var ) == 'ssurf*' )  unit = 'kg/kg'
2394             IF ( TRIM( var ) == 'ssws*'  )  unit = 'kg/m2*s'
2395             IF ( TRIM( var ) == 't*'     )  unit = 'K'
2396             IF ( TRIM( var ) == 'tsurf*' )  unit = 'K'
2397             IF ( TRIM( var ) == 'us*'    )  unit = 'm/s'
2398             IF ( TRIM( var ) == 'z0*'    )  unit = 'm'
2399             IF ( TRIM( var ) == 'z0h*'   )  unit = 'm'
2400!
2401!--          Output of surface latent and sensible heat flux will be in W/m2 in case of natural- and
2402!--          urban-type surfaces, even if flux_output_mode is set to kinematic units.
2403             IF ( land_surface  .OR.  urban_surface )  THEN
2404                IF ( TRIM( var ) == 'shf*'   )  unit = 'W/m2'
2405                IF ( TRIM( var ) == 'qsws*'  )  unit = 'W/m2'
2406             ENDIF
2407
2408          CASE DEFAULT
2409!
2410!--          Check for other modules
2411             CALL module_interface_check_data_output( var, unit, i, j, ilen, k )
2412
2413             IF ( unit == 'illegal' )  THEN
2414                IF ( data_output_user(1) /= ' ' )  THEN
2415                   message_string = 'illegal value for data_output or ' //                         &
2416                                    'data_output_user = "' // TRIM( data_output(i) ) // '"'
2417                   CALL message( 'check_parameters', 'PA0114', 1, 2, 0, 6, 0 )
2418                ELSE
2419                   message_string = 'illegal value for data_output = "' //                         &
2420                                    TRIM( data_output(i) ) // '"'
2421                   CALL message( 'check_parameters', 'PA0115', 1, 2, 0, 6, 0 )
2422                ENDIF
2423             ENDIF
2424
2425       END SELECT
2426!
2427!--    Set the internal steering parameters appropriately
2428       IF ( k == 0 )  THEN
2429          do3d_no(j)              = do3d_no(j) + 1
2430          do3d(j,do3d_no(j))      = data_output(i)
2431          do3d_unit(j,do3d_no(j)) = unit
2432       ELSE
2433          do2d_no(j)              = do2d_no(j) + 1
2434          do2d(j,do2d_no(j))      = data_output(i)
2435          do2d_unit(j,do2d_no(j)) = unit
2436          IF ( data_output(i)(ilen-2:ilen) == '_xy' )  THEN
2437             data_output_xy(j) = .TRUE.
2438          ENDIF
2439          IF ( data_output(i)(ilen-2:ilen) == '_xz' )  THEN
2440             data_output_xz(j) = .TRUE.
2441          ENDIF
2442          IF ( data_output(i)(ilen-2:ilen) == '_yz' )  THEN
2443             data_output_yz(j) = .TRUE.
2444          ENDIF
2445       ENDIF
2446
2447       IF ( j == 1 )  THEN
2448!
2449!--       Check, if variable is already subject to averaging
2450          found = .FALSE.
2451          DO  k = 1, doav_n
2452             IF ( TRIM( doav(k) ) == TRIM( var ) )  found = .TRUE.
2453          ENDDO
2454
2455          IF ( .NOT. found )  THEN
2456             doav_n = doav_n + 1
2457             doav(doav_n) = var
2458          ENDIF
2459       ENDIF
2460
2461       i = i + 1
2462    ENDDO
2463
2464!
2465!-- Averaged 2d or 3d output requires that an averaging interval has been set
2466    IF ( doav_n > 0  .AND.  averaging_interval == 0.0_wp )  THEN
2467       WRITE( message_string, * )  'output of averaged quantity "', TRIM( doav(1) ),               &
2468                                   '_av" requires to set a ', 'non-zero averaging interval'
2469       CALL message( 'check_parameters', 'PA0323', 1, 2, 0, 6, 0 )
2470    ENDIF
2471
2472!
2473!-- Check sectional planes and store them in one shared array
2474    IF ( ANY( section_xy > nz + 1 ) )  THEN
2475       WRITE( message_string, * )  'section_xy must be <= nz + 1 = ', nz + 1
2476       CALL message( 'check_parameters', 'PA0319', 1, 2, 0, 6, 0 )
2477    ENDIF
2478    IF ( ANY( section_xz > ny + 1 ) )  THEN
2479       WRITE( message_string, * )  'section_xz must be <= ny + 1 = ', ny + 1
2480       CALL message( 'check_parameters', 'PA0320', 1, 2, 0, 6, 0 )
2481    ENDIF
2482    IF ( ANY( section_yz > nx + 1 ) )  THEN
2483       WRITE( message_string, * )  'section_yz must be <= nx + 1 = ', nx + 1
2484       CALL message( 'check_parameters', 'PA0321', 1, 2, 0, 6, 0 )
2485    ENDIF
2486    section(:,1) = section_xy
2487    section(:,2) = section_xz
2488    section(:,3) = section_yz
2489
2490    IF ( ANY( data_output_xy )  .AND.  .NOT. ANY( section(:,1) /= -9999 ) )  THEN
2491       WRITE( message_string, * )  'section_xy not defined for requested xy-cross section ' //     &
2492                                   'output.&At least one cross section must be given.'
2493       CALL message( 'check_parameters', 'PA0681', 1, 2, 0, 6, 0 )
2494    ENDIF
2495    IF ( ANY( data_output_xz )  .AND.  .NOT. ANY( section(:,2) /= -9999 ) )  THEN
2496       WRITE( message_string, * )  'section_xz not defined for requested xz-cross section ' //     &
2497                                   'output.&At least one cross section must be given.'
2498       CALL message( 'check_parameters', 'PA0681', 1, 2, 0, 6, 0 )
2499    ENDIF
2500    IF ( ANY( data_output_yz )  .AND.  .NOT. ANY( section(:,3) /= -9999 ) )  THEN
2501       WRITE( message_string, * )  'section_yz not defined for requested yz-cross section ' //     &
2502                                   'output.&At least one cross section must be given.'
2503       CALL message( 'check_parameters', 'PA0681', 1, 2, 0, 6, 0 )
2504    ENDIF
2505!
2506!-- Upper plot limit for 3D arrays
2507    IF ( nz_do3d == -9999 )  nz_do3d = nzt + 1
2508
2509!
2510!-- Set output format string (used in header)
2511    SELECT CASE ( netcdf_data_format )
2512       CASE ( 1 )
2513          netcdf_data_format_string = 'netCDF classic'
2514       CASE ( 2 )
2515          netcdf_data_format_string = 'netCDF 64bit offset'
2516       CASE ( 3 )
2517          netcdf_data_format_string = 'netCDF4/HDF5'
2518       CASE ( 4 )
2519          netcdf_data_format_string = 'netCDF4/HDF5 classic'
2520       CASE ( 5 )
2521          netcdf_data_format_string = 'parallel netCDF4/HDF5'
2522       CASE ( 6 )
2523          netcdf_data_format_string = 'parallel netCDF4/HDF5 classic'
2524
2525    END SELECT
2526
2527!
2528!-- Check mask conditions
2529    DO mid = 1, max_masks
2530       IF ( data_output_masks(mid,1) /= ' '  .OR.  data_output_masks_user(mid,1) /= ' ' )  THEN
2531          masks = masks + 1
2532       ENDIF
2533    ENDDO
2534
2535    IF ( masks < 0  .OR.  masks > max_masks )  THEN
2536       WRITE( message_string, * )  'illegal value: masks must be >= 0 and ', '<= ', max_masks,     &
2537              ' (=max_masks)'
2538       CALL message( 'check_parameters', 'PA0325', 1, 2, 0, 6, 0 )
2539    ENDIF
2540    IF ( masks > 0 )  THEN
2541       mask_scale(1) = mask_scale_x
2542       mask_scale(2) = mask_scale_y
2543       mask_scale(3) = mask_scale_z
2544       IF ( ANY( mask_scale <= 0.0_wp ) )  THEN
2545          WRITE( message_string, * )  'illegal value: mask_scale_x, mask_scale_y and mask_scale_z',&
2546                 'must be > 0.0'
2547          CALL message( 'check_parameters', 'PA0326', 1, 2, 0, 6, 0 )
2548       ENDIF
2549!
2550!--    Generate masks for masked data output.
2551!--    Parallel netcdf output is not tested so far for masked data, hence netcdf_data_format is
2552!--    switched back to non-parallel output.
2553       netcdf_data_format_save = netcdf_data_format
2554       IF ( netcdf_data_format > 4 )  THEN
2555          IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
2556          IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
2557          message_string = 'netCDF file formats '// '5 (parallel netCDF 4) and 6 (parallel ' //    &
2558                           'netCDF 4 Classic model) & are currently not supported (not yet ' //    &
2559                           'tested) for masked data. &Using respective non-parallel' //            &
2560                           ' output for masked data.'
2561          CALL message( 'check_parameters', 'PA0383', 0, 0, 0, 6, 0 )
2562       ENDIF
2563       CALL init_masks
2564       netcdf_data_format = netcdf_data_format_save
2565    ENDIF
2566
2567!
2568!-- Check the NetCDF data format
2569    IF ( netcdf_data_format > 2 )  THEN
2570#if defined( __netcdf4 )
2571       CONTINUE
2572#else
2573       message_string = 'netCDF: netCDF4 format requested but no ' //                              &
2574                        'cpp-directive __netcdf4 given & switch back to 64-bit offset format'
2575       CALL message( 'check_parameters', 'PA0171', 0, 1, 0, 6, 0 )
2576       netcdf_data_format = 2
2577#endif
2578    ENDIF
2579    IF ( netcdf_data_format > 4 )  THEN
2580#if defined( __netcdf4 ) && defined( __netcdf4_parallel )
2581       CONTINUE
2582#else
2583       message_string = 'netCDF: netCDF4 parallel output requested but no ' //                     &
2584                        'cpp-directive __netcdf4_parallel given & switch ' //                      &
2585                        'back to netCDF4 non-parallel output'
2586       CALL message( 'check_parameters', 'PA0099', 0, 1, 0, 6, 0 )
2587       netcdf_data_format = netcdf_data_format - 2
2588#endif
2589    ENDIF
2590
2591!
2592!-- Calculate fixed number of output time levels for parallel netcdf output.
2593!-- The time dimension has to be defined as limited for parallel output, because otherwise the I/O
2594!-- performance drops significantly.
2595    IF ( netcdf_data_format > 4 )  THEN
2596
2597!
2598!--    Check if any of the follwoing data output interval is 0.0s, which is not allowed for parallel
2599!--    output.
2600       CALL check_dt_do( dt_do3d,           'dt_do3d'           )
2601       CALL check_dt_do( dt_do2d_xy,        'dt_do2d_xy'        )
2602       CALL check_dt_do( dt_do2d_xz,        'dt_do2d_xz'        )
2603       CALL check_dt_do( dt_do2d_yz,        'dt_do2d_yz'        )
2604       CALL check_dt_do( dt_data_output_av, 'dt_data_output_av' )
2605
2606!--    Set needed time levels (ntdim) to saved time levels + to be saved time levels.
2607       ntdim_3d(0) = do3d_time_count(0) + CEILING(                                                 &
2608                     ( end_time - MAX(                                                             &
2609                         MERGE( skip_time_do3d, skip_time_do3d + spinup_time,                      &
2610                                data_output_during_spinup ),                                       &
2611                         simulated_time_at_begin )                                                 &
2612                     ) / dt_do3d )
2613       IF ( do3d_at_begin ) ntdim_3d(0) = ntdim_3d(0) + 1
2614
2615       ntdim_3d(1) = do3d_time_count(1) + CEILING(                                                 &
2616                     ( end_time - MAX(                                                             &
2617                         MERGE( skip_time_data_output_av, skip_time_data_output_av + spinup_time,  &
2618                                data_output_during_spinup ),                                       &
2619                         simulated_time_at_begin )                                                 &
2620                     ) / dt_data_output_av )
2621
2622       ntdim_2d_xy(0) = do2d_xy_time_count(0) + CEILING(                                           &
2623                        ( end_time - MAX(                                                          &
2624                            MERGE( skip_time_do2d_xy, skip_time_do2d_xy + spinup_time,             &
2625                                   data_output_during_spinup ),                                    &
2626                            simulated_time_at_begin )                                              &
2627                        ) / dt_do2d_xy )
2628
2629       ntdim_2d_xz(0) = do2d_xz_time_count(0) + CEILING(                                           &
2630                        ( end_time - MAX(                                                          &
2631                            MERGE( skip_time_do2d_xz, skip_time_do2d_xz + spinup_time,             &
2632                                   data_output_during_spinup ),                                    &
2633                            simulated_time_at_begin )                                              &
2634                        ) / dt_do2d_xz )
2635
2636       ntdim_2d_yz(0) = do2d_yz_time_count(0) + CEILING(                                           &
2637                        ( end_time - MAX(                                                          &
2638                            MERGE( skip_time_do2d_yz, skip_time_do2d_yz + spinup_time,             &
2639                                   data_output_during_spinup ),                                    &
2640                            simulated_time_at_begin )                                              &
2641                        ) / dt_do2d_yz )
2642
2643       IF ( do2d_at_begin )  THEN
2644          ntdim_2d_xy(0) = ntdim_2d_xy(0) + 1
2645          ntdim_2d_xz(0) = ntdim_2d_xz(0) + 1
2646          ntdim_2d_yz(0) = ntdim_2d_yz(0) + 1
2647       ENDIF
2648!
2649!--    Please note, for averaged 2D data skip_time_data_output_av is the relavant output control
2650!--    parameter.
2651       ntdim_2d_xy(1) = do2d_xy_time_count(1) + CEILING(                                           &
2652                        ( end_time - MAX( MERGE( skip_time_data_output_av,                         &
2653                                                 skip_time_data_output_av + spinup_time,           &
2654                                                 data_output_during_spinup ),                      &
2655                                          simulated_time_at_begin )                                &
2656                        ) / dt_data_output_av )
2657
2658       ntdim_2d_xz(1) = do2d_xz_time_count(1) + CEILING(                                           &
2659                        ( end_time - MAX( MERGE( skip_time_data_output_av,                         &
2660                                                 skip_time_data_output_av + spinup_time,           &
2661                                                 data_output_during_spinup ),                      &
2662                                          simulated_time_at_begin )                                &
2663                        ) / dt_data_output_av )
2664
2665       ntdim_2d_yz(1) = do2d_yz_time_count(1) + CEILING(                                           &
2666                        ( end_time - MAX( MERGE( skip_time_data_output_av,                         &
2667                                                 skip_time_data_output_av + spinup_time,           &
2668                                                 data_output_during_spinup ),                      &
2669                                          simulated_time_at_begin )                                &
2670                        ) / dt_data_output_av )
2671
2672    ENDIF
2673
2674!
2675!-- Check, whether a constant diffusion coefficient shall be used
2676    IF ( km_constant /= -1.0_wp )  THEN
2677       IF ( km_constant < 0.0_wp )  THEN
2678          WRITE( message_string, * )  'km_constant = ', km_constant, ' < 0.0'
2679          CALL message( 'check_parameters', 'PA0121', 1, 2, 0, 6, 0 )
2680       ELSE
2681          IF ( prandtl_number < 0.0_wp )  THEN
2682             WRITE( message_string, * )  'prandtl_number = ', prandtl_number, ' < 0.0'
2683             CALL message( 'check_parameters', 'PA0122', 1, 2, 0, 6, 0 )
2684          ENDIF
2685          constant_diffusion = .TRUE.
2686
2687          IF ( constant_flux_layer )  THEN
2688             message_string = 'constant_flux_layer is not allowed with fixed value of km'
2689             CALL message( 'check_parameters', 'PA0123', 1, 2, 0, 6, 0 )
2690          ENDIF
2691       ENDIF
2692    ENDIF
2693
2694!
2695!-- In case of non-cyclic lateral boundaries and a damping layer for the potential temperature,
2696!-- check the width of the damping layer
2697    IF ( bc_lr /= 'cyclic' ) THEN
2698       IF ( pt_damping_width < 0.0_wp  .OR.  pt_damping_width > REAL( (nx+1) * dx ) )  THEN
2699          message_string = 'pt_damping_width out of range'
2700          CALL message( 'check_parameters', 'PA0124', 1, 2, 0, 6, 0 )
2701       ENDIF
2702    ENDIF
2703
2704    IF ( bc_ns /= 'cyclic' )  THEN
2705       IF ( pt_damping_width < 0.0_wp  .OR.  pt_damping_width > REAL( (ny+1) * dy ) )  THEN
2706          message_string = 'pt_damping_width out of range'
2707          CALL message( 'check_parameters', 'PA0124', 1, 2, 0, 6, 0 )
2708       ENDIF
2709    ENDIF
2710
2711!
2712!-- Check value range for zeta = z/L
2713    IF ( zeta_min >= zeta_max )  THEN
2714       WRITE( message_string, * )  'zeta_min = ', zeta_min, ' must be less ', 'than zeta_max = ',  &
2715              zeta_max
2716       CALL message( 'check_parameters', 'PA0125', 1, 2, 0, 6, 0 )
2717    ENDIF
2718
2719!
2720!-- Check random generator
2721    IF ( (random_generator /= 'system-specific'      .AND.                                         &
2722          random_generator /= 'random-parallel'   )  .AND.                                         &
2723          random_generator /= 'numerical-recipes' )  THEN
2724       message_string = 'unknown random generator: random_generator = "' //                        &
2725                        TRIM( random_generator ) // '"'
2726       CALL message( 'check_parameters', 'PA0135', 1, 2, 0, 6, 0 )
2727    ENDIF
2728
2729!
2730!-- Determine upper and lower hight level indices for random perturbations
2731    IF ( disturbance_level_b == -9999999.9_wp )  THEN
2732       IF ( ocean_mode )  THEN
2733          disturbance_level_b     = zu((nzt*2)/3)
2734          disturbance_level_ind_b = ( nzt * 2 ) / 3
2735       ELSE
2736          disturbance_level_b     = zu(nzb+3)
2737          disturbance_level_ind_b = nzb + 3
2738       ENDIF
2739    ELSEIF ( disturbance_level_b < zu(3) )  THEN
2740       WRITE( message_string, * )  'disturbance_level_b = ', disturbance_level_b, ' must be >= ',  &
2741              zu(3), '(zu(3))'
2742       CALL message( 'check_parameters', 'PA0126', 1, 2, 0, 6, 0 )
2743    ELSEIF ( disturbance_level_b > zu(nzt-2) )  THEN
2744       WRITE( message_string, * )  'disturbance_level_b = ', disturbance_level_b, ' must be <= ',  &
2745              zu(nzt-2), '(zu(nzt-2))'
2746       CALL message( 'check_parameters', 'PA0127', 1, 2, 0, 6, 0 )
2747    ELSE
2748       DO  k = 3, nzt-2
2749          IF ( disturbance_level_b <= zu(k) )  THEN
2750             disturbance_level_ind_b = k
2751             EXIT
2752          ENDIF
2753       ENDDO
2754    ENDIF
2755
2756    IF ( disturbance_level_t == -9999999.9_wp )  THEN
2757       IF ( ocean_mode )  THEN
2758          disturbance_level_t     = zu(nzt-3)
2759          disturbance_level_ind_t = nzt - 3
2760       ELSE
2761          disturbance_level_t     = zu(nzt/3)
2762          disturbance_level_ind_t = nzt / 3
2763       ENDIF
2764    ELSEIF ( disturbance_level_t > zu(nzt-2) )  THEN
2765       WRITE( message_string, * )  'disturbance_level_t = ', disturbance_level_t, ' must be <= ',  &
2766              zu(nzt-2), '(zu(nzt-2))'
2767       CALL message( 'check_parameters', 'PA0128', 1, 2, 0, 6, 0 )
2768    ELSEIF ( disturbance_level_t < disturbance_level_b )  THEN
2769       WRITE( message_string, * )  'disturbance_level_t = ', disturbance_level_t,                  &
2770             ' must be >= disturbance_level_b = ', disturbance_level_b
2771       CALL message( 'check_parameters', 'PA0129', 1, 2, 0, 6, 0 )
2772    ELSE
2773       DO  k = 3, nzt-2
2774          IF ( disturbance_level_t <= zu(k) )  THEN
2775             disturbance_level_ind_t = k
2776             EXIT
2777          ENDIF
2778       ENDDO
2779    ENDIF
2780
2781!
2782!-- Check again whether the levels determined this way are ok.
2783!-- Error may occur at automatic determination and too few grid points in z-direction.
2784    IF ( disturbance_level_ind_t < disturbance_level_ind_b )  THEN
2785       WRITE( message_string, * )  'disturbance_level_ind_t = ', disturbance_level_ind_t,          &
2786              ' must be >= ', 'disturbance_level_ind_b = ', disturbance_level_ind_b
2787       CALL message( 'check_parameters', 'PA0130', 1, 2, 0, 6, 0 )
2788    ENDIF
2789
2790!
2791!-- Determine the horizontal index range for random perturbations.
2792!-- In case of non-cyclic horizontal boundaries, no perturbations are imposed near the inflow and
2793!-- the perturbation area is further limited to ...(1) after the initial phase of the flow.
2794
2795    IF ( bc_lr /= 'cyclic' )  THEN
2796       IF ( inflow_disturbance_begin == -1 )  THEN
2797          inflow_disturbance_begin = MIN( 10, nx/2 )
2798       ENDIF
2799       IF ( inflow_disturbance_begin < 0  .OR.  inflow_disturbance_begin > nx )  THEN
2800          message_string = 'inflow_disturbance_begin out of range'
2801          CALL message( 'check_parameters', 'PA0131', 1, 2, 0, 6, 0 )
2802       ENDIF
2803       IF ( inflow_disturbance_end == -1 )  THEN
2804          inflow_disturbance_end = MIN( 100, 3*nx/4 )
2805       ENDIF
2806       IF ( inflow_disturbance_end < 0  .OR.  inflow_disturbance_end > nx )  THEN
2807          message_string = 'inflow_disturbance_end out of range'
2808          CALL message( 'check_parameters', 'PA0132', 1, 2, 0, 6, 0 )
2809       ENDIF
2810    ELSEIF ( bc_ns /= 'cyclic' )  THEN
2811       IF ( inflow_disturbance_begin == -1 )  THEN
2812          inflow_disturbance_begin = MIN( 10, ny/2 )
2813       ENDIF
2814       IF ( inflow_disturbance_begin < 0  .OR.  inflow_disturbance_begin > ny )  THEN
2815          message_string = 'inflow_disturbance_begin out of range'
2816          CALL message( 'check_parameters', 'PA0131', 1, 2, 0, 6, 0 )
2817       ENDIF
2818       IF ( inflow_disturbance_end == -1 )  THEN
2819          inflow_disturbance_end = MIN( 100, 3*ny/4 )
2820       ENDIF
2821       IF ( inflow_disturbance_end < 0  .OR.  inflow_disturbance_end > ny )  THEN
2822          message_string = 'inflow_disturbance_end out of range'
2823          CALL message( 'check_parameters', 'PA0132', 1, 2, 0, 6, 0 )
2824       ENDIF
2825    ENDIF
2826
2827    IF ( random_generator == 'random-parallel' )  THEN
2828       dist_nxl = nxl;  dist_nxr = nxr
2829       dist_nys = nys;  dist_nyn = nyn
2830       IF ( bc_lr == 'radiation/dirichlet' )  THEN
2831          dist_nxr    = MIN( nx - inflow_disturbance_begin, nxr )
2832          dist_nxl(1) = MAX( nx - inflow_disturbance_end, nxl )
2833       ELSEIF ( bc_lr == 'dirichlet/radiation' )  THEN
2834          dist_nxl    = MAX( inflow_disturbance_begin, nxl )
2835          dist_nxr(1) = MIN( inflow_disturbance_end, nxr )
2836       ELSEIF ( bc_lr == 'nested'  .OR.  bc_lr == 'nesting_offline' )  THEN
2837          dist_nxl    = MAX( inflow_disturbance_begin, nxl )
2838          dist_nxr    = MIN( nx - inflow_disturbance_begin, nxr )
2839       ENDIF
2840       IF ( bc_ns == 'dirichlet/radiation' )  THEN
2841          dist_nyn    = MIN( ny - inflow_disturbance_begin, nyn )
2842          dist_nys(1) = MAX( ny - inflow_disturbance_end, nys )
2843       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
2844          dist_nys    = MAX( inflow_disturbance_begin, nys )
2845          dist_nyn(1) = MIN( inflow_disturbance_end, nyn )
2846       ELSEIF ( bc_ns == 'nested'  .OR.  bc_ns == 'nesting_offline' )  THEN
2847          dist_nys    = MAX( inflow_disturbance_begin, nys )
2848          dist_nyn    = MIN( ny - inflow_disturbance_begin, nyn )
2849       ENDIF
2850    ELSE
2851       dist_nxl = 0;  dist_nxr = nx
2852       dist_nys = 0;  dist_nyn = ny
2853       IF ( bc_lr == 'radiation/dirichlet' )  THEN
2854          dist_nxr    = nx - inflow_disturbance_begin
2855          dist_nxl(1) = nx - inflow_disturbance_end
2856       ELSEIF ( bc_lr == 'dirichlet/radiation' )  THEN
2857          dist_nxl    = inflow_disturbance_begin
2858          dist_nxr(1) = inflow_disturbance_end
2859       ELSEIF ( bc_lr == 'nested'  .OR.  bc_lr == 'nesting_offline' )  THEN
2860          dist_nxr    = nx - inflow_disturbance_begin
2861          dist_nxl    = inflow_disturbance_begin
2862       ENDIF
2863       IF ( bc_ns == 'dirichlet/radiation' )  THEN
2864          dist_nyn    = ny - inflow_disturbance_begin
2865          dist_nys(1) = ny - inflow_disturbance_end
2866       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
2867          dist_nys    = inflow_disturbance_begin
2868          dist_nyn(1) = inflow_disturbance_end
2869       ELSEIF ( bc_ns == 'nested'  .OR.  bc_ns == 'nesting_offline' )  THEN
2870          dist_nyn    = ny - inflow_disturbance_begin
2871          dist_nys    = inflow_disturbance_begin
2872       ENDIF
2873    ENDIF
2874
2875!
2876!-- A turbulent inflow requires Dirichlet conditions at the respective inflow boundary (so far, a
2877!-- turbulent inflow is realized from the left side only).
2878    IF ( turbulent_inflow  .AND.  bc_lr /= 'dirichlet/radiation' )  THEN
2879       message_string = 'turbulent_inflow = .T. requires a Dirichlet ' //                          &
2880                        'condition at the inflow boundary'
2881       CALL message( 'check_parameters', 'PA0133', 1, 2, 0, 6, 0 )
2882    ENDIF
2883
2884!
2885!-- Turbulent inflow requires that 3d arrays have been cyclically filled with data from prerun in
2886!-- the first main run
2887    IF ( turbulent_inflow  .AND.  initializing_actions /= 'cyclic_fill'  .AND.                     &
2888         initializing_actions /= 'read_restart_data' )  THEN
2889       message_string = 'turbulent_inflow = .T. requires ' //                                      &
2890                        'initializing_actions = ''cyclic_fill'' or ' //                            &
2891                        'initializing_actions = ''read_restart_data'' '
2892       CALL message( 'check_parameters', 'PA0055', 1, 2, 0, 6, 0 )
2893    ENDIF
2894
2895!
2896!-- In case of turbulent inflow
2897    IF ( turbulent_inflow )  THEN
2898
2899!
2900!--    Calculate the index of the recycling plane
2901       IF ( recycling_width <= dx  .OR.  recycling_width >= nx * dx )  THEN
2902          WRITE( message_string, * )  'illegal value for recycling_width: ', recycling_width
2903          CALL message( 'check_parameters', 'PA0134', 1, 2, 0, 6, 0 )
2904       ENDIF
2905!
2906!--    Calculate the index
2907       recycling_plane = recycling_width / dx
2908!
2909!--   Check for correct input of recycling method for thermodynamic quantities
2910       IF ( TRIM( recycling_method_for_thermodynamic_quantities ) /= 'turbulent_fluctuation'  .AND.&
2911            TRIM( recycling_method_for_thermodynamic_quantities ) /= 'absolute_value' )  THEN
2912          WRITE( message_string, * )  'unknown recycling method for thermodynamic quantities: ',   &
2913               TRIM( recycling_method_for_thermodynamic_quantities )
2914          CALL message( 'check_parameters', 'PA0184', 1, 2, 0, 6, 0 )
2915       ENDIF
2916
2917    ENDIF
2918
2919
2920    IF ( turbulent_outflow )  THEN
2921!
2922!--    Turbulent outflow requires Dirichlet conditions at the respective inflow boundary (so far, a
2923!--    turbulent outflow is realized at the right side only).
2924       IF ( bc_lr /= 'dirichlet/radiation' )  THEN
2925          message_string = 'turbulent_outflow = .T. requires bc_lr = "dirichlet/radiation"'
2926          CALL message( 'check_parameters', 'PA0038', 1, 2, 0, 6, 0 )
2927       ENDIF
2928!
2929!--    The ouflow-source plane must lay inside the model domain
2930       IF ( outflow_source_plane < dx  .OR.  outflow_source_plane > nx * dx )  THEN
2931          WRITE( message_string, * )  'illegal value for outflow_source'// '_plane: ',             &
2932                 outflow_source_plane
2933          CALL message( 'check_parameters', 'PA0145', 1, 2, 0, 6, 0 )
2934       ENDIF
2935    ENDIF
2936
2937!
2938!-- Determine damping level index for 1D model
2939    IF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
2940       IF ( damp_level_1d == -1.0_wp )  THEN
2941          damp_level_1d     = zu(nzt+1)
2942          damp_level_ind_1d = nzt + 1
2943       ELSEIF ( damp_level_1d < 0.0_wp  .OR.  damp_level_1d > zu(nzt+1) )  THEN
2944          WRITE( message_string, * )  'damp_level_1d = ', damp_level_1d, ' must be >= 0.0 and <= ',&
2945                 zu(nzt+1), '(zu(nzt+1))'
2946          CALL message( 'check_parameters', 'PA0136', 1, 2, 0, 6, 0 )
2947       ELSE
2948          DO  k = 1, nzt+1
2949             IF ( damp_level_1d <= zu(k) )  THEN
2950                damp_level_ind_1d = k
2951                EXIT
2952             ENDIF
2953          ENDDO
2954       ENDIF
2955    ENDIF
2956
2957!
2958!-- Check some other 1d-model parameters
2959    IF ( TRIM( mixing_length_1d ) /= 'as_in_3d_model'  .AND.                                       &
2960         TRIM( mixing_length_1d ) /= 'blackadar' )  THEN
2961       message_string = 'mixing_length_1d = "' // TRIM( mixing_length_1d ) // '" is unknown'
2962       CALL message( 'check_parameters', 'PA0137', 1, 2, 0, 6, 0 )
2963    ENDIF
2964    IF ( TRIM( dissipation_1d ) /= 'as_in_3d_model'  .AND.                                         &
2965         TRIM( dissipation_1d ) /= 'detering'        .AND.                                         &
2966         TRIM( dissipation_1d ) /= 'prognostic' )  THEN
2967       message_string = 'dissipation_1d = "' // TRIM( dissipation_1d ) // '" is unknown'
2968       CALL message( 'check_parameters', 'PA0138', 1, 2, 0, 6, 0 )
2969    ENDIF
2970    IF ( TRIM( mixing_length_1d ) /= 'as_in_3d_model'  .AND.                                       &
2971         TRIM( dissipation_1d ) == 'as_in_3d_model' )  THEN
2972       message_string = 'dissipation_1d = "' // TRIM( dissipation_1d ) //                          &
2973                        '" requires mixing_length_1d = "as_in_3d_model"'
2974       CALL message( 'check_parameters', 'PA0485', 1, 2, 0, 6, 0 )
2975    ENDIF
2976
2977!
2978!-- Set time for the next user defined restart (time_restart is the internal parameter for steering
2979!-- restart events)
2980    IF ( restart_time /= 9999999.9_wp )  THEN
2981       IF ( restart_time > time_since_reference_point )  THEN
2982          time_restart = restart_time
2983       ENDIF
2984    ELSE
2985!
2986!--    In case of a restart run, set internal parameter to default (no restart) if the
2987!--    NAMELIST-parameter restart_time is omitted
2988       time_restart = 9999999.9_wp
2989    ENDIF
2990
2991!
2992!-- Check pressure gradient conditions
2993    IF ( dp_external  .AND.  conserve_volume_flow )  THEN
2994       WRITE( message_string, * )  'Both dp_external and conserve_volume_flo',                     &
2995              'w are .TRUE. but one of them must be .FALSE.'
2996       CALL message( 'check_parameters', 'PA0150', 1, 2, 0, 6, 0 )
2997    ENDIF
2998    IF ( dp_external )  THEN
2999       IF ( dp_level_b < zu(nzb)  .OR.  dp_level_b > zu(nzt) )  THEN
3000          WRITE( message_string, * )  'dp_level_b = ', dp_level_b, ' is out ',                     &
3001                 ' of range [zu(nzb), zu(nzt)]'
3002          CALL message( 'check_parameters', 'PA0151', 1, 2, 0, 6, 0 )
3003       ENDIF
3004       IF ( .NOT. ANY( dpdxy /= 0.0_wp ) )  THEN
3005          WRITE( message_string, * )  'dp_external is .TRUE. but dpdxy is ze',                     &
3006                 'ro, i.e. the external pressure gradient will not be applied'
3007          CALL message( 'check_parameters', 'PA0152', 0, 1, 0, 6, 0 )
3008       ENDIF
3009    ENDIF
3010    IF ( ANY( dpdxy /= 0.0_wp )  .AND.  .NOT.  dp_external )  THEN
3011       WRITE( message_string, * )  'dpdxy is nonzero but dp_external is ',                         &
3012              '.FALSE., i.e. the external pressure gradient & will not be applied'
3013       CALL message( 'check_parameters', 'PA0153', 0, 1, 0, 6, 0 )
3014    ENDIF
3015    IF ( conserve_volume_flow )  THEN
3016       IF ( TRIM( conserve_volume_flow_mode ) == 'default' )  THEN
3017
3018          conserve_volume_flow_mode = 'initial_profiles'
3019
3020       ELSEIF ( TRIM( conserve_volume_flow_mode ) /= 'initial_profiles'  .AND.                     &
3021                TRIM( conserve_volume_flow_mode ) /= 'bulk_velocity' )  THEN
3022          WRITE( message_string, * )  'unknown conserve_volume_flow_mode: ',                       &
3023                 conserve_volume_flow_mode
3024          CALL message( 'check_parameters', 'PA0154', 1, 2, 0, 6, 0 )
3025       ENDIF
3026       IF ( ( bc_lr /= 'cyclic'  .OR.  bc_ns /= 'cyclic')  .AND.                                   &
3027            TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' )  THEN
3028          WRITE( message_string, * )  'non-cyclic boundary conditions ',                           &
3029                 'require  conserve_volume_flow_mode = ''initial_profiles'''
3030          CALL message( 'check_parameters', 'PA0155', 1, 2, 0, 6, 0 )
3031       ENDIF
3032    ENDIF
3033    IF ( ( u_bulk /= 0.0_wp .OR. v_bulk /= 0.0_wp )  .AND.                                         &
3034         ( .NOT. conserve_volume_flow .OR. TRIM( conserve_volume_flow_mode ) /= 'bulk_velocity' ) )&
3035    THEN
3036       WRITE( message_string, * )  'nonzero bulk velocity requires ',                              &
3037              'conserve_volume_flow = .T. and ', 'conserve_volume_flow_mode = ''bulk_velocity'''
3038       CALL message( 'check_parameters', 'PA0157', 1, 2, 0, 6, 0 )
3039    ENDIF
3040
3041!
3042!-- Prevent empty time records in volume, cross-section and masked data in case of non-parallel
3043!-- netcdf-output in restart runs
3044    IF ( netcdf_data_format < 5 )  THEN
3045       IF ( TRIM( initializing_actions ) == 'read_restart_data' )  THEN
3046          do3d_time_count    = 0
3047          do2d_xy_time_count = 0
3048          do2d_xz_time_count = 0
3049          do2d_yz_time_count = 0
3050          domask_time_count  = 0
3051       ENDIF
3052    ENDIF
3053
3054
3055!
3056!-- Check roughness length, which has to be smaller than dz/2
3057    IF ( ( constant_flux_layer .OR. INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  &
3058         .AND.  roughness_length >= 0.5 * dz(1) )  THEN
3059       message_string = 'roughness_length must be smaller than dz/2'
3060       CALL message( 'check_parameters', 'PA0424', 1, 2, 0, 6, 0 )
3061    ENDIF
3062
3063!
3064!-- Check if topography is read from file in case of complex terrain simulations
3065    IF ( complex_terrain  .AND.  TRIM( topography ) /= 'read_from_file' )  THEN
3066       message_string = 'complex_terrain requires topography = ''read_from_file'''
3067       CALL message( 'check_parameters', 'PA0295', 1, 2, 0, 6, 0 )
3068    ENDIF
3069
3070!
3071!-- Check if vertical grid stretching is switched off in case of complex terrain simulations
3072    IF ( complex_terrain  .AND.  ANY( dz_stretch_level_start /= -9999999.9_wp ) )  THEN
3073       message_string = 'Vertical grid stretching is not allowed for complex_terrain = .TRUE.'
3074       CALL message( 'check_parameters', 'PA0473', 1, 2, 0, 6, 0 )
3075    ENDIF
3076
3077    CALL location_message( 'checking parameters', 'finished' )
3078
3079 CONTAINS
3080
3081!--------------------------------------------------------------------------------------------------!
3082! Description:
3083! ------------
3084!> Check the length of data output intervals. In case of parallel NetCDF output the time levels of
3085!> the output files need to be fixed. Therefore setting the output interval to 0.0s (usually used to
3086!> output each timestep) is not possible as long as a non-fixed timestep is used.
3087!--------------------------------------------------------------------------------------------------!
3088
3089    SUBROUTINE check_dt_do( dt_do, dt_do_name )
3090
3091       IMPLICIT NONE
3092
3093       CHARACTER (LEN=*), INTENT (IN) :: dt_do_name !< parin variable name
3094
3095       REAL(wp), INTENT (INOUT)       :: dt_do      !< data output interval
3096
3097       IF ( dt_do == 0.0_wp )  THEN
3098          IF ( dt_fixed )  THEN
3099             WRITE( message_string, '(A,F9.4,A)' )  'Output at every timestep is wanted (' //      &
3100                    dt_do_name // ' = 0.0).&'//                                                    &
3101                    'The output interval is set to the fixed timestep dt '// '= ', dt, 's.'
3102             CALL message( 'check_parameters', 'PA0060', 0, 0, 0, 6, 0 )
3103             dt_do = dt
3104          ELSE
3105             message_string = dt_do_name // ' = 0.0 while using a ' //                             &
3106                              'variable timestep and parallel netCDF4 is not allowed.'
3107             CALL message( 'check_parameters', 'PA0081', 1, 2, 0, 6, 0 )
3108          ENDIF
3109       ENDIF
3110
3111    END SUBROUTINE check_dt_do
3112
3113
3114
3115!--------------------------------------------------------------------------------------------------!
3116! Description:
3117! ------------
3118!> Set the bottom and top boundary conditions for humidity and scalars.
3119!--------------------------------------------------------------------------------------------------!
3120
3121    SUBROUTINE set_bc_scalars( sq, bc_b, bc_t, ibc_b, ibc_t, err_nr_b, err_nr_t )
3122
3123
3124       IMPLICIT NONE
3125
3126       CHARACTER (LEN=*)   ::  bc_b       !< bottom boundary condition
3127       CHARACTER (LEN=*)   ::  bc_t       !< top boundary condition
3128       CHARACTER (LEN=*)   ::  err_nr_b   !< error number if bottom bc is unknown
3129       CHARACTER (LEN=*)   ::  err_nr_t   !< error number if top bc is unknown
3130       CHARACTER (LEN=1)   ::  sq         !< name of scalar quantity
3131
3132
3133       INTEGER(iwp)        ::  ibc_b      !< index for bottom boundary condition
3134       INTEGER(iwp)        ::  ibc_t      !< index for top boundary condition
3135
3136!
3137!--    Set Integer flags and check for possilbe errorneous settings for bottom boundary condition
3138       IF ( bc_b == 'dirichlet' )  THEN
3139          ibc_b = 0
3140       ELSEIF ( bc_b == 'neumann' )  THEN
3141          ibc_b = 1
3142       ELSE
3143          message_string = 'unknown boundary condition: bc_' // TRIM( sq ) // '_b ="' //           &
3144                           TRIM( bc_b ) // '"'
3145          CALL message( 'check_parameters', err_nr_b, 1, 2, 0, 6, 0 )
3146       ENDIF
3147!
3148!--    Set Integer flags and check for possilbe errorneous settings for top boundary condition
3149       IF ( bc_t == 'dirichlet' )  THEN
3150          ibc_t = 0
3151       ELSEIF ( bc_t == 'neumann' )  THEN
3152          ibc_t = 1
3153       ELSEIF ( bc_t == 'initial_gradient' )  THEN
3154          ibc_t = 2
3155       ELSEIF ( bc_t == 'nested'  .OR.  bc_t == 'nesting_offline' )  THEN
3156          ibc_t = 3
3157       ELSE
3158          message_string = 'unknown boundary condition: bc_' // TRIM( sq ) // '_t ="' //           &
3159                           TRIM( bc_t ) // '"'
3160          CALL message( 'check_parameters', err_nr_t, 1, 2, 0, 6, 0 )
3161       ENDIF
3162
3163
3164    END SUBROUTINE set_bc_scalars
3165
3166
3167
3168!--------------------------------------------------------------------------------------------------!
3169! Description:
3170! ------------
3171!> Check for consistent settings of bottom boundary conditions for humidity and scalars.
3172!--------------------------------------------------------------------------------------------------!
3173
3174    SUBROUTINE check_bc_scalars( sq, bc_b, ibc_b, err_nr_1, err_nr_2, constant_flux,               &
3175                                 surface_initial_change )
3176
3177
3178       IMPLICIT NONE
3179
3180       CHARACTER (LEN=*)   ::  bc_b                     !< bottom boundary condition
3181       CHARACTER (LEN=*)   ::  err_nr_1                 !< error number of first error
3182       CHARACTER (LEN=*)   ::  err_nr_2                 !< error number of second error
3183       CHARACTER (LEN=1)   ::  sq                       !< name of scalar quantity
3184
3185
3186       INTEGER(iwp)        ::  ibc_b                    !< index of bottom boundary condition
3187
3188       LOGICAL             ::  constant_flux            !< flag for constant-flux layer
3189
3190       REAL(wp)            ::  surface_initial_change   !< value of initial change at the surface
3191
3192!
3193!--    A given surface value implies Dirichlet boundary condition for the respective quantity. In
3194!--    this case specification of a constant flux is forbidden. However, an exception is made for
3195!--    large-scale forcing as well as land-surface model.
3196       IF ( .NOT. land_surface  .AND.  .NOT. large_scale_forcing )  THEN
3197          IF ( ibc_b == 0  .AND.  constant_flux )  THEN
3198             message_string = 'boundary condition: bc_' // TRIM( sq ) // '_b = "' //               &
3199                              TRIM( bc_b ) // '" is not allowed with prescribed surface flux'
3200             CALL message( 'check_parameters', err_nr_1, 1, 2, 0, 6, 0 )
3201          ENDIF
3202       ENDIF
3203       IF ( constant_flux  .AND.  surface_initial_change /= 0.0_wp )  THEN
3204          WRITE( message_string, * )  'a prescribed surface flux is not allo', 'wed with ', sq,    &
3205                '_surface_initial_change (/=0) = ', surface_initial_change
3206          CALL message( 'check_parameters', err_nr_2, 1, 2, 0, 6, 0 )
3207       ENDIF
3208
3209
3210    END SUBROUTINE check_bc_scalars
3211
3212
3213
3214 END SUBROUTINE check_parameters
Note: See TracBrowser for help on using the repository browser.