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

Last change on this file since 4210 was 4196, checked in by gronemeier, 5 years ago

Consider rotation of model domain for claculation of Coriolis force:

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