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

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

messages and debug output converted to PALM routines (restart_data_mpi_io_mod), binary version number set to 5.0, heeader output for restart data format added, restart data filesize and I/O transfer speed added in cpu_measures, handling of single restart files (created with MPI-I/O) added to palmrun, bugfix: preprocessor directive adjusted (virtual_measurement_mod), location message format changed

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