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

Last change on this file since 4513 was 4513, checked in by raasch, 5 years ago

dependencies from chemistry modules updated

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