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

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