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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

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