source: palm/trunk/SOURCE/check_parameters.f90

Last change on this file was 4856, checked in by raasch, 3 years ago

array sizes for output profiles increased from 400 to 500

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