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

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

I/O on reduced number of cores added (using shared memory MPI)

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