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

Last change on this file since 4391 was 4384, checked in by Giersch, 4 years ago

Header corrected

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