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

Last change on this file since 4381 was 4360, checked in by suehring, 4 years ago

Bugfix in output of time-averaged plant-canopy quanities; Output of plant-canopy data only where tall canopy is defined; land-surface model: fix wrong location strings; tests: update urban test case; all source code files: copyright update

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