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

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

restart data handling with MPI-IO added, first part

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