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

Last change on this file since 4559 was 4559, checked in by raasch, 4 years ago

files re-formatted to follow the PALM coding standard

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