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

Last change on this file since 1496 was 1496, checked in by maronga, 9 years ago

added beta version of a land surface model and a simple radiation model for clear sky conditions

  • Property svn:keywords set to Id
File size: 153.6 KB
Line 
1 SUBROUTINE check_parameters
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later 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-2014 Leibniz Universitaet Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22! Added checks for the land surface model
23!
24! Former revisions:
25! -----------------
26! $Id: check_parameters.f90 1496 2014-12-02 17:25:50Z maronga $
27!
28! 1484 2014-10-21 10:53:05Z kanani
29! Changes due to new module structure of the plant canopy model:
30!   module plant_canopy_model_mod added,
31!   checks regarding usage of new method for leaf area density profile
32!   construction added,
33!   lad-profile construction moved to new subroutine init_plant_canopy within
34!   the module plant_canopy_model_mod,
35!   drag_coefficient renamed to canopy_drag_coeff.
36! Missing KIND-attribute for REAL constant added
37!
38! 1455 2014-08-29 10:47:47Z heinze
39! empty time records in volume, cross-section and masked data output prevented 
40! in case of non-parallel netcdf-output in restart runs
41!
42! 1429 2014-07-15 12:53:45Z knoop
43! run_description_header exended to provide ensemble_member_nr if specified
44!
45! 1425 2014-07-05 10:57:53Z knoop
46! bugfix: perturbation domain modified for parallel random number generator
47!
48! 1402 2014-05-09 14:25:13Z raasch
49! location messages modified
50!
51! 1400 2014-05-09 14:03:54Z knoop
52! Check random generator extended by option random-parallel
53!
54! 1384 2014-05-02 14:31:06Z raasch
55! location messages added
56!
57! 1365 2014-04-22 15:03:56Z boeske
58! Usage of large scale forcing for pt and q enabled:
59! output for profiles of large scale advection (td_lsa_lpt, td_lsa_q),
60! large scale subsidence (td_sub_lpt, td_sub_q)
61! and nudging tendencies (td_nud_lpt, td_nud_q, td_nud_u and td_nud_v) added,
62! check if use_subsidence_tendencies is used correctly
63!
64! 1361 2014-04-16 15:17:48Z hoffmann
65! PA0363 removed
66! PA0362 changed
67!
68! 1359 2014-04-11 17:15:14Z hoffmann
69! Do not allow the execution of PALM with use_particle_tails, since particle
70! tails are currently not supported by our new particle structure.
71!
72! PA0084 not necessary for new particle structure
73!
74! 1353 2014-04-08 15:21:23Z heinze
75! REAL constants provided with KIND-attribute
76!
77! 1330 2014-03-24 17:29:32Z suehring
78! In case of SGS-particle velocity advection of TKE is also allowed with
79! dissipative 5th-order scheme.
80!
81! 1327 2014-03-21 11:00:16Z raasch
82! "baroclinicity" renamed "baroclinity", "ocean version" replaced by "ocean mode"
83! bugfix: duplicate error message 56 removed,
84! check of data_output_format and do3d_compress removed
85!
86! 1322 2014-03-20 16:38:49Z raasch
87! some REAL constants defined as wp-kind
88!
89! 1320 2014-03-20 08:40:49Z raasch
90! Kind-parameters added to all INTEGER and REAL declaration statements,
91! kinds are defined in new module kinds,
92! revision history before 2012 removed,
93! comment fields (!:) to be used for variable explanations added to
94! all variable declaration statements
95!
96! 1308 2014-03-13 14:58:42Z fricke
97! +netcdf_data_format_save
98! Calculate fixed number of output time levels for parallel netcdf output.
99! For masked data, parallel netcdf output is not tested so far, hence
100! netcdf_data_format is switched back to non-paralell output.
101!
102! 1299 2014-03-06 13:15:21Z heinze
103! enable usage of large_scale subsidence in combination with large_scale_forcing
104! output for profile of large scale vertical velocity w_subs added
105!
106! 1276 2014-01-15 13:40:41Z heinze
107! Use LSF_DATA also in case of Dirichlet bottom boundary condition for scalars
108!
109! 1241 2013-10-30 11:36:58Z heinze
110! output for profiles of ug and vg added
111! set surface_heatflux and surface_waterflux also in dependence on
112! large_scale_forcing
113! checks for nudging and large scale forcing from external file
114!
115! 1236 2013-09-27 07:21:13Z raasch
116! check number of spectra levels
117!
118! 1216 2013-08-26 09:31:42Z raasch
119! check for transpose_compute_overlap (temporary)
120!
121! 1214 2013-08-21 12:29:17Z kanani
122! additional check for simultaneous use of vertical grid stretching
123! and particle advection
124!
125! 1212 2013-08-15 08:46:27Z raasch
126! checks for poisfft_hybrid removed
127!
128! 1210 2013-08-14 10:58:20Z raasch
129! check for fftw
130!
131! 1179 2013-06-14 05:57:58Z raasch
132! checks and settings of buoyancy parameters and switches revised,
133! initial profile for rho added to hom (id=77)
134!
135! 1174 2013-05-31 10:28:08Z gryschka
136! Bugfix in computing initial profiles for ug, vg, lad, q in case of Atmosphere
137!
138! 1159 2013-05-21 11:58:22Z fricke
139! bc_lr/ns_dirneu/neudir removed
140!
141! 1115 2013-03-26 18:16:16Z hoffmann
142! unused variables removed
143! drizzle can be used without precipitation
144!
145! 1111 2013-03-08 23:54:10Z raasch
146! ibc_p_b = 2 removed
147!
148! 1103 2013-02-20 02:15:53Z raasch
149! Bugfix: turbulent inflow must not require cyclic fill in restart runs
150!
151! 1092 2013-02-02 11:24:22Z raasch
152! unused variables removed
153!
154! 1069 2012-11-28 16:18:43Z maronga
155! allow usage of topography in combination with cloud physics
156!
157! 1065 2012-11-22 17:42:36Z hoffmann
158! Bugfix: It is not allowed to use cloud_scheme = seifert_beheng without
159!         precipitation in order to save computational resources.
160!
161! 1060 2012-11-21 07:19:51Z raasch
162! additional check for parameter turbulent_inflow
163!
164! 1053 2012-11-13 17:11:03Z hoffmann
165! necessary changes for the new two-moment cloud physics scheme added:
166! - check cloud physics scheme (Kessler or Seifert and Beheng)
167! - plant_canopy is not allowed
168! - currently, only cache loop_optimization is allowed
169! - initial profiles of nr, qr
170! - boundary condition of nr, qr
171! - check output quantities (qr, nr, prr)
172!
173! 1036 2012-10-22 13:43:42Z raasch
174! code put under GPL (PALM 3.9)
175!
176! 1031/1034 2012-10-22 11:32:49Z raasch
177! check of netcdf4 parallel file support
178!
179! 1019 2012-09-28 06:46:45Z raasch
180! non-optimized version of prognostic_equations not allowed any more
181!
182! 1015 2012-09-27 09:23:24Z raasch
183! acc allowed for loop optimization,
184! checks for adjustment of mixing length to the Prandtl mixing length removed
185!
186! 1003 2012-09-14 14:35:53Z raasch
187! checks for cases with unequal subdomain sizes removed
188!
189! 1001 2012-09-13 14:08:46Z raasch
190! all actions concerning leapfrog- and upstream-spline-scheme removed
191!
192! 996 2012-09-07 10:41:47Z raasch
193! little reformatting
194
195! 978 2012-08-09 08:28:32Z fricke
196! setting of bc_lr/ns_dirneu/neudir
197! outflow damping layer removed
198! check for z0h*
199! check for pt_damping_width
200!
201! 964 2012-07-26 09:14:24Z raasch
202! check of old profil-parameters removed
203!
204! 940 2012-07-09 14:31:00Z raasch
205! checks for parameter neutral
206!
207! 924 2012-06-06 07:44:41Z maronga
208! Bugfix: preprocessor directives caused error during compilation
209!
210! 892 2012-05-02 13:51:44Z maronga
211! Bugfix for parameter file check ( excluding __netcdf4 )
212!
213! 866 2012-03-28 06:44:41Z raasch
214! use only 60% of the geostrophic wind as translation speed in case of Galilean
215! transformation and use_ug_for_galilei_tr = .T. in order to mimimize the
216! timestep
217!
218! 861 2012-03-26 14:18:34Z suehring
219! Check for topography and ws-scheme removed.
220! Check for loop_optimization = 'vector' and ws-scheme removed.
221!
222! 845 2012-03-07 10:23:05Z maronga
223! Bugfix: exclude __netcdf4 directive part from namelist file check compilation
224!
225! 828 2012-02-21 12:00:36Z raasch
226! check of collision_kernel extended
227!
228! 825 2012-02-19 03:03:44Z raasch
229! check for collision_kernel and curvature_solution_effects
230!
231! 809 2012-01-30 13:32:58Z maronga
232! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives
233!
234! 807 2012-01-25 11:53:51Z maronga
235! New cpp directive "__check" implemented which is used by check_namelist_files
236!
237! Revision 1.1  1997/08/26 06:29:23  raasch
238! Initial revision
239!
240!
241! Description:
242! ------------
243! Check control parameters and deduce further quantities.
244!------------------------------------------------------------------------------!
245
246    USE arrays_3d
247    USE cloud_parameters
248    USE constants
249    USE control_parameters
250    USE dvrp_variables
251    USE grid_variables
252    USE indices
253    USE land_surface_model_mod
254    USE kinds
255    USE model_1d
256    USE netcdf_control
257    USE particle_attributes
258    USE pegrid
259    USE plant_canopy_model_mod
260    USE profil_parameter
261    USE radiation_model_mod
262    USE spectrum
263    USE statistics
264    USE subsidence_mod
265    USE statistics
266    USE transpose_indices
267
268    IMPLICIT NONE
269
270    CHARACTER (LEN=1)   ::  sq                       !:
271    CHARACTER (LEN=6)   ::  var                      !:
272    CHARACTER (LEN=7)   ::  unit                     !:
273    CHARACTER (LEN=8)   ::  date                     !:
274    CHARACTER (LEN=10)  ::  time                     !:
275    CHARACTER (LEN=40)  ::  coupling_string          !:
276    CHARACTER (LEN=100) ::  action                   !:
277
278    INTEGER(iwp) ::  i                               !:
279    INTEGER(iwp) ::  ilen                            !:
280    INTEGER(iwp) ::  iremote = 0                     !:
281    INTEGER(iwp) ::  j                               !:
282    INTEGER(iwp) ::  k                               !:
283    INTEGER(iwp) ::  kk                              !:
284    INTEGER(iwp) ::  netcdf_data_format_save         !:
285    INTEGER(iwp) ::  position                        !:
286    INTEGER(iwp) ::  prec                            !:
287   
288    LOGICAL     ::  found                            !:
289    LOGICAL     ::  ldum                             !:
290   
291    REAL(wp)    ::  gradient                         !:
292    REAL(wp)    ::  remote = 0.0_wp                  !:
293    REAL(wp)    ::  simulation_time_since_reference  !:
294
295
296    CALL location_message( 'checking parameters', .FALSE. )
297
298!
299!-- Check for overlap combinations, which are not realized yet
300    IF ( transpose_compute_overlap )  THEN
301       IF ( numprocs == 1 )  STOP '+++ transpose-compute-overlap not implemented for single PE runs'
302#if defined( __openacc )
303       STOP '+++ transpose-compute-overlap not implemented for GPU usage'
304#endif
305    ENDIF
306
307!
308!-- Warning, if host is not set
309    IF ( host(1:1) == ' ' )  THEN
310       message_string = '"host" is not set. Please check that environment ' // &
311                        'variable "localhost" & is set before running PALM'
312       CALL message( 'check_parameters', 'PA0001', 0, 0, 0, 6, 0 )
313    ENDIF
314
315!
316!-- Check the coupling mode
317    IF ( coupling_mode /= 'uncoupled'            .AND.  &
318         coupling_mode /= 'atmosphere_to_ocean'  .AND.  &
319         coupling_mode /= 'ocean_to_atmosphere' )  THEN
320       message_string = 'illegal coupling mode: ' // TRIM( coupling_mode )
321       CALL message( 'check_parameters', 'PA0002', 1, 2, 0, 6, 0 )
322    ENDIF
323
324!
325!-- Check dt_coupling, restart_time, dt_restart, end_time, dx, dy, nx and ny
326    IF ( coupling_mode /= 'uncoupled')  THEN
327
328       IF ( dt_coupling == 9999999.9_wp )  THEN
329          message_string = 'dt_coupling is not set but required for coup' // &
330                           'ling mode "' //  TRIM( coupling_mode ) // '"'
331          CALL message( 'check_parameters', 'PA0003', 1, 2, 0, 6, 0 )
332       ENDIF
333
334#if defined( __parallel )
335
336!
337!--    NOTE: coupled runs have not been implemented in the check_namelist_files
338!--    program.
339!--    check_namelist_files will need the following information of the other
340!--    model (atmosphere/ocean).
341!       dt_coupling = remote
342!       dt_max = remote
343!       restart_time = remote
344!       dt_restart= remote
345!       simulation_time_since_reference = remote
346!       dx = remote
347
348
349#if ! defined( __check )
350       IF ( myid == 0 ) THEN
351          CALL MPI_SEND( dt_coupling, 1, MPI_REAL, target_id, 11, comm_inter, &
352                         ierr )
353          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 11, comm_inter, &
354                         status, ierr )
355       ENDIF
356       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
357#endif     
358       IF ( dt_coupling /= remote )  THEN
359          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ), &
360                 '": dt_coupling = ', dt_coupling, '& is not equal to ',       &
361                 'dt_coupling_remote = ', remote
362          CALL message( 'check_parameters', 'PA0004', 1, 2, 0, 6, 0 )
363       ENDIF
364       IF ( dt_coupling <= 0.0_wp )  THEN
365#if ! defined( __check )
366          IF ( myid == 0  ) THEN
367             CALL MPI_SEND( dt_max, 1, MPI_REAL, target_id, 19, comm_inter, ierr )
368             CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 19, comm_inter, &
369                            status, ierr )
370          ENDIF   
371          CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
372#endif         
373          dt_coupling = MAX( dt_max, remote )
374          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ), &
375                 '": dt_coupling <= 0.0 & is not allowed and is reset to ',    &
376                 'MAX(dt_max(A,O)) = ', dt_coupling
377          CALL message( 'check_parameters', 'PA0005', 0, 1, 0, 6, 0 )
378       ENDIF
379#if ! defined( __check )
380       IF ( myid == 0 ) THEN
381          CALL MPI_SEND( restart_time, 1, MPI_REAL, target_id, 12, comm_inter, &
382                         ierr )
383          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 12, comm_inter, &
384                         status, ierr )
385       ENDIF
386       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
387#endif     
388       IF ( restart_time /= remote )  THEN
389          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ), &
390                 '": restart_time = ', restart_time, '& is not equal to ',     &
391                 'restart_time_remote = ', remote
392          CALL message( 'check_parameters', 'PA0006', 1, 2, 0, 6, 0 )
393       ENDIF
394#if ! defined( __check )
395       IF ( myid == 0 ) THEN
396          CALL MPI_SEND( dt_restart, 1, MPI_REAL, target_id, 13, comm_inter, &
397                         ierr )
398          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 13, comm_inter, &
399                         status, ierr )
400       ENDIF   
401       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
402#endif     
403       IF ( dt_restart /= remote )  THEN
404          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ), &
405                 '": dt_restart = ', dt_restart, '& is not equal to ',         &
406                 'dt_restart_remote = ', remote
407          CALL message( 'check_parameters', 'PA0007', 1, 2, 0, 6, 0 )
408       ENDIF
409
410       simulation_time_since_reference = end_time - coupling_start_time
411#if ! defined( __check )
412       IF  ( myid == 0 ) THEN
413          CALL MPI_SEND( simulation_time_since_reference, 1, MPI_REAL, target_id, &
414                         14, comm_inter, ierr )
415          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 14, comm_inter, &
416                         status, ierr )   
417       ENDIF
418       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
419#endif     
420       IF ( simulation_time_since_reference /= remote )  THEN
421          WRITE( message_string, * ) 'coupling mode "', TRIM( coupling_mode ), &
422                 '": simulation_time_since_reference = ',                      &
423                 simulation_time_since_reference, '& is not equal to ',        &
424                 'simulation_time_since_reference_remote = ', remote
425          CALL message( 'check_parameters', 'PA0008', 1, 2, 0, 6, 0 )
426       ENDIF
427
428#if ! defined( __check )
429       IF ( myid == 0 ) THEN
430          CALL MPI_SEND( dx, 1, MPI_REAL, target_id, 15, comm_inter, ierr )
431          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 15, comm_inter, &
432                                                             status, ierr )
433       ENDIF
434       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
435
436#endif
437       IF ( coupling_mode == 'atmosphere_to_ocean') THEN
438
439          IF ( dx < remote ) THEN
440             WRITE( message_string, * ) 'coupling mode "', &
441                   TRIM( coupling_mode ),                  &
442           '": dx in Atmosphere is not equal to or not larger then dx in ocean'
443             CALL message( 'check_parameters', 'PA0009', 1, 2, 0, 6, 0 )
444          ENDIF
445
446          IF ( (nx_a+1)*dx /= (nx_o+1)*remote )  THEN
447             WRITE( message_string, * ) 'coupling mode "', &
448                    TRIM( coupling_mode ), &
449             '": Domain size in x-direction is not equal in ocean and atmosphere'
450             CALL message( 'check_parameters', 'PA0010', 1, 2, 0, 6, 0 )
451          ENDIF
452
453       ENDIF
454
455#if ! defined( __check )
456       IF ( myid == 0) THEN
457          CALL MPI_SEND( dy, 1, MPI_REAL, target_id, 16, comm_inter, ierr )
458          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 16, comm_inter, &
459                         status, ierr )
460       ENDIF
461       CALL MPI_BCAST( remote, 1, MPI_REAL, 0, comm2d, ierr)
462#endif
463       IF ( coupling_mode == 'atmosphere_to_ocean') THEN
464
465          IF ( dy < remote )  THEN
466             WRITE( message_string, * ) 'coupling mode "', &
467                    TRIM( coupling_mode ), &
468                 '": dy in Atmosphere is not equal to or not larger then dy in ocean'
469             CALL message( 'check_parameters', 'PA0011', 1, 2, 0, 6, 0 )
470          ENDIF
471
472          IF ( (ny_a+1)*dy /= (ny_o+1)*remote )  THEN
473             WRITE( message_string, * ) 'coupling mode "', &
474                   TRIM( coupling_mode ), &
475             '": Domain size in y-direction is not equal in ocean and atmosphere'
476             CALL message( 'check_parameters', 'PA0012', 1, 2, 0, 6, 0 )
477          ENDIF
478
479          IF ( MOD(nx_o+1,nx_a+1) /= 0 )  THEN
480             WRITE( message_string, * ) 'coupling mode "', &
481                   TRIM( coupling_mode ), &
482             '": nx+1 in ocean is not divisible without remainder with nx+1 in', & 
483             ' atmosphere'
484             CALL message( 'check_parameters', 'PA0339', 1, 2, 0, 6, 0 )
485          ENDIF
486
487          IF ( MOD(ny_o+1,ny_a+1) /= 0 )  THEN
488             WRITE( message_string, * ) 'coupling mode "', &
489                   TRIM( coupling_mode ), &
490             '": ny+1 in ocean is not divisible without remainder with ny+1 in', & 
491             ' atmosphere'
492             CALL message( 'check_parameters', 'PA0340', 1, 2, 0, 6, 0 )
493          ENDIF
494
495       ENDIF
496#else
497       WRITE( message_string, * ) 'coupling requires PALM to be called with', &
498            ' ''mrun -K parallel'''
499       CALL message( 'check_parameters', 'PA0141', 1, 2, 0, 6, 0 )
500#endif
501    ENDIF
502
503#if defined( __parallel ) && ! defined ( __check )
504!
505!-- Exchange via intercommunicator
506    IF ( coupling_mode == 'atmosphere_to_ocean' .AND. myid == 0 )  THEN
507       CALL MPI_SEND( humidity, 1, MPI_LOGICAL, target_id, 19, comm_inter, &
508                      ierr )
509    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' .AND. myid == 0)  THEN
510       CALL MPI_RECV( humidity_remote, 1, MPI_LOGICAL, target_id, 19, &
511                      comm_inter, status, ierr )
512    ENDIF
513    CALL MPI_BCAST( humidity_remote, 1, MPI_LOGICAL, 0, comm2d, ierr)
514   
515#endif
516
517
518!
519!-- Generate the file header which is used as a header for most of PALM's
520!-- output files
521    CALL DATE_AND_TIME( date, time )
522    run_date = date(7:8)//'-'//date(5:6)//'-'//date(3:4)
523    run_time = time(1:2)//':'//time(3:4)//':'//time(5:6)
524    IF ( coupling_mode == 'uncoupled' )  THEN
525       coupling_string = ''
526    ELSEIF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
527       coupling_string = ' coupled (atmosphere)'
528    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
529       coupling_string = ' coupled (ocean)'
530    ENDIF       
531
532    IF ( ensemble_member_nr /= 0 )  THEN
533       WRITE ( run_description_header,                                         &
534                  '(A,2X,A,2X,A,A,A,I2.2,A,2X,A,I2.2,2X,A,A,2X,A,1X,A)' )      &
535              TRIM( version ), TRIM( revision ), 'run: ',                      &
536              TRIM( run_identifier ), '.', runnr, TRIM( coupling_string ),     &
537              'en-no: ', ensemble_member_nr,'host: ', TRIM( host ),            &
538              run_date, run_time
539    ELSE
540       WRITE ( run_description_header,                                         &
541                  '(A,2X,A,2X,A,A,A,I2.2,A,2X,A,A,2X,A,1X,A)' )                &
542              TRIM( version ), TRIM( revision ), 'run: ',                      &
543              TRIM( run_identifier ), '.', runnr, TRIM( coupling_string ),     &
544              'host: ', TRIM( host ), run_date, run_time
545    ENDIF
546!
547!-- Check the general loop optimization method
548    IF ( loop_optimization == 'default' )  THEN
549       IF ( host(1:3) == 'nec' )  THEN
550          loop_optimization = 'vector'
551       ELSE
552          loop_optimization = 'cache'
553       ENDIF
554    ENDIF
555
556    SELECT CASE ( TRIM( loop_optimization ) )
557
558       CASE ( 'acc', 'cache', 'vector' )
559          CONTINUE
560
561       CASE DEFAULT
562          message_string = 'illegal value given for loop_optimization: "' // &
563                           TRIM( loop_optimization ) // '"'
564          CALL message( 'check_parameters', 'PA0013', 1, 2, 0, 6, 0 )
565
566    END SELECT
567
568!
569!-- Check if vertical grid stretching is used together with particles
570    IF ( dz_stretch_level < 100000.0_wp .AND. particle_advection )  THEN
571       message_string = 'Vertical grid stretching is not allowed together ' // &
572                        'with particle advection.'
573       CALL message( 'check_parameters', 'PA0017', 1, 2, 0, 6, 0 )
574    ENDIF
575
576!
577!--
578    IF ( use_particle_tails )  THEN
579       message_string = 'Particle tails are currently not available due ' //   &
580                        'to the new particle structure.'
581       CALL message( 'check_parameters', 'PA0392', 1, 2, 0, 6, 0 )
582    ENDIF
583
584!
585!-- Check topography setting (check for illegal parameter combinations)
586    IF ( topography /= 'flat' )  THEN
587       action = ' '
588       IF ( scalar_advec /= 'pw-scheme' .AND. scalar_advec /= 'ws-scheme')  THEN
589          WRITE( action, '(A,A)' )  'scalar_advec = ', scalar_advec
590       ENDIF
591       IF ( momentum_advec /= 'pw-scheme' .AND. momentum_advec /= 'ws-scheme' ) &
592       THEN
593          WRITE( action, '(A,A)' )  'momentum_advec = ', momentum_advec
594       ENDIF
595       IF ( psolver == 'sor' )  THEN
596          WRITE( action, '(A,A)' )  'psolver = ', psolver
597       ENDIF
598       IF ( sloping_surface )  THEN
599          WRITE( action, '(A)' )  'sloping surface = .TRUE.'
600       ENDIF
601       IF ( galilei_transformation )  THEN
602          WRITE( action, '(A)' )  'galilei_transformation = .TRUE.'
603       ENDIF
604       IF ( cloud_physics )  THEN
605          WRITE( action, '(A)' )  'cloud_physics = .TRUE.'
606       ENDIF
607       IF ( cloud_droplets )  THEN
608          WRITE( action, '(A)' )  'cloud_droplets = .TRUE.'
609       ENDIF
610       IF ( .NOT. prandtl_layer )  THEN
611          WRITE( action, '(A)' )  'prandtl_layer = .FALSE.'
612       ENDIF
613       IF ( action /= ' ' )  THEN
614          message_string = 'a non-flat topography does not allow ' // &
615                           TRIM( action )
616          CALL message( 'check_parameters', 'PA0014', 1, 2, 0, 6, 0 )
617       ENDIF
618!
619!--    In case of non-flat topography, check whether the convention how to
620!--    define the topography grid has been set correctly, or whether the default
621!--    is applicable. If this is not possible, abort.
622       IF ( TRIM( topography_grid_convention ) == ' ' )  THEN
623          IF ( TRIM( topography ) /= 'single_building' .AND.  &
624               TRIM( topography ) /= 'single_street_canyon' .AND.  &
625               TRIM( topography ) /= 'read_from_file' )  THEN
626!--          The default value is not applicable here, because it is only valid
627!--          for the two standard cases 'single_building' and 'read_from_file'
628!--          defined in init_grid.
629             WRITE( message_string, * )  &
630                  'The value for "topography_grid_convention" ',  &
631                  'is not set. Its default value is & only valid for ',  &
632                  '"topography" = ''single_building'', ',  &
633                  '''single_street_canyon'' & or ''read_from_file''.',  &
634                  ' & Choose ''cell_edge'' or ''cell_center''.'
635             CALL message( 'user_check_parameters', 'PA0239', 1, 2, 0, 6, 0 )
636          ELSE
637!--          The default value is applicable here.
638!--          Set convention according to topography.
639             IF ( TRIM( topography ) == 'single_building' .OR.  &
640                  TRIM( topography ) == 'single_street_canyon' )  THEN
641                topography_grid_convention = 'cell_edge'
642             ELSEIF ( TRIM( topography ) == 'read_from_file' )  THEN
643                topography_grid_convention = 'cell_center'
644             ENDIF
645          ENDIF
646       ELSEIF ( TRIM( topography_grid_convention ) /= 'cell_edge' .AND.  &
647                TRIM( topography_grid_convention ) /= 'cell_center' )  THEN
648          WRITE( message_string, * )  &
649               'The value for "topography_grid_convention" is ', &
650               'not recognized. & Choose ''cell_edge'' or ''cell_center''.'
651          CALL message( 'user_check_parameters', 'PA0240', 1, 2, 0, 6, 0 )
652       ENDIF
653
654    ENDIF
655
656!
657!-- Check ocean setting
658    IF ( ocean )  THEN
659
660       action = ' '
661       IF ( action /= ' ' )  THEN
662          message_string = 'ocean = .T. does not allow ' // TRIM( action )
663          CALL message( 'check_parameters', 'PA0015', 1, 2, 0, 6, 0 )
664       ENDIF
665
666    ELSEIF ( TRIM( coupling_mode ) == 'uncoupled'  .AND.  &
667             TRIM( coupling_char ) == '_O' )  THEN
668
669!
670!--    Check whether an (uncoupled) atmospheric run has been declared as an
671!--    ocean run (this setting is done via mrun-option -y)
672
673       message_string = 'ocean = .F. does not allow coupling_char = "' // &
674                        TRIM( coupling_char ) // '" set by mrun-option "-y"'
675       CALL message( 'check_parameters', 'PA0317', 1, 2, 0, 6, 0 )
676
677    ENDIF
678!
679!-- Check cloud scheme
680    IF ( cloud_scheme == 'seifert_beheng' )  THEN
681       icloud_scheme = 0
682    ELSEIF ( cloud_scheme == 'kessler' )  THEN
683       icloud_scheme = 1
684    ELSE
685       message_string = 'unknown cloud microphysics scheme cloud_scheme ="' // &
686                        TRIM( cloud_scheme ) // '"'
687       CALL message( 'check_parameters', 'PA0357', 1, 2, 0, 6, 0 )
688    ENDIF
689!
690!-- Check whether there are any illegal values
691!-- Pressure solver:
692    IF ( psolver /= 'poisfft'  .AND. &
693         psolver /= 'sor'  .AND.  psolver /= 'multigrid' )  THEN
694       message_string = 'unknown solver for perturbation pressure: psolver' // &
695                        ' = "' // TRIM( psolver ) // '"'
696       CALL message( 'check_parameters', 'PA0016', 1, 2, 0, 6, 0 )
697    ENDIF
698
699    IF ( psolver == 'multigrid' )  THEN
700       IF ( cycle_mg == 'w' )  THEN
701          gamma_mg = 2
702       ELSEIF ( cycle_mg == 'v' )  THEN
703          gamma_mg = 1
704       ELSE
705          message_string = 'unknown multigrid cycle: cycle_mg = "' // &
706                           TRIM( cycle_mg ) // '"'
707          CALL message( 'check_parameters', 'PA0020', 1, 2, 0, 6, 0 )
708       ENDIF
709    ENDIF
710
711    IF ( fft_method /= 'singleton-algorithm'  .AND.  &
712         fft_method /= 'temperton-algorithm'  .AND.  &
713         fft_method /= 'fftw'                 .AND.  &
714         fft_method /= 'system-specific' )  THEN
715       message_string = 'unknown fft-algorithm: fft_method = "' // &
716                        TRIM( fft_method ) // '"'
717       CALL message( 'check_parameters', 'PA0021', 1, 2, 0, 6, 0 )
718    ENDIF
719   
720    IF( momentum_advec == 'ws-scheme' .AND. & 
721        .NOT. call_psolver_at_all_substeps  ) THEN
722        message_string = 'psolver must be called at each RK3 substep when "'//&
723                      TRIM(momentum_advec) // ' "is used for momentum_advec'
724        CALL message( 'check_parameters', 'PA0344', 1, 2, 0, 6, 0 )
725    END IF
726!
727!-- Advection schemes:
728    IF ( momentum_advec /= 'pw-scheme'  .AND.  momentum_advec /= 'ws-scheme' ) &
729    THEN
730       message_string = 'unknown advection scheme: momentum_advec = "' // &
731                        TRIM( momentum_advec ) // '"'
732       CALL message( 'check_parameters', 'PA0022', 1, 2, 0, 6, 0 )
733    ENDIF
734    IF ( ( momentum_advec == 'ws-scheme' .OR.  scalar_advec == 'ws-scheme' )   &
735           .AND. ( timestep_scheme == 'euler' .OR.                             &
736                   timestep_scheme == 'runge-kutta-2' ) )                      &
737    THEN
738       message_string = 'momentum_advec or scalar_advec = "' &
739         // TRIM( momentum_advec ) // '" is not allowed with timestep_scheme = "' // &
740         TRIM( timestep_scheme ) // '"'
741       CALL message( 'check_parameters', 'PA0023', 1, 2, 0, 6, 0 )
742    ENDIF
743    IF ( scalar_advec /= 'pw-scheme'  .AND.  scalar_advec /= 'ws-scheme' .AND. &
744         scalar_advec /= 'bc-scheme' )                                         &
745    THEN
746       message_string = 'unknown advection scheme: scalar_advec = "' // &
747                        TRIM( scalar_advec ) // '"'
748       CALL message( 'check_parameters', 'PA0024', 1, 2, 0, 6, 0 )
749    ENDIF
750    IF ( scalar_advec == 'bc-scheme'  .AND.  loop_optimization == 'cache' )    &
751    THEN
752       message_string = 'advection_scheme scalar_advec = "' &
753         // TRIM( scalar_advec ) // '" not implemented for & loop_optimization = "' // &
754         TRIM( loop_optimization ) // '"'
755       CALL message( 'check_parameters', 'PA0026', 1, 2, 0, 6, 0 )
756    ENDIF
757
758    IF ( use_sgs_for_particles  .AND.  .NOT. use_upstream_for_tke .AND.        &
759         scalar_advec /= 'ws-scheme' )  THEN
760       use_upstream_for_tke = .TRUE.
761       message_string = 'use_upstream_for_tke set .TRUE. because ' //          &
762                        'use_sgs_for_particles = .TRUE. '          //          &
763                        'and scalar_advec /= ws-scheme'
764       CALL message( 'check_parameters', 'PA0025', 0, 1, 0, 6, 0 )
765    ENDIF
766
767    IF ( use_sgs_for_particles  .AND.  curvature_solution_effects )  THEN
768       message_string = 'use_sgs_for_particles = .TRUE. not allowed with ' //  &
769                        'curvature_solution_effects = .TRUE.'
770       CALL message( 'check_parameters', 'PA0349', 1, 2, 0, 6, 0 )
771    ENDIF
772
773!
774!-- Set LOGICAL switches to enhance performance
775    IF ( momentum_advec == 'ws-scheme' )    ws_scheme_mom = .TRUE.
776    IF ( scalar_advec   == 'ws-scheme'   )  ws_scheme_sca = .TRUE.
777
778!
779!-- Timestep schemes:
780    SELECT CASE ( TRIM( timestep_scheme ) )
781
782       CASE ( 'euler' )
783          intermediate_timestep_count_max = 1
784
785       CASE ( 'runge-kutta-2' )
786          intermediate_timestep_count_max = 2
787
788       CASE ( 'runge-kutta-3' )
789          intermediate_timestep_count_max = 3
790
791       CASE DEFAULT
792          message_string = 'unknown timestep scheme: timestep_scheme = "' //   &
793                           TRIM( timestep_scheme ) // '"'
794          CALL message( 'check_parameters', 'PA0027', 1, 2, 0, 6, 0 )
795
796    END SELECT
797
798    IF ( (momentum_advec /= 'pw-scheme' .AND. momentum_advec /= 'ws-scheme')   &
799         .AND. timestep_scheme(1:5) == 'runge' ) THEN
800       message_string = 'momentum advection scheme "' // &
801                        TRIM( momentum_advec ) // '" & does not work with ' // &
802                        'timestep_scheme "' // TRIM( timestep_scheme ) // '"'
803       CALL message( 'check_parameters', 'PA0029', 1, 2, 0, 6, 0 )
804    ENDIF
805
806!
807!-- Collision kernels:
808    SELECT CASE ( TRIM( collision_kernel ) )
809
810       CASE ( 'hall', 'hall_fast' )
811          hall_kernel = .TRUE.
812
813       CASE ( 'palm' )
814          palm_kernel = .TRUE.
815
816       CASE ( 'wang', 'wang_fast' )
817          wang_kernel = .TRUE.
818
819       CASE ( 'none' )
820
821
822       CASE DEFAULT
823          message_string = 'unknown collision kernel: collision_kernel = "' // &
824                           TRIM( collision_kernel ) // '"'
825          CALL message( 'check_parameters', 'PA0350', 1, 2, 0, 6, 0 )
826
827    END SELECT
828    IF ( collision_kernel(6:9) == 'fast' )  use_kernel_tables = .TRUE.
829
830    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.  &
831         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
832!
833!--    No restart run: several initialising actions are possible
834       action = initializing_actions
835       DO WHILE ( TRIM( action ) /= '' )
836          position = INDEX( action, ' ' )
837          SELECT CASE ( action(1:position-1) )
838
839             CASE ( 'set_constant_profiles', 'set_1d-model_profiles', &
840                    'by_user', 'initialize_vortex',     'initialize_ptanom' )
841                action = action(position+1:)
842
843             CASE DEFAULT
844                message_string = 'initializing_action = "' // &
845                                 TRIM( action ) // '" unkown or not allowed'
846                CALL message( 'check_parameters', 'PA0030', 1, 2, 0, 6, 0 )
847
848          END SELECT
849       ENDDO
850    ENDIF
851
852    IF ( TRIM( initializing_actions ) == 'initialize_vortex' .AND. &
853         conserve_volume_flow ) THEN
854         message_string = 'initializing_actions = "initialize_vortex"' // &
855                        ' ist not allowed with conserve_volume_flow = .T.'
856       CALL message( 'check_parameters', 'PA0343', 1, 2, 0, 6, 0 )
857    ENDIF       
858
859
860    IF ( INDEX( initializing_actions, 'set_constant_profiles' ) /= 0  .AND. &
861         INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
862       message_string = 'initializing_actions = "set_constant_profiles"' // &
863                        ' and "set_1d-model_profiles" are not allowed ' //  &
864                        'simultaneously'
865       CALL message( 'check_parameters', 'PA0031', 1, 2, 0, 6, 0 )
866    ENDIF
867
868    IF ( INDEX( initializing_actions, 'set_constant_profiles' ) /= 0  .AND. &
869         INDEX( initializing_actions, 'by_user' ) /= 0 )  THEN
870       message_string = 'initializing_actions = "set_constant_profiles"' // &
871                        ' and "by_user" are not allowed simultaneously'
872       CALL message( 'check_parameters', 'PA0032', 1, 2, 0, 6, 0 )
873    ENDIF
874
875    IF ( INDEX( initializing_actions, 'by_user' ) /= 0  .AND. &
876         INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
877       message_string = 'initializing_actions = "by_user" and ' // &
878                        '"set_1d-model_profiles" are not allowed simultaneously'
879       CALL message( 'check_parameters', 'PA0033', 1, 2, 0, 6, 0 )
880    ENDIF
881
882    IF ( cloud_physics  .AND.  .NOT. humidity )  THEN
883       WRITE( message_string, * ) 'cloud_physics = ', cloud_physics, ' is ', &
884              'not allowed with humidity = ', humidity
885       CALL message( 'check_parameters', 'PA0034', 1, 2, 0, 6, 0 )
886    ENDIF
887
888    IF ( precipitation  .AND.  .NOT.  cloud_physics )  THEN
889       WRITE( message_string, * ) 'precipitation = ', precipitation, ' is ', &
890              'not allowed with cloud_physics = ', cloud_physics
891       CALL message( 'check_parameters', 'PA0035', 1, 2, 0, 6, 0 )
892    ENDIF
893
894    IF ( humidity  .AND.  sloping_surface )  THEN
895       message_string = 'humidity = .TRUE. and sloping_surface = .TRUE. ' // &
896                        'are not allowed simultaneously'
897       CALL message( 'check_parameters', 'PA0036', 1, 2, 0, 6, 0 )
898    ENDIF
899
900    IF ( passive_scalar  .AND.  humidity )  THEN
901       message_string = 'humidity = .TRUE. and passive_scalar = .TRUE. ' // &
902                        'is not allowed simultaneously'
903       CALL message( 'check_parameters', 'PA0038', 1, 2, 0, 6, 0 )
904    ENDIF
905
906    IF ( plant_canopy )  THEN
907   
908       IF ( canopy_drag_coeff == 0.0_wp )  THEN
909          message_string = 'plant_canopy = .TRUE. requires a non-zero drag '// &
910                           'coefficient & given value is canopy_drag_coeff = 0.0'
911          CALL message( 'check_parameters', 'PA0041', 1, 2, 0, 6, 0 )
912       ENDIF
913   
914       IF ( ( alpha_lad /= 9999999.9_wp  .AND.  beta_lad == 9999999.9_wp )  .OR.&
915              beta_lad /= 9999999.9_wp   .AND.  alpha_lad == 9999999.9_wp )  THEN
916          message_string = 'using the beta function for the construction ' //  &
917                           'of the leaf area density profile requires '    //  &
918                           'both alpha_lad and beta_lad to be /= 9999999.9'
919          CALL message( 'check_parameters', 'PA0118', 1, 2, 0, 6, 0 )
920       ENDIF
921   
922       IF ( calc_beta_lad_profile  .AND.  lai_beta == 0.0_wp )  THEN
923          message_string = 'using the beta function for the construction ' //  &
924                           'of the leaf area density profile requires '    //  &
925                           'a non-zero lai_beta, but given value is '      //  &
926                           'lai_beta = 0.0'
927          CALL message( 'check_parameters', 'PA0119', 1, 2, 0, 6, 0 )
928       ENDIF
929
930       IF ( calc_beta_lad_profile  .AND.  lad_surface /= 0.0_wp )  THEN
931          message_string = 'simultaneous setting of alpha_lad /= 9999999.9' // &
932                           'and lad_surface /= 0.0 is not possible, '       // &
933                           'use either vertical gradients or the beta '     // &
934                           'function for the construction of the leaf area '// &
935                           'density profile'
936          CALL message( 'check_parameters', 'PA0120', 1, 2, 0, 6, 0 )
937       ENDIF
938
939       IF ( cloud_physics  .AND.  icloud_scheme == 0 )  THEN
940          message_string = 'plant_canopy = .TRUE. requires cloud_scheme /=' // &
941                           ' seifert_beheng'
942          CALL message( 'check_parameters', 'PA0360', 1, 2, 0, 6, 0 )
943       ENDIF
944
945    ENDIF
946
947
948    IF ( land_surface )  THEN
949 
950       IF ( ANY(soil_temperature == 9999999.9_wp) )  THEN
951             message_string = '&lsm_par list requires setting'//               &
952                              'of soil_temperature(0:3)'//                     &
953                              '/= 9999999.9'
954             CALL message( 'check_parameters', 'PA0398', 1, 2, 0, 6, 0 )
955       ENDIF   
956
957!      Dirichlet boundary conditions are allowed at the moment for testing
958!      purposes
959!        IF ( bc_pt_b == 'dirichlet' .OR. bc_q_b == 'dirichlet' )  THEN
960!           message_string = 'lsm requires setting of'//                         &
961!                            'bc_pt_b = "neumann" and '//                        &
962!                            'bc_q_b  = "neumann"'
963!           CALL message( 'check_parameters', 'PA0399', 1, 2, 0, 6, 0 )
964!        ENDIF
965
966       IF ( .NOT. prandtl_layer )  THEN
967          message_string = 'lsm requires '//                                   &
968                           'prandtl_layer = .T.'
969          CALL message( 'check_parameters', 'PA0400', 1, 2, 0, 6, 0 )
970       ENDIF
971
972       IF ( veg_type == 0 )  THEN
973          IF ( SUM(root_fraction) /= 1.0_wp)  THEN
974             message_string = 'veg_type = 0 (user_defined)'//                  &
975                              'requires setting of root_fraction(0:3)'//       &
976                              '/= 9999999.9 and SUM(root_fraction) = 1'
977             CALL message( 'check_parameters', 'PA0401', 1, 2, 0, 6, 0 )
978          ENDIF
979       ENDIF
980
981       IF ( .NOT. radiation )  THEN
982          message_string = 'lsm requires '//                                   &
983                           'radiation = .T.'
984          CALL message( 'check_parameters', 'PA0402', 1, 2, 0, 6, 0 )
985       ENDIF
986
987
988    END IF
989
990
991    IF ( .NOT. ( loop_optimization == 'cache'  .OR.                            &
992                 loop_optimization == 'vector' )                               &
993         .AND.  cloud_physics  .AND.  icloud_scheme == 0 )  THEN
994       message_string = 'cloud_scheme = seifert_beheng requires ' // &
995                        'loop_optimization = "cache" or "vector"'
996       CALL message( 'check_parameters', 'PA0362', 1, 2, 0, 6, 0 )
997    ENDIF 
998
999!
1000!-- In case of no model continuation run, check initialising parameters and
1001!-- deduce further quantities
1002    IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
1003
1004!
1005!--    Initial profiles for 1D and 3D model, respectively (u,v further below)
1006       pt_init = pt_surface
1007       IF ( humidity )  THEN
1008          q_init  = q_surface
1009       ENDIF
1010       IF ( ocean )           sa_init = sa_surface
1011       IF ( passive_scalar )  q_init  = s_surface
1012
1013!
1014!--
1015!--    If required, compute initial profile of the geostrophic wind
1016!--    (component ug)
1017       i = 1
1018       gradient = 0.0_wp
1019
1020       IF ( .NOT. ocean )  THEN
1021
1022          ug_vertical_gradient_level_ind(1) = 0
1023          ug(0) = ug_surface
1024          DO  k = 1, nzt+1
1025             IF ( i < 11 ) THEN
1026                IF ( ug_vertical_gradient_level(i) < zu(k)  .AND. &
1027                     ug_vertical_gradient_level(i) >= 0.0_wp )  THEN
1028                   gradient = ug_vertical_gradient(i) / 100.0_wp
1029                   ug_vertical_gradient_level_ind(i) = k - 1
1030                   i = i + 1
1031                ENDIF
1032             ENDIF       
1033             IF ( gradient /= 0.0_wp )  THEN
1034                IF ( k /= 1 )  THEN
1035                   ug(k) = ug(k-1) + dzu(k) * gradient
1036                ELSE
1037                   ug(k) = ug_surface + dzu(k) * gradient
1038                ENDIF
1039             ELSE
1040                ug(k) = ug(k-1)
1041             ENDIF
1042          ENDDO
1043
1044       ELSE
1045
1046          ug_vertical_gradient_level_ind(1) = nzt+1
1047          ug(nzt+1) = ug_surface
1048          DO  k = nzt, nzb, -1
1049             IF ( i < 11 ) THEN
1050                IF ( ug_vertical_gradient_level(i) > zu(k)  .AND. &
1051                     ug_vertical_gradient_level(i) <= 0.0_wp )  THEN
1052                   gradient = ug_vertical_gradient(i) / 100.0_wp
1053                   ug_vertical_gradient_level_ind(i) = k + 1
1054                   i = i + 1
1055                ENDIF
1056             ENDIF
1057             IF ( gradient /= 0.0_wp )  THEN
1058                IF ( k /= nzt )  THEN
1059                   ug(k) = ug(k+1) - dzu(k+1) * gradient
1060                ELSE
1061                   ug(k)   = ug_surface - 0.5_wp * dzu(k+1) * gradient
1062                   ug(k+1) = ug_surface + 0.5_wp * dzu(k+1) * gradient
1063                ENDIF
1064             ELSE
1065                ug(k) = ug(k+1)
1066             ENDIF
1067          ENDDO
1068
1069       ENDIF
1070
1071!
1072!--    In case of no given gradients for ug, choose a zero gradient
1073       IF ( ug_vertical_gradient_level(1) == -9999999.9_wp )  THEN
1074          ug_vertical_gradient_level(1) = 0.0_wp
1075       ENDIF 
1076
1077!
1078!--
1079!--    If required, compute initial profile of the geostrophic wind
1080!--    (component vg)
1081       i = 1
1082       gradient = 0.0_wp
1083
1084       IF ( .NOT. ocean )  THEN
1085
1086          vg_vertical_gradient_level_ind(1) = 0
1087          vg(0) = vg_surface
1088          DO  k = 1, nzt+1
1089             IF ( i < 11 ) THEN
1090                IF ( vg_vertical_gradient_level(i) < zu(k)  .AND. &
1091                     vg_vertical_gradient_level(i) >= 0.0_wp )  THEN
1092                   gradient = vg_vertical_gradient(i) / 100.0_wp
1093                   vg_vertical_gradient_level_ind(i) = k - 1
1094                   i = i + 1
1095                ENDIF
1096             ENDIF
1097             IF ( gradient /= 0.0_wp )  THEN
1098                IF ( k /= 1 )  THEN
1099                   vg(k) = vg(k-1) + dzu(k) * gradient
1100                ELSE
1101                   vg(k) = vg_surface + dzu(k) * gradient
1102                ENDIF
1103             ELSE
1104                vg(k) = vg(k-1)
1105             ENDIF
1106          ENDDO
1107
1108       ELSE
1109
1110          vg_vertical_gradient_level_ind(1) = nzt+1
1111          vg(nzt+1) = vg_surface
1112          DO  k = nzt, nzb, -1
1113             IF ( i < 11 ) THEN
1114                IF ( vg_vertical_gradient_level(i) > zu(k)  .AND. &
1115                     vg_vertical_gradient_level(i) <= 0.0_wp )  THEN
1116                   gradient = vg_vertical_gradient(i) / 100.0_wp
1117                   vg_vertical_gradient_level_ind(i) = k + 1
1118                   i = i + 1
1119                ENDIF
1120             ENDIF
1121             IF ( gradient /= 0.0_wp )  THEN
1122                IF ( k /= nzt )  THEN
1123                   vg(k) = vg(k+1) - dzu(k+1) * gradient
1124                ELSE
1125                   vg(k)   = vg_surface - 0.5_wp * dzu(k+1) * gradient
1126                   vg(k+1) = vg_surface + 0.5_wp * dzu(k+1) * gradient
1127                ENDIF
1128             ELSE
1129                vg(k) = vg(k+1)
1130             ENDIF
1131          ENDDO
1132
1133       ENDIF
1134
1135!
1136!--    In case of no given gradients for vg, choose a zero gradient
1137       IF ( vg_vertical_gradient_level(1) == -9999999.9_wp )  THEN
1138          vg_vertical_gradient_level(1) = 0.0_wp
1139       ENDIF
1140
1141!
1142!--    Let the initial wind profiles be the calculated ug/vg profiles or
1143!--    interpolate them from wind profile data (if given)
1144       IF ( u_profile(1) == 9999999.9_wp  .AND.  v_profile(1) == 9999999.9_wp )  THEN
1145
1146          u_init = ug
1147          v_init = vg
1148
1149       ELSEIF ( u_profile(1) == 0.0_wp  .AND.  v_profile(1) == 0.0_wp )  THEN
1150
1151          IF ( uv_heights(1) /= 0.0_wp )  THEN
1152             message_string = 'uv_heights(1) must be 0.0'
1153             CALL message( 'check_parameters', 'PA0345', 1, 2, 0, 6, 0 )
1154          ENDIF
1155
1156          use_prescribed_profile_data = .TRUE.
1157
1158          kk = 1
1159          u_init(0) = 0.0_wp
1160          v_init(0) = 0.0_wp
1161
1162          DO  k = 1, nz+1
1163
1164             IF ( kk < 100 )  THEN
1165                DO WHILE ( uv_heights(kk+1) <= zu(k) )
1166                   kk = kk + 1
1167                   IF ( kk == 100 )  EXIT
1168                ENDDO
1169             ENDIF
1170
1171             IF ( kk < 100 .AND. uv_heights(kk+1) /= 9999999.9_wp )  THEN
1172                u_init(k) = u_profile(kk) + ( zu(k) - uv_heights(kk) ) /       &
1173                                       ( uv_heights(kk+1) - uv_heights(kk) ) * &
1174                                       ( u_profile(kk+1) - u_profile(kk) )
1175                v_init(k) = v_profile(kk) + ( zu(k) - uv_heights(kk) ) /       &
1176                                       ( uv_heights(kk+1) - uv_heights(kk) ) * &
1177                                       ( v_profile(kk+1) - v_profile(kk) )
1178             ELSE
1179                u_init(k) = u_profile(kk)
1180                v_init(k) = v_profile(kk)
1181             ENDIF
1182
1183          ENDDO
1184
1185       ELSE
1186
1187          message_string = 'u_profile(1) and v_profile(1) must be 0.0'
1188          CALL message( 'check_parameters', 'PA0346', 1, 2, 0, 6, 0 )
1189
1190       ENDIF
1191
1192!
1193!--    Compute initial temperature profile using the given temperature gradients
1194       IF ( .NOT. neutral )  THEN
1195
1196          i = 1
1197          gradient = 0.0_wp
1198
1199          IF ( .NOT. ocean )  THEN
1200
1201             pt_vertical_gradient_level_ind(1) = 0
1202             DO  k = 1, nzt+1
1203                IF ( i < 11 ) THEN
1204                   IF ( pt_vertical_gradient_level(i) < zu(k)  .AND. &
1205                        pt_vertical_gradient_level(i) >= 0.0_wp )  THEN
1206                      gradient = pt_vertical_gradient(i) / 100.0_wp
1207                      pt_vertical_gradient_level_ind(i) = k - 1
1208                      i = i + 1
1209                   ENDIF
1210                ENDIF
1211                IF ( gradient /= 0.0_wp )  THEN
1212                   IF ( k /= 1 )  THEN
1213                      pt_init(k) = pt_init(k-1) + dzu(k) * gradient
1214                   ELSE
1215                      pt_init(k) = pt_surface   + dzu(k) * gradient
1216                   ENDIF
1217                ELSE
1218                   pt_init(k) = pt_init(k-1)
1219                ENDIF
1220             ENDDO
1221
1222          ELSE
1223
1224             pt_vertical_gradient_level_ind(1) = nzt+1
1225             DO  k = nzt, 0, -1
1226                IF ( i < 11 ) THEN
1227                   IF ( pt_vertical_gradient_level(i) > zu(k)  .AND. &
1228                        pt_vertical_gradient_level(i) <= 0.0_wp )  THEN
1229                      gradient = pt_vertical_gradient(i) / 100.0_wp
1230                      pt_vertical_gradient_level_ind(i) = k + 1
1231                      i = i + 1
1232                   ENDIF
1233                ENDIF
1234                IF ( gradient /= 0.0_wp )  THEN
1235                   IF ( k /= nzt )  THEN
1236                      pt_init(k) = pt_init(k+1) - dzu(k+1) * gradient
1237                   ELSE
1238                      pt_init(k)   = pt_surface - 0.5_wp * dzu(k+1) * gradient
1239                      pt_init(k+1) = pt_surface + 0.5_wp * dzu(k+1) * gradient
1240                   ENDIF
1241                ELSE
1242                   pt_init(k) = pt_init(k+1)
1243                ENDIF
1244             ENDDO
1245
1246          ENDIF
1247
1248       ENDIF
1249
1250!
1251!--    In case of no given temperature gradients, choose gradient of neutral
1252!--    stratification
1253       IF ( pt_vertical_gradient_level(1) == -9999999.9_wp )  THEN
1254          pt_vertical_gradient_level(1) = 0.0_wp
1255       ENDIF
1256
1257!
1258!--    Store temperature gradient at the top boundary for possible Neumann
1259!--    boundary condition
1260       bc_pt_t_val = ( pt_init(nzt+1) - pt_init(nzt) ) / dzu(nzt+1)
1261
1262!
1263!--    If required, compute initial humidity or scalar profile using the given
1264!--    humidity/scalar gradient. In case of scalar transport, initially store
1265!--    values of the scalar parameters on humidity parameters
1266       IF ( passive_scalar )  THEN
1267          bc_q_b                    = bc_s_b
1268          bc_q_t                    = bc_s_t
1269          q_surface                 = s_surface
1270          q_surface_initial_change  = s_surface_initial_change
1271          q_vertical_gradient       = s_vertical_gradient
1272          q_vertical_gradient_level = s_vertical_gradient_level
1273          surface_waterflux         = surface_scalarflux
1274          wall_humidityflux         = wall_scalarflux
1275       ENDIF
1276
1277       IF ( humidity  .OR.  passive_scalar )  THEN
1278
1279          i = 1
1280          gradient = 0.0_wp
1281          q_vertical_gradient_level_ind(1) = 0
1282          DO  k = 1, nzt+1
1283             IF ( i < 11 ) THEN
1284                IF ( q_vertical_gradient_level(i) < zu(k)  .AND. &
1285                     q_vertical_gradient_level(i) >= 0.0_wp )  THEN
1286                   gradient = q_vertical_gradient(i) / 100.0_wp
1287                   q_vertical_gradient_level_ind(i) = k - 1
1288                   i = i + 1
1289                ENDIF
1290             ENDIF
1291             IF ( gradient /= 0.0_wp )  THEN
1292                IF ( k /= 1 )  THEN
1293                   q_init(k) = q_init(k-1) + dzu(k) * gradient
1294                ELSE
1295                   q_init(k) = q_init(k-1) + dzu(k) * gradient
1296                ENDIF
1297             ELSE
1298                q_init(k) = q_init(k-1)
1299             ENDIF
1300!
1301!--          Avoid negative humidities
1302             IF ( q_init(k) < 0.0_wp )  THEN
1303                q_init(k) = 0.0_wp
1304             ENDIF
1305          ENDDO
1306
1307!
1308!--       In case of no given humidity gradients, choose zero gradient
1309!--       conditions
1310          IF ( q_vertical_gradient_level(1) == -1.0_wp )  THEN
1311             q_vertical_gradient_level(1) = 0.0_wp
1312          ENDIF
1313!
1314!--       Store humidity, rain water content and rain drop concentration
1315!--       gradient at the top boundary for possile Neumann boundary condition
1316          bc_q_t_val  = ( q_init(nzt+1) - q_init(nzt) ) / dzu(nzt+1)
1317       ENDIF
1318
1319!
1320!--    If required, compute initial salinity profile using the given salinity
1321!--    gradients
1322       IF ( ocean )  THEN
1323
1324          i = 1
1325          gradient = 0.0_wp
1326
1327          sa_vertical_gradient_level_ind(1) = nzt+1
1328          DO  k = nzt, 0, -1
1329             IF ( i < 11 ) THEN
1330                IF ( sa_vertical_gradient_level(i) > zu(k)  .AND. &
1331                     sa_vertical_gradient_level(i) <= 0.0_wp )  THEN
1332                   gradient = sa_vertical_gradient(i) / 100.0_wp
1333                   sa_vertical_gradient_level_ind(i) = k + 1
1334                   i = i + 1
1335                ENDIF
1336             ENDIF
1337             IF ( gradient /= 0.0_wp )  THEN
1338                IF ( k /= nzt )  THEN
1339                   sa_init(k) = sa_init(k+1) - dzu(k+1) * gradient
1340                ELSE
1341                   sa_init(k)   = sa_surface - 0.5_wp * dzu(k+1) * gradient
1342                   sa_init(k+1) = sa_surface + 0.5_wp * dzu(k+1) * gradient
1343                ENDIF
1344             ELSE
1345                sa_init(k) = sa_init(k+1)
1346             ENDIF
1347          ENDDO
1348
1349       ENDIF
1350
1351         
1352    ENDIF
1353
1354!
1355!-- Check if the control parameter use_subsidence_tendencies is used correctly
1356    IF ( use_subsidence_tendencies  .AND.  .NOT. large_scale_subsidence )  THEN
1357       message_string = 'The usage of use_subsidence_tendencies ' // &
1358                            'requires large_scale_subsidence = .T..'
1359       CALL message( 'check_parameters', 'PA0396', 1, 2, 0, 6, 0 )
1360    ELSEIF ( use_subsidence_tendencies  .AND.  .NOT. large_scale_forcing )  THEN
1361       message_string = 'The usage of use_subsidence_tendencies ' // &
1362                            'requires large_scale_forcing = .T..'
1363       CALL message( 'check_parameters', 'PA0397', 1, 2, 0, 6, 0 )
1364    ENDIF
1365
1366!
1367!-- Initialize large scale subsidence if required
1368    If ( large_scale_subsidence )  THEN
1369       IF ( subs_vertical_gradient_level(1) /= -9999999.9_wp .AND. &
1370                                     .NOT. large_scale_forcing )  THEN
1371          CALL init_w_subsidence
1372       ENDIF
1373!
1374!--    In case large_scale_forcing is used, profiles for subsidence velocity
1375!--    are read in from file LSF_DATA
1376
1377       IF ( subs_vertical_gradient_level(1) == -9999999.9_wp .AND. &
1378                                     .NOT. large_scale_forcing )  THEN
1379          message_string = 'There is no default large scale vertical ' // &
1380                           'velocity profile set. Specify the subsidence ' // &
1381                           'velocity profile via subs_vertical_gradient and ' // &
1382                           'subs_vertical_gradient_level.'
1383          CALL message( 'check_parameters', 'PA0380', 1, 2, 0, 6, 0 )
1384       ENDIF
1385    ELSE
1386        IF ( subs_vertical_gradient_level(1) /= -9999999.9_wp )  THEN
1387           message_string = 'Enable usage of large scale subsidence by ' // &
1388                            'setting large_scale_subsidence = .T..'
1389          CALL message( 'check_parameters', 'PA0381', 1, 2, 0, 6, 0 )
1390        ENDIF
1391    ENDIF   
1392
1393!
1394!-- Compute Coriolis parameter
1395    f  = 2.0_wp * omega * SIN( phi / 180.0_wp * pi )
1396    fs = 2.0_wp * omega * COS( phi / 180.0_wp * pi )
1397
1398!
1399!-- Check and set buoyancy related parameters and switches
1400    IF ( reference_state == 'horizontal_average' )  THEN
1401       CONTINUE
1402    ELSEIF ( reference_state == 'initial_profile' )  THEN
1403       use_initial_profile_as_reference = .TRUE.
1404    ELSEIF ( reference_state == 'single_value' )  THEN
1405       use_single_reference_value = .TRUE.
1406       IF ( pt_reference == 9999999.9_wp )  pt_reference = pt_surface
1407       vpt_reference = pt_reference * ( 1.0_wp + 0.61_wp * q_surface )
1408    ELSE
1409       message_string = 'illegal value for reference_state: "' // &
1410                        TRIM( reference_state ) // '"'
1411       CALL message( 'check_parameters', 'PA0056', 1, 2, 0, 6, 0 )
1412    ENDIF
1413
1414!
1415!-- Ocean runs always use reference values in the buoyancy term
1416    IF ( ocean )  THEN
1417       reference_state = 'single_value'
1418       use_single_reference_value = .TRUE.
1419    ENDIF
1420
1421!
1422!-- Sign of buoyancy/stability terms
1423    IF ( ocean )  atmos_ocean_sign = -1.0_wp
1424
1425!
1426!-- Ocean version must use flux boundary conditions at the top
1427    IF ( ocean .AND. .NOT. use_top_fluxes )  THEN
1428       message_string = 'use_top_fluxes must be .TRUE. in ocean mode'
1429       CALL message( 'check_parameters', 'PA0042', 1, 2, 0, 6, 0 )
1430    ENDIF
1431
1432!
1433!-- In case of a given slope, compute the relevant quantities
1434    IF ( alpha_surface /= 0.0_wp )  THEN
1435       IF ( ABS( alpha_surface ) > 90.0_wp )  THEN
1436          WRITE( message_string, * ) 'ABS( alpha_surface = ', alpha_surface, &
1437                                     ' ) must be < 90.0'
1438          CALL message( 'check_parameters', 'PA0043', 1, 2, 0, 6, 0 )
1439       ENDIF
1440       sloping_surface = .TRUE.
1441       cos_alpha_surface = COS( alpha_surface / 180.0_wp * pi )
1442       sin_alpha_surface = SIN( alpha_surface / 180.0_wp * pi )
1443    ENDIF
1444
1445!
1446!-- Check time step and cfl_factor
1447    IF ( dt /= -1.0_wp )  THEN
1448       IF ( dt <= 0.0_wp  .AND.  dt /= -1.0_wp )  THEN
1449          WRITE( message_string, * ) 'dt = ', dt , ' <= 0.0'
1450          CALL message( 'check_parameters', 'PA0044', 1, 2, 0, 6, 0 )
1451       ENDIF
1452       dt_3d = dt
1453       dt_fixed = .TRUE.
1454    ENDIF
1455
1456    IF ( cfl_factor <= 0.0_wp  .OR.  cfl_factor > 1.0_wp )  THEN
1457       IF ( cfl_factor == -1.0_wp )  THEN
1458          IF ( timestep_scheme == 'runge-kutta-2' )  THEN
1459             cfl_factor = 0.8_wp
1460          ELSEIF ( timestep_scheme == 'runge-kutta-3' )  THEN
1461             cfl_factor = 0.9_wp
1462          ELSE
1463             cfl_factor = 0.9_wp
1464          ENDIF
1465       ELSE
1466          WRITE( message_string, * ) 'cfl_factor = ', cfl_factor, &
1467                 ' out of range & 0.0 < cfl_factor <= 1.0 is required'
1468          CALL message( 'check_parameters', 'PA0045', 1, 2, 0, 6, 0 )
1469       ENDIF
1470    ENDIF
1471
1472!
1473!-- Store simulated time at begin
1474    simulated_time_at_begin = simulated_time
1475
1476!
1477!-- Store reference time for coupled runs and change the coupling flag,
1478!-- if ...
1479    IF ( simulated_time == 0.0_wp )  THEN
1480       IF ( coupling_start_time == 0.0_wp )  THEN
1481          time_since_reference_point = 0.0_wp
1482       ELSEIF ( time_since_reference_point < 0.0_wp )  THEN
1483          run_coupled = .FALSE.
1484       ENDIF
1485    ENDIF
1486
1487!
1488!-- Set wind speed in the Galilei-transformed system
1489    IF ( galilei_transformation )  THEN
1490       IF ( use_ug_for_galilei_tr .AND.                     &
1491            ug_vertical_gradient_level(1) == 0.0_wp  .AND.  &
1492            ug_vertical_gradient(1) == 0.0_wp  .AND.        & 
1493            vg_vertical_gradient_level(1) == 0.0_wp  .AND.  &
1494            vg_vertical_gradient(1) == 0.0_wp )  THEN
1495          u_gtrans = ug_surface * 0.6_wp
1496          v_gtrans = vg_surface * 0.6_wp
1497       ELSEIF ( use_ug_for_galilei_tr  .AND.                     &
1498                ( ug_vertical_gradient_level(1) /= 0.0_wp  .OR.  &
1499                ug_vertical_gradient(1) /= 0.0_wp ) )  THEN
1500          message_string = 'baroclinity (ug) not allowed simultaneously' // &
1501                           ' with galilei transformation'
1502          CALL message( 'check_parameters', 'PA0046', 1, 2, 0, 6, 0 )
1503       ELSEIF ( use_ug_for_galilei_tr  .AND.                     &
1504                ( vg_vertical_gradient_level(1) /= 0.0_wp  .OR.  &
1505                vg_vertical_gradient(1) /= 0.0_wp ) )  THEN
1506          message_string = 'baroclinity (vg) not allowed simultaneously' // &
1507                           ' with galilei transformation'
1508          CALL message( 'check_parameters', 'PA0047', 1, 2, 0, 6, 0 )
1509       ELSE
1510          message_string = 'variable translation speed used for galilei-' // &
1511             'transformation, which may cause & instabilities in stably ' // &
1512             'stratified regions'
1513          CALL message( 'check_parameters', 'PA0048', 0, 1, 0, 6, 0 )
1514       ENDIF
1515    ENDIF
1516
1517!
1518!-- In case of using a prandtl-layer, calculated (or prescribed) surface
1519!-- fluxes have to be used in the diffusion-terms
1520    IF ( prandtl_layer )  use_surface_fluxes = .TRUE.
1521
1522!
1523!-- Check boundary conditions and set internal variables:
1524!-- Lateral boundary conditions
1525    IF ( bc_lr /= 'cyclic'  .AND.  bc_lr /= 'dirichlet/radiation'  .AND. &
1526         bc_lr /= 'radiation/dirichlet' )  THEN
1527       message_string = 'unknown boundary condition: bc_lr = "' // &
1528                        TRIM( bc_lr ) // '"'
1529       CALL message( 'check_parameters', 'PA0049', 1, 2, 0, 6, 0 )
1530    ENDIF
1531    IF ( bc_ns /= 'cyclic'  .AND.  bc_ns /= 'dirichlet/radiation'  .AND. &
1532         bc_ns /= 'radiation/dirichlet' )  THEN
1533       message_string = 'unknown boundary condition: bc_ns = "' // &
1534                        TRIM( bc_ns ) // '"'
1535       CALL message( 'check_parameters', 'PA0050', 1, 2, 0, 6, 0 )
1536    ENDIF
1537
1538!
1539!-- Internal variables used for speed optimization in if clauses
1540    IF ( bc_lr /= 'cyclic' )               bc_lr_cyc    = .FALSE.
1541    IF ( bc_lr == 'dirichlet/radiation' )  bc_lr_dirrad = .TRUE.
1542    IF ( bc_lr == 'radiation/dirichlet' )  bc_lr_raddir = .TRUE.
1543    IF ( bc_ns /= 'cyclic' )               bc_ns_cyc    = .FALSE.
1544    IF ( bc_ns == 'dirichlet/radiation' )  bc_ns_dirrad = .TRUE.
1545    IF ( bc_ns == 'radiation/dirichlet' )  bc_ns_raddir = .TRUE.
1546
1547!
1548!-- Non-cyclic lateral boundaries require the multigrid method and Piascek-
1549!-- Willimas or Wicker - Skamarock advection scheme. Several schemes
1550!-- and tools do not work with non-cyclic boundary conditions.
1551    IF ( bc_lr /= 'cyclic'  .OR.  bc_ns /= 'cyclic' )  THEN
1552       IF ( psolver /= 'multigrid' )  THEN
1553          message_string = 'non-cyclic lateral boundaries do not allow ' // &
1554                           'psolver = "' // TRIM( psolver ) // '"'
1555          CALL message( 'check_parameters', 'PA0051', 1, 2, 0, 6, 0 )
1556       ENDIF
1557       IF ( momentum_advec /= 'pw-scheme' .AND. &
1558            momentum_advec /= 'ws-scheme')  THEN
1559          message_string = 'non-cyclic lateral boundaries do not allow ' // &
1560                           'momentum_advec = "' // TRIM( momentum_advec ) // '"'
1561          CALL message( 'check_parameters', 'PA0052', 1, 2, 0, 6, 0 )
1562       ENDIF
1563       IF ( scalar_advec /= 'pw-scheme' .AND. &
1564            scalar_advec /= 'ws-scheme' )  THEN
1565          message_string = 'non-cyclic lateral boundaries do not allow ' // &
1566                           'scalar_advec = "' // TRIM( scalar_advec ) // '"'
1567          CALL message( 'check_parameters', 'PA0053', 1, 2, 0, 6, 0 )
1568       ENDIF
1569       IF ( galilei_transformation )  THEN
1570          message_string = 'non-cyclic lateral boundaries do not allow ' // &
1571                           'galilei_transformation = .T.'
1572          CALL message( 'check_parameters', 'PA0054', 1, 2, 0, 6, 0 )
1573       ENDIF
1574    ENDIF
1575
1576!
1577!-- Bottom boundary condition for the turbulent Kinetic energy
1578    IF ( bc_e_b == 'neumann' )  THEN
1579       ibc_e_b = 1
1580    ELSEIF ( bc_e_b == '(u*)**2+neumann' )  THEN
1581       ibc_e_b = 2
1582       IF ( .NOT. prandtl_layer )  THEN
1583          bc_e_b = 'neumann'
1584          ibc_e_b = 1
1585          message_string = 'boundary condition bc_e_b changed to "' // &
1586                           TRIM( bc_e_b ) // '"'
1587          CALL message( 'check_parameters', 'PA0057', 0, 1, 0, 6, 0 )
1588       ENDIF
1589    ELSE
1590       message_string = 'unknown boundary condition: bc_e_b = "' // &
1591                        TRIM( bc_e_b ) // '"'
1592       CALL message( 'check_parameters', 'PA0058', 1, 2, 0, 6, 0 )
1593    ENDIF
1594
1595!
1596!-- Boundary conditions for perturbation pressure
1597    IF ( bc_p_b == 'dirichlet' )  THEN
1598       ibc_p_b = 0
1599    ELSEIF ( bc_p_b == 'neumann' )  THEN
1600       ibc_p_b = 1
1601    ELSE
1602       message_string = 'unknown boundary condition: bc_p_b = "' // &
1603                        TRIM( bc_p_b ) // '"'
1604       CALL message( 'check_parameters', 'PA0059', 1, 2, 0, 6, 0 )
1605    ENDIF
1606
1607    IF ( bc_p_t == 'dirichlet' )  THEN
1608       ibc_p_t = 0
1609    ELSEIF ( bc_p_t == 'neumann' )  THEN
1610       ibc_p_t = 1
1611    ELSE
1612       message_string = 'unknown boundary condition: bc_p_t = "' // &
1613                        TRIM( bc_p_t ) // '"'
1614       CALL message( 'check_parameters', 'PA0061', 1, 2, 0, 6, 0 )
1615    ENDIF
1616
1617!
1618!-- Boundary conditions for potential temperature
1619    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
1620       ibc_pt_b = 2
1621    ELSE
1622       IF ( bc_pt_b == 'dirichlet' )  THEN
1623          ibc_pt_b = 0
1624       ELSEIF ( bc_pt_b == 'neumann' )  THEN
1625          ibc_pt_b = 1
1626       ELSE
1627          message_string = 'unknown boundary condition: bc_pt_b = "' // &
1628                           TRIM( bc_pt_b ) // '"'
1629          CALL message( 'check_parameters', 'PA0062', 1, 2, 0, 6, 0 )
1630       ENDIF
1631    ENDIF
1632
1633    IF ( bc_pt_t == 'dirichlet' )  THEN
1634       ibc_pt_t = 0
1635    ELSEIF ( bc_pt_t == 'neumann' )  THEN
1636       ibc_pt_t = 1
1637    ELSEIF ( bc_pt_t == 'initial_gradient' )  THEN
1638       ibc_pt_t = 2
1639    ELSE
1640       message_string = 'unknown boundary condition: bc_pt_t = "' // &
1641                        TRIM( bc_pt_t ) // '"'
1642       CALL message( 'check_parameters', 'PA0063', 1, 2, 0, 6, 0 )
1643    ENDIF
1644
1645    IF ( surface_heatflux == 9999999.9_wp  )  THEN
1646       constant_heatflux = .FALSE.
1647       IF ( large_scale_forcing  .OR.  land_surface )  THEN
1648          IF ( ibc_pt_b == 0 )  THEN
1649             constant_heatflux = .FALSE.
1650          ELSEIF ( ibc_pt_b == 1 )  THEN
1651             constant_heatflux = .TRUE.
1652             IF ( TRIM( initializing_actions ) /= 'read_restart_data' .AND.    &
1653                  .NOT. land_surface )  THEN
1654                surface_heatflux = shf_surf(1)
1655             ELSE
1656                surface_heatflux = 0.0_wp
1657             ENDIF
1658          ENDIF
1659       ENDIF
1660    ELSE
1661        constant_heatflux = .TRUE.
1662        IF ( TRIM( initializing_actions ) /= 'read_restart_data' .AND.         &
1663             .NOT. land_surface )  THEN
1664           surface_heatflux = shf_surf(1)
1665        ENDIF
1666    ENDIF
1667
1668    IF ( top_heatflux     == 9999999.9_wp )  constant_top_heatflux = .FALSE.
1669
1670    IF ( neutral )  THEN
1671
1672       IF ( surface_heatflux /= 0.0_wp  .AND. surface_heatflux /= 9999999.9_wp ) &
1673       THEN
1674          message_string = 'heatflux must not be set for pure neutral flow'
1675          CALL message( 'check_parameters', 'PA0351', 1, 2, 0, 6, 0 )
1676       ENDIF
1677
1678       IF ( top_heatflux /= 0.0_wp  .AND.  top_heatflux /= 9999999.9_wp ) &
1679       THEN
1680          message_string = 'heatflux must not be set for pure neutral flow'
1681          CALL message( 'check_parameters', 'PA0351', 1, 2, 0, 6, 0 )
1682       ENDIF
1683
1684    ENDIF
1685
1686    IF ( top_momentumflux_u /= 9999999.9_wp  .AND.  &
1687         top_momentumflux_v /= 9999999.9_wp )  THEN
1688       constant_top_momentumflux = .TRUE.
1689    ELSEIF (  .NOT. ( top_momentumflux_u == 9999999.9_wp  .AND.  &
1690           top_momentumflux_v == 9999999.9_wp ) )  THEN
1691       message_string = 'both, top_momentumflux_u AND top_momentumflux_v ' // &
1692                        'must be set'
1693       CALL message( 'check_parameters', 'PA0064', 1, 2, 0, 6, 0 )
1694    ENDIF
1695
1696!
1697!-- A given surface temperature implies Dirichlet boundary condition for
1698!-- temperature. In this case specification of a constant heat flux is
1699!-- forbidden.
1700    IF ( ibc_pt_b == 0  .AND.   constant_heatflux  .AND. &
1701         surface_heatflux /= 0.0_wp )  THEN
1702       message_string = 'boundary_condition: bc_pt_b = "' // TRIM( bc_pt_b ) //&
1703                        '& is not allowed with constant_heatflux = .TRUE.'
1704       CALL message( 'check_parameters', 'PA0065', 1, 2, 0, 6, 0 )
1705    ENDIF
1706    IF ( constant_heatflux  .AND.  pt_surface_initial_change /= 0.0_wp )  THEN
1707       WRITE ( message_string, * )  'constant_heatflux = .TRUE. is not allo', &
1708               'wed with pt_surface_initial_change (/=0) = ', &
1709               pt_surface_initial_change
1710       CALL message( 'check_parameters', 'PA0066', 1, 2, 0, 6, 0 )
1711    ENDIF
1712
1713!
1714!-- A given temperature at the top implies Dirichlet boundary condition for
1715!-- temperature. In this case specification of a constant heat flux is
1716!-- forbidden.
1717    IF ( ibc_pt_t == 0  .AND.   constant_top_heatflux  .AND. &
1718         top_heatflux /= 0.0_wp )  THEN
1719       message_string = 'boundary_condition: bc_pt_t = "' // TRIM( bc_pt_t ) //&
1720                        '" is not allowed with constant_top_heatflux = .TRUE.'
1721       CALL message( 'check_parameters', 'PA0067', 1, 2, 0, 6, 0 )
1722    ENDIF
1723
1724!
1725!-- Boundary conditions for salinity
1726    IF ( ocean )  THEN
1727       IF ( bc_sa_t == 'dirichlet' )  THEN
1728          ibc_sa_t = 0
1729       ELSEIF ( bc_sa_t == 'neumann' )  THEN
1730          ibc_sa_t = 1
1731       ELSE
1732          message_string = 'unknown boundary condition: bc_sa_t = "' // &
1733                           TRIM( bc_sa_t ) // '"'
1734          CALL message( 'check_parameters', 'PA0068', 1, 2, 0, 6, 0 )
1735       ENDIF
1736
1737       IF ( top_salinityflux == 9999999.9_wp )  constant_top_salinityflux = .FALSE.
1738       IF ( ibc_sa_t == 1  .AND.   top_salinityflux == 9999999.9_wp )  THEN
1739          message_string = 'boundary condition: bc_sa_t = "' // &
1740                           TRIM( bc_sa_t ) // '" requires to set ' // &
1741                           'top_salinityflux'
1742          CALL message( 'check_parameters', 'PA0069', 1, 2, 0, 6, 0 )
1743       ENDIF
1744
1745!
1746!--    A fixed salinity at the top implies Dirichlet boundary condition for
1747!--    salinity. In this case specification of a constant salinity flux is
1748!--    forbidden.
1749       IF ( ibc_sa_t == 0  .AND.   constant_top_salinityflux  .AND. &
1750            top_salinityflux /= 0.0_wp )  THEN
1751          message_string = 'boundary condition: bc_sa_t = "' // &
1752                           TRIM( bc_sa_t ) // '" is not allowed with ' // &
1753                           'constant_top_salinityflux = .TRUE.'
1754          CALL message( 'check_parameters', 'PA0070', 1, 2, 0, 6, 0 )
1755       ENDIF
1756
1757    ENDIF
1758
1759!
1760!-- In case of humidity or passive scalar, set boundary conditions for total
1761!-- water content / scalar
1762    IF ( humidity  .OR.  passive_scalar ) THEN
1763       IF ( humidity )  THEN
1764          sq = 'q'
1765       ELSE
1766          sq = 's'
1767       ENDIF
1768       IF ( bc_q_b == 'dirichlet' )  THEN
1769          ibc_q_b = 0
1770       ELSEIF ( bc_q_b == 'neumann' )  THEN
1771          ibc_q_b = 1
1772       ELSE
1773          message_string = 'unknown boundary condition: bc_' // TRIM( sq ) // &
1774                           '_b ="' // TRIM( bc_q_b ) // '"'
1775          CALL message( 'check_parameters', 'PA0071', 1, 2, 0, 6, 0 )
1776       ENDIF
1777       IF ( bc_q_t == 'dirichlet' )  THEN
1778          ibc_q_t = 0
1779       ELSEIF ( bc_q_t == 'neumann' )  THEN
1780          ibc_q_t = 1
1781       ELSE
1782          message_string = 'unknown boundary condition: bc_' // TRIM( sq ) // &
1783                           '_t ="' // TRIM( bc_q_t ) // '"'
1784          CALL message( 'check_parameters', 'PA0072', 1, 2, 0, 6, 0 )
1785       ENDIF
1786
1787       IF ( surface_waterflux == 9999999.9_wp  )  THEN
1788          constant_waterflux = .FALSE.
1789          IF ( large_scale_forcing )  THEN
1790             IF ( ibc_q_b == 0 )  THEN
1791                constant_waterflux = .FALSE.
1792             ELSEIF ( ibc_q_b == 1 )  THEN
1793                constant_waterflux = .TRUE.
1794                IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
1795                   surface_waterflux = qsws_surf(1)
1796                ENDIF
1797             ENDIF
1798          ENDIF
1799       ELSE
1800          constant_waterflux = .TRUE.
1801          IF ( TRIM( initializing_actions ) /= 'read_restart_data' .AND. &
1802                 large_scale_forcing ) THEN
1803             surface_waterflux = qsws_surf(1)
1804          ENDIF
1805       ENDIF
1806
1807!
1808!--    A given surface humidity implies Dirichlet boundary condition for
1809!--    humidity. In this case specification of a constant water flux is
1810!--    forbidden.
1811       IF ( ibc_q_b == 0  .AND.  constant_waterflux )  THEN
1812          message_string = 'boundary condition: bc_' // TRIM( sq ) // '_b ' // &
1813                           '= "' // TRIM( bc_q_b ) // '" is not allowed wi' // &
1814                           'th prescribed surface flux'
1815          CALL message( 'check_parameters', 'PA0073', 1, 2, 0, 6, 0 )
1816       ENDIF
1817       IF ( constant_waterflux  .AND.  q_surface_initial_change /= 0.0_wp )  THEN
1818          WRITE( message_string, * )  'a prescribed surface flux is not allo', &
1819                 'wed with ', sq, '_surface_initial_change (/=0) = ', &
1820                 q_surface_initial_change
1821          CALL message( 'check_parameters', 'PA0074', 1, 2, 0, 6, 0 )
1822       ENDIF
1823
1824    ENDIF
1825!
1826!-- Boundary conditions for horizontal components of wind speed
1827    IF ( bc_uv_b == 'dirichlet' )  THEN
1828       ibc_uv_b = 0
1829    ELSEIF ( bc_uv_b == 'neumann' )  THEN
1830       ibc_uv_b = 1
1831       IF ( prandtl_layer )  THEN
1832          message_string = 'boundary condition: bc_uv_b = "' // &
1833               TRIM( bc_uv_b ) // '" is not allowed with prandtl_layer = .TRUE.'
1834          CALL message( 'check_parameters', 'PA0075', 1, 2, 0, 6, 0 )
1835       ENDIF
1836    ELSE
1837       message_string = 'unknown boundary condition: bc_uv_b = "' // &
1838                        TRIM( bc_uv_b ) // '"'
1839       CALL message( 'check_parameters', 'PA0076', 1, 2, 0, 6, 0 )
1840    ENDIF
1841!
1842!-- In case of coupled simulations u and v at the ground in atmosphere will be
1843!-- assigned with the u and v values of the ocean surface
1844    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
1845       ibc_uv_b = 2
1846    ENDIF
1847
1848    IF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
1849       bc_uv_t = 'neumann'
1850       ibc_uv_t = 1
1851    ELSE
1852       IF ( bc_uv_t == 'dirichlet' .OR. bc_uv_t == 'dirichlet_0' )  THEN
1853          ibc_uv_t = 0
1854          IF ( bc_uv_t == 'dirichlet_0' )  THEN
1855!
1856!--          Velocities for the initial u,v-profiles are set zero at the top
1857!--          in case of dirichlet_0 conditions
1858             u_init(nzt+1)    = 0.0_wp
1859             v_init(nzt+1)    = 0.0_wp
1860          ENDIF
1861       ELSEIF ( bc_uv_t == 'neumann' )  THEN
1862          ibc_uv_t = 1
1863       ELSE
1864          message_string = 'unknown boundary condition: bc_uv_t = "' // &
1865                           TRIM( bc_uv_t ) // '"'
1866          CALL message( 'check_parameters', 'PA0077', 1, 2, 0, 6, 0 )
1867       ENDIF
1868    ENDIF
1869
1870!
1871!-- Compute and check, respectively, the Rayleigh Damping parameter
1872    IF ( rayleigh_damping_factor == -1.0_wp )  THEN
1873       rayleigh_damping_factor = 0.0_wp
1874    ELSE
1875       IF ( rayleigh_damping_factor < 0.0_wp .OR. rayleigh_damping_factor > 1.0_wp ) &
1876       THEN
1877          WRITE( message_string, * )  'rayleigh_damping_factor = ', &
1878                              rayleigh_damping_factor, ' out of range [0.0,1.0]'
1879          CALL message( 'check_parameters', 'PA0078', 1, 2, 0, 6, 0 )
1880       ENDIF
1881    ENDIF
1882
1883    IF ( rayleigh_damping_height == -1.0_wp )  THEN
1884       IF ( .NOT. ocean )  THEN
1885          rayleigh_damping_height = 0.66666666666_wp * zu(nzt)
1886       ELSE
1887          rayleigh_damping_height = 0.66666666666_wp * zu(nzb)
1888       ENDIF
1889    ELSE
1890       IF ( .NOT. ocean )  THEN
1891          IF ( rayleigh_damping_height < 0.0_wp  .OR. &
1892               rayleigh_damping_height > zu(nzt) )  THEN
1893             WRITE( message_string, * )  'rayleigh_damping_height = ', &
1894                   rayleigh_damping_height, ' out of range [0.0,', zu(nzt), ']'
1895             CALL message( 'check_parameters', 'PA0079', 1, 2, 0, 6, 0 )
1896          ENDIF
1897       ELSE
1898          IF ( rayleigh_damping_height > 0.0_wp  .OR. &
1899               rayleigh_damping_height < zu(nzb) )  THEN
1900             WRITE( message_string, * )  'rayleigh_damping_height = ', &
1901                   rayleigh_damping_height, ' out of range [0.0,', zu(nzb), ']'
1902             CALL message( 'check_parameters', 'PA0079', 1, 2, 0, 6, 0 )
1903          ENDIF
1904       ENDIF
1905    ENDIF
1906
1907!
1908!-- Check number of chosen statistic regions. More than 10 regions are not
1909!-- allowed, because so far no more than 10 corresponding output files can
1910!-- be opened (cf. check_open)
1911    IF ( statistic_regions > 9  .OR.  statistic_regions < 0 )  THEN
1912       WRITE ( message_string, * ) 'number of statistic_regions = ', &
1913                   statistic_regions+1, ' but only 10 regions are allowed'
1914       CALL message( 'check_parameters', 'PA0082', 1, 2, 0, 6, 0 )
1915    ENDIF
1916    IF ( normalizing_region > statistic_regions  .OR. &
1917         normalizing_region < 0)  THEN
1918       WRITE ( message_string, * ) 'normalizing_region = ', &
1919                normalizing_region, ' must be >= 0 and <= ',statistic_regions, &
1920                ' (value of statistic_regions)'
1921       CALL message( 'check_parameters', 'PA0083', 1, 2, 0, 6, 0 )
1922    ENDIF
1923
1924!
1925!-- Set the default intervals for data output, if necessary
1926!-- NOTE: dt_dosp has already been set in package_parin
1927    IF ( dt_data_output /= 9999999.9_wp )  THEN
1928       IF ( dt_dopr           == 9999999.9_wp )  dt_dopr           = dt_data_output
1929       IF ( dt_dopts          == 9999999.9_wp )  dt_dopts          = dt_data_output
1930       IF ( dt_do2d_xy        == 9999999.9_wp )  dt_do2d_xy        = dt_data_output
1931       IF ( dt_do2d_xz        == 9999999.9_wp )  dt_do2d_xz        = dt_data_output
1932       IF ( dt_do2d_yz        == 9999999.9_wp )  dt_do2d_yz        = dt_data_output
1933       IF ( dt_do3d           == 9999999.9_wp )  dt_do3d           = dt_data_output
1934       IF ( dt_data_output_av == 9999999.9_wp )  dt_data_output_av = dt_data_output
1935       DO  mid = 1, max_masks
1936          IF ( dt_domask(mid) == 9999999.9_wp )  dt_domask(mid)    = dt_data_output
1937       ENDDO
1938    ENDIF
1939
1940!
1941!-- Set the default skip time intervals for data output, if necessary
1942    IF ( skip_time_dopr    == 9999999.9_wp ) &
1943                                       skip_time_dopr    = skip_time_data_output
1944    IF ( skip_time_dosp    == 9999999.9_wp ) &
1945                                       skip_time_dosp    = skip_time_data_output
1946    IF ( skip_time_do2d_xy == 9999999.9_wp ) &
1947                                       skip_time_do2d_xy = skip_time_data_output
1948    IF ( skip_time_do2d_xz == 9999999.9_wp ) &
1949                                       skip_time_do2d_xz = skip_time_data_output
1950    IF ( skip_time_do2d_yz == 9999999.9_wp ) &
1951                                       skip_time_do2d_yz = skip_time_data_output
1952    IF ( skip_time_do3d    == 9999999.9_wp ) &
1953                                       skip_time_do3d    = skip_time_data_output
1954    IF ( skip_time_data_output_av == 9999999.9_wp ) &
1955                                skip_time_data_output_av = skip_time_data_output
1956    DO  mid = 1, max_masks
1957       IF ( skip_time_domask(mid) == 9999999.9_wp ) &
1958                                skip_time_domask(mid)    = skip_time_data_output
1959    ENDDO
1960
1961!
1962!-- Check the average intervals (first for 3d-data, then for profiles and
1963!-- spectra)
1964    IF ( averaging_interval > dt_data_output_av )  THEN
1965       WRITE( message_string, * )  'averaging_interval = ', &
1966             averaging_interval, ' must be <= dt_data_output = ', dt_data_output
1967       CALL message( 'check_parameters', 'PA0085', 1, 2, 0, 6, 0 )
1968    ENDIF
1969
1970    IF ( averaging_interval_pr == 9999999.9_wp )  THEN
1971       averaging_interval_pr = averaging_interval
1972    ENDIF
1973
1974    IF ( averaging_interval_pr > dt_dopr )  THEN
1975       WRITE( message_string, * )  'averaging_interval_pr = ', &
1976             averaging_interval_pr, ' must be <= dt_dopr = ', dt_dopr
1977       CALL message( 'check_parameters', 'PA0086', 1, 2, 0, 6, 0 )
1978    ENDIF
1979
1980    IF ( averaging_interval_sp == 9999999.9_wp )  THEN
1981       averaging_interval_sp = averaging_interval
1982    ENDIF
1983
1984    IF ( averaging_interval_sp > dt_dosp )  THEN
1985       WRITE( message_string, * )  'averaging_interval_sp = ', &
1986             averaging_interval_sp, ' must be <= dt_dosp = ', dt_dosp
1987       CALL message( 'check_parameters', 'PA0087', 1, 2, 0, 6, 0 )
1988    ENDIF
1989
1990!
1991!-- Set the default interval for profiles entering the temporal average
1992    IF ( dt_averaging_input_pr == 9999999.9_wp )  THEN
1993       dt_averaging_input_pr = dt_averaging_input
1994    ENDIF
1995
1996!
1997!-- Set the default interval for the output of timeseries to a reasonable
1998!-- value (tries to minimize the number of calls of flow_statistics)
1999    IF ( dt_dots == 9999999.9_wp )  THEN
2000       IF ( averaging_interval_pr == 0.0_wp )  THEN
2001          dt_dots = MIN( dt_run_control, dt_dopr )
2002       ELSE
2003          dt_dots = MIN( dt_run_control, dt_averaging_input_pr )
2004       ENDIF
2005    ENDIF
2006
2007!
2008!-- Check the sample rate for averaging (first for 3d-data, then for profiles)
2009    IF ( dt_averaging_input > averaging_interval )  THEN
2010       WRITE( message_string, * )  'dt_averaging_input = ', &
2011                dt_averaging_input, ' must be <= averaging_interval = ', &
2012                averaging_interval
2013       CALL message( 'check_parameters', 'PA0088', 1, 2, 0, 6, 0 )
2014    ENDIF
2015
2016    IF ( dt_averaging_input_pr > averaging_interval_pr )  THEN
2017       WRITE( message_string, * )  'dt_averaging_input_pr = ', &
2018                dt_averaging_input_pr, ' must be <= averaging_interval_pr = ', &
2019                averaging_interval_pr
2020       CALL message( 'check_parameters', 'PA0089', 1, 2, 0, 6, 0 )
2021    ENDIF
2022
2023!
2024!-- Set the default value for the integration interval of precipitation amount
2025    IF ( precipitation )  THEN
2026       IF ( precipitation_amount_interval == 9999999.9_wp )  THEN
2027          precipitation_amount_interval = dt_do2d_xy
2028       ELSE
2029          IF ( precipitation_amount_interval > dt_do2d_xy )  THEN
2030             WRITE( message_string, * )  'precipitation_amount_interval = ', &
2031                 precipitation_amount_interval, ' must not be larger than ', &
2032                 'dt_do2d_xy = ', dt_do2d_xy
2033             CALL message( 'check_parameters', 'PA0090', 1, 2, 0, 6, 0 )
2034          ENDIF
2035       ENDIF
2036    ENDIF
2037
2038!
2039!-- Determine the number of output profiles and check whether they are
2040!-- permissible
2041    DO  WHILE ( data_output_pr(dopr_n+1) /= '          ' )
2042
2043       dopr_n = dopr_n + 1
2044       i = dopr_n
2045
2046!
2047!--    Determine internal profile number (for hom, homs)
2048!--    and store height levels
2049       SELECT CASE ( TRIM( data_output_pr(i) ) )
2050
2051          CASE ( 'u', '#u' )
2052             dopr_index(i) = 1
2053             dopr_unit(i)  = 'm/s'
2054             hom(:,2,1,:)  = SPREAD( zu, 2, statistic_regions+1 )
2055             IF ( data_output_pr(i)(1:1) == '#' )  THEN
2056                dopr_initial_index(i) = 5
2057                hom(:,2,5,:)          = SPREAD( zu, 2, statistic_regions+1 )
2058                data_output_pr(i)     = data_output_pr(i)(2:)
2059             ENDIF
2060
2061          CASE ( 'v', '#v' )
2062             dopr_index(i) = 2
2063             dopr_unit(i)  = 'm/s'
2064             hom(:,2,2,:)  = SPREAD( zu, 2, statistic_regions+1 )
2065             IF ( data_output_pr(i)(1:1) == '#' )  THEN
2066                dopr_initial_index(i) = 6
2067                hom(:,2,6,:)          = SPREAD( zu, 2, statistic_regions+1 )
2068                data_output_pr(i)     = data_output_pr(i)(2:)
2069             ENDIF
2070
2071          CASE ( 'w' )
2072             dopr_index(i) = 3
2073             dopr_unit(i)  = 'm/s'
2074             hom(:,2,3,:)  = SPREAD( zw, 2, statistic_regions+1 )
2075
2076          CASE ( 'pt', '#pt' )
2077             IF ( .NOT. cloud_physics ) THEN
2078                dopr_index(i) = 4
2079                dopr_unit(i)  = 'K'
2080                hom(:,2,4,:)  = SPREAD( zu, 2, statistic_regions+1 )
2081                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2082                   dopr_initial_index(i) = 7
2083                   hom(:,2,7,:)          = SPREAD( zu, 2, statistic_regions+1 )
2084                   hom(nzb,2,7,:)        = 0.0_wp    ! because zu(nzb) is negative
2085                   data_output_pr(i)     = data_output_pr(i)(2:)
2086                ENDIF
2087             ELSE
2088                dopr_index(i) = 43
2089                dopr_unit(i)  = 'K'
2090                hom(:,2,43,:)  = SPREAD( zu, 2, statistic_regions+1 )
2091                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2092                   dopr_initial_index(i) = 28
2093                   hom(:,2,28,:)         = SPREAD( zu, 2, statistic_regions+1 )
2094                   hom(nzb,2,28,:)       = 0.0_wp    ! because zu(nzb) is negative
2095                   data_output_pr(i)     = data_output_pr(i)(2:)
2096                ENDIF
2097             ENDIF
2098
2099          CASE ( 'e' )
2100             dopr_index(i)  = 8
2101             dopr_unit(i)   = 'm2/s2'
2102             hom(:,2,8,:)   = SPREAD( zu, 2, statistic_regions+1 )
2103             hom(nzb,2,8,:) = 0.0_wp
2104
2105          CASE ( 'km', '#km' )
2106             dopr_index(i)  = 9
2107             dopr_unit(i)   = 'm2/s'
2108             hom(:,2,9,:)   = SPREAD( zu, 2, statistic_regions+1 )
2109             hom(nzb,2,9,:) = 0.0_wp
2110             IF ( data_output_pr(i)(1:1) == '#' )  THEN
2111                dopr_initial_index(i) = 23
2112                hom(:,2,23,:)         = hom(:,2,9,:)
2113                data_output_pr(i)     = data_output_pr(i)(2:)
2114             ENDIF
2115
2116          CASE ( 'kh', '#kh' )
2117             dopr_index(i)   = 10
2118             dopr_unit(i)    = 'm2/s'
2119             hom(:,2,10,:)   = SPREAD( zu, 2, statistic_regions+1 )
2120             hom(nzb,2,10,:) = 0.0_wp
2121             IF ( data_output_pr(i)(1:1) == '#' )  THEN
2122                dopr_initial_index(i) = 24
2123                hom(:,2,24,:)         = hom(:,2,10,:)
2124                data_output_pr(i)     = data_output_pr(i)(2:)
2125             ENDIF
2126
2127          CASE ( 'l', '#l' )
2128             dopr_index(i)   = 11
2129             dopr_unit(i)    = 'm'
2130             hom(:,2,11,:)   = SPREAD( zu, 2, statistic_regions+1 )
2131             hom(nzb,2,11,:) = 0.0_wp
2132             IF ( data_output_pr(i)(1:1) == '#' )  THEN
2133                dopr_initial_index(i) = 25
2134                hom(:,2,25,:)         = hom(:,2,11,:)
2135                data_output_pr(i)     = data_output_pr(i)(2:)
2136             ENDIF
2137
2138          CASE ( 'w"u"' )
2139             dopr_index(i) = 12
2140             dopr_unit(i)  = 'm2/s2'
2141             hom(:,2,12,:) = SPREAD( zw, 2, statistic_regions+1 )
2142             IF ( prandtl_layer )  hom(nzb,2,12,:) = zu(1)
2143
2144          CASE ( 'w*u*' )
2145             dopr_index(i) = 13
2146             dopr_unit(i)  = 'm2/s2'
2147             hom(:,2,13,:) = SPREAD( zw, 2, statistic_regions+1 )
2148
2149          CASE ( 'w"v"' )
2150             dopr_index(i) = 14
2151             dopr_unit(i)  = 'm2/s2'
2152             hom(:,2,14,:) = SPREAD( zw, 2, statistic_regions+1 )
2153             IF ( prandtl_layer )  hom(nzb,2,14,:) = zu(1)
2154
2155          CASE ( 'w*v*' )
2156             dopr_index(i) = 15
2157             dopr_unit(i)  = 'm2/s2'
2158             hom(:,2,15,:) = SPREAD( zw, 2, statistic_regions+1 )
2159
2160          CASE ( 'w"pt"' )
2161             dopr_index(i) = 16
2162             dopr_unit(i)  = 'K m/s'
2163             hom(:,2,16,:) = SPREAD( zw, 2, statistic_regions+1 )
2164
2165          CASE ( 'w*pt*' )
2166             dopr_index(i) = 17
2167             dopr_unit(i)  = 'K m/s'
2168             hom(:,2,17,:) = SPREAD( zw, 2, statistic_regions+1 )
2169
2170          CASE ( 'wpt' )
2171             dopr_index(i) = 18
2172             dopr_unit(i)  = 'K m/s'
2173             hom(:,2,18,:) = SPREAD( zw, 2, statistic_regions+1 )
2174
2175          CASE ( 'wu' )
2176             dopr_index(i) = 19
2177             dopr_unit(i)  = 'm2/s2'
2178             hom(:,2,19,:) = SPREAD( zw, 2, statistic_regions+1 )
2179             IF ( prandtl_layer )  hom(nzb,2,19,:) = zu(1)
2180
2181          CASE ( 'wv' )
2182             dopr_index(i) = 20
2183             dopr_unit(i)  = 'm2/s2'
2184             hom(:,2,20,:) = SPREAD( zw, 2, statistic_regions+1 )
2185             IF ( prandtl_layer )  hom(nzb,2,20,:) = zu(1)
2186
2187          CASE ( 'w*pt*BC' )
2188             dopr_index(i) = 21
2189             dopr_unit(i)  = 'K m/s'
2190             hom(:,2,21,:) = SPREAD( zw, 2, statistic_regions+1 )
2191
2192          CASE ( 'wptBC' )
2193             dopr_index(i) = 22
2194             dopr_unit(i)  = 'K m/s'
2195             hom(:,2,22,:) = SPREAD( zw, 2, statistic_regions+1 )
2196
2197          CASE ( 'sa', '#sa' )
2198             IF ( .NOT. ocean )  THEN
2199                message_string = 'data_output_pr = ' // &
2200                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2201                                 'lemented for ocean = .FALSE.'
2202                CALL message( 'check_parameters', 'PA0091', 1, 2, 0, 6, 0 )
2203             ELSE
2204                dopr_index(i) = 23
2205                dopr_unit(i)  = 'psu'
2206                hom(:,2,23,:) = SPREAD( zu, 2, statistic_regions+1 )
2207                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2208                   dopr_initial_index(i) = 26
2209                   hom(:,2,26,:)         = SPREAD( zu, 2, statistic_regions+1 )
2210                   hom(nzb,2,26,:)       = 0.0_wp    ! because zu(nzb) is negative
2211                   data_output_pr(i)     = data_output_pr(i)(2:)
2212                ENDIF
2213             ENDIF
2214
2215          CASE ( 'u*2' )
2216             dopr_index(i) = 30
2217             dopr_unit(i)  = 'm2/s2'
2218             hom(:,2,30,:) = SPREAD( zu, 2, statistic_regions+1 )
2219
2220          CASE ( 'v*2' )
2221             dopr_index(i) = 31
2222             dopr_unit(i)  = 'm2/s2'
2223             hom(:,2,31,:) = SPREAD( zu, 2, statistic_regions+1 )
2224
2225          CASE ( 'w*2' )
2226             dopr_index(i) = 32
2227             dopr_unit(i)  = 'm2/s2'
2228             hom(:,2,32,:) = SPREAD( zw, 2, statistic_regions+1 )
2229
2230          CASE ( 'pt*2' )
2231             dopr_index(i) = 33
2232             dopr_unit(i)  = 'K2'
2233             hom(:,2,33,:) = SPREAD( zu, 2, statistic_regions+1 )
2234
2235          CASE ( 'e*' )
2236             dopr_index(i) = 34
2237             dopr_unit(i)  = 'm2/s2'
2238             hom(:,2,34,:) = SPREAD( zu, 2, statistic_regions+1 )
2239
2240          CASE ( 'w*2pt*' )
2241             dopr_index(i) = 35
2242             dopr_unit(i)  = 'K m2/s2'
2243             hom(:,2,35,:) = SPREAD( zw, 2, statistic_regions+1 )
2244
2245          CASE ( 'w*pt*2' )
2246             dopr_index(i) = 36
2247             dopr_unit(i)  = 'K2 m/s'
2248             hom(:,2,36,:) = SPREAD( zw, 2, statistic_regions+1 )
2249
2250          CASE ( 'w*e*' )
2251             dopr_index(i) = 37
2252             dopr_unit(i)  = 'm3/s3'
2253             hom(:,2,37,:) = SPREAD( zw, 2, statistic_regions+1 )
2254
2255          CASE ( 'w*3' )
2256             dopr_index(i) = 38
2257             dopr_unit(i)  = 'm3/s3'
2258             hom(:,2,38,:) = SPREAD( zw, 2, statistic_regions+1 )
2259
2260          CASE ( 'Sw' )
2261             dopr_index(i) = 39
2262             dopr_unit(i)  = 'none'
2263             hom(:,2,39,:) = SPREAD( zw, 2, statistic_regions+1 )
2264
2265          CASE ( 'p' )
2266             dopr_index(i) = 40
2267             dopr_unit(i)  = 'Pa'
2268             hom(:,2,40,:) = SPREAD( zu, 2, statistic_regions+1 )
2269
2270          CASE ( 'q', '#q' )
2271             IF ( .NOT. humidity )  THEN
2272                message_string = 'data_output_pr = ' // &
2273                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2274                                 'lemented for humidity = .FALSE.'
2275                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
2276             ELSE
2277                dopr_index(i) = 41
2278                dopr_unit(i)  = 'kg/kg'
2279                hom(:,2,41,:) = SPREAD( zu, 2, statistic_regions+1 )
2280                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2281                   dopr_initial_index(i) = 26
2282                   hom(:,2,26,:)         = SPREAD( zu, 2, statistic_regions+1 )
2283                   hom(nzb,2,26,:)       = 0.0_wp    ! because zu(nzb) is negative
2284                   data_output_pr(i)     = data_output_pr(i)(2:)
2285                ENDIF
2286             ENDIF
2287
2288          CASE ( 's', '#s' )
2289             IF ( .NOT. passive_scalar )  THEN
2290                message_string = 'data_output_pr = ' // &
2291                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2292                                 'lemented for passive_scalar = .FALSE.'
2293                CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
2294             ELSE
2295                dopr_index(i) = 41
2296                dopr_unit(i)  = 'kg/m3'
2297                hom(:,2,41,:) = SPREAD( zu, 2, statistic_regions+1 )
2298                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2299                   dopr_initial_index(i) = 26
2300                   hom(:,2,26,:)         = SPREAD( zu, 2, statistic_regions+1 )
2301                   hom(nzb,2,26,:)       = 0.0_wp    ! because zu(nzb) is negative
2302                   data_output_pr(i)     = data_output_pr(i)(2:)
2303                ENDIF
2304             ENDIF
2305
2306          CASE ( 'qv', '#qv' )
2307             IF ( .NOT. cloud_physics ) THEN
2308                dopr_index(i) = 41
2309                dopr_unit(i)  = 'kg/kg'
2310                hom(:,2,41,:) = SPREAD( zu, 2, statistic_regions+1 )
2311                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2312                   dopr_initial_index(i) = 26
2313                   hom(:,2,26,:)         = SPREAD( zu, 2, statistic_regions+1 )
2314                   hom(nzb,2,26,:)       = 0.0_wp    ! because zu(nzb) is negative
2315                   data_output_pr(i)     = data_output_pr(i)(2:)
2316                ENDIF
2317             ELSE
2318                dopr_index(i) = 42
2319                dopr_unit(i)  = 'kg/kg'
2320                hom(:,2,42,:) = SPREAD( zu, 2, statistic_regions+1 )
2321                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2322                   dopr_initial_index(i) = 27
2323                   hom(:,2,27,:)         = SPREAD( zu, 2, statistic_regions+1 )
2324                   hom(nzb,2,27,:)       = 0.0_wp   ! because zu(nzb) is negative
2325                   data_output_pr(i)     = data_output_pr(i)(2:)
2326                ENDIF
2327             ENDIF
2328
2329          CASE ( 'lpt', '#lpt' )
2330             IF ( .NOT. cloud_physics ) THEN
2331                message_string = 'data_output_pr = ' // &
2332                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2333                                 'lemented for cloud_physics = .FALSE.'
2334                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
2335             ELSE
2336                dopr_index(i) = 4
2337                dopr_unit(i)  = 'K'
2338                hom(:,2,4,:)  = SPREAD( zu, 2, statistic_regions+1 )
2339                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2340                   dopr_initial_index(i) = 7
2341                   hom(:,2,7,:)          = SPREAD( zu, 2, statistic_regions+1 )
2342                   hom(nzb,2,7,:)        = 0.0_wp    ! because zu(nzb) is negative
2343                   data_output_pr(i)     = data_output_pr(i)(2:)
2344                ENDIF
2345             ENDIF
2346
2347          CASE ( 'vpt', '#vpt' )
2348             dopr_index(i) = 44
2349             dopr_unit(i)  = 'K'
2350             hom(:,2,44,:) = SPREAD( zu, 2, statistic_regions+1 )
2351             IF ( data_output_pr(i)(1:1) == '#' )  THEN
2352                dopr_initial_index(i) = 29
2353                hom(:,2,29,:)         = SPREAD( zu, 2, statistic_regions+1 )
2354                hom(nzb,2,29,:)       = 0.0_wp    ! because zu(nzb) is negative
2355                data_output_pr(i)     = data_output_pr(i)(2:)
2356             ENDIF
2357
2358          CASE ( 'w"vpt"' )
2359             dopr_index(i) = 45
2360             dopr_unit(i)  = 'K m/s'
2361             hom(:,2,45,:) = SPREAD( zw, 2, statistic_regions+1 )
2362
2363          CASE ( 'w*vpt*' )
2364             dopr_index(i) = 46
2365             dopr_unit(i)  = 'K m/s'
2366             hom(:,2,46,:) = SPREAD( zw, 2, statistic_regions+1 )
2367
2368          CASE ( 'wvpt' )
2369             dopr_index(i) = 47
2370             dopr_unit(i)  = 'K m/s'
2371             hom(:,2,47,:) = SPREAD( zw, 2, statistic_regions+1 )
2372
2373          CASE ( 'w"q"' )
2374             IF ( .NOT. humidity )  THEN
2375                message_string = 'data_output_pr = ' // &
2376                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2377                                 'lemented for humidity = .FALSE.'
2378                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
2379             ELSE
2380                dopr_index(i) = 48
2381                dopr_unit(i)  = 'kg/kg m/s'
2382                hom(:,2,48,:) = SPREAD( zw, 2, statistic_regions+1 )
2383             ENDIF
2384
2385          CASE ( 'w*q*' )
2386             IF ( .NOT. humidity )  THEN
2387                message_string = 'data_output_pr = ' // &
2388                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2389                                 'lemented for humidity = .FALSE.'
2390                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
2391             ELSE
2392                dopr_index(i) = 49
2393                dopr_unit(i)  = 'kg/kg m/s'
2394                hom(:,2,49,:) = SPREAD( zw, 2, statistic_regions+1 )
2395             ENDIF
2396
2397          CASE ( 'wq' )
2398             IF ( .NOT. humidity )  THEN
2399                message_string = 'data_output_pr = ' // &
2400                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2401                                 'lemented for humidity = .FALSE.'
2402                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
2403             ELSE
2404                dopr_index(i) = 50
2405                dopr_unit(i)  = 'kg/kg m/s'
2406                hom(:,2,50,:) = SPREAD( zw, 2, statistic_regions+1 )
2407             ENDIF
2408
2409          CASE ( 'w"s"' )
2410             IF ( .NOT. passive_scalar ) THEN
2411                message_string = 'data_output_pr = ' // &
2412                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2413                                 'lemented for passive_scalar = .FALSE.'
2414                CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
2415             ELSE
2416                dopr_index(i) = 48
2417                dopr_unit(i)  = 'kg/m3 m/s'
2418                hom(:,2,48,:) = SPREAD( zw, 2, statistic_regions+1 )
2419             ENDIF
2420
2421          CASE ( 'w*s*' )
2422             IF ( .NOT. passive_scalar ) THEN
2423                message_string = 'data_output_pr = ' // &
2424                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2425                                 'lemented for passive_scalar = .FALSE.'
2426                CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
2427             ELSE
2428                dopr_index(i) = 49
2429                dopr_unit(i)  = 'kg/m3 m/s'
2430                hom(:,2,49,:) = SPREAD( zw, 2, statistic_regions+1 )
2431             ENDIF
2432
2433          CASE ( 'ws' )
2434             IF ( .NOT. passive_scalar ) THEN
2435                message_string = 'data_output_pr = ' // &
2436                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2437                                 'lemented for passive_scalar = .FALSE.'
2438                CALL message( 'check_parameters', 'PA0093', 1, 2, 0, 6, 0 )
2439             ELSE
2440                dopr_index(i) = 50
2441                dopr_unit(i)  = 'kg/m3 m/s'
2442                hom(:,2,50,:) = SPREAD( zw, 2, statistic_regions+1 )
2443             ENDIF
2444
2445          CASE ( 'w"qv"' )
2446             IF ( humidity  .AND.  .NOT. cloud_physics ) &
2447             THEN
2448                dopr_index(i) = 48
2449                dopr_unit(i)  = 'kg/kg m/s'
2450                hom(:,2,48,:) = SPREAD( zw, 2, statistic_regions+1 )
2451             ELSEIF( humidity .AND. cloud_physics ) THEN
2452                dopr_index(i) = 51
2453                dopr_unit(i)  = 'kg/kg m/s'
2454                hom(:,2,51,:) = SPREAD( zw, 2, statistic_regions+1 )
2455             ELSE
2456                message_string = 'data_output_pr = ' // &
2457                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2458                                 'lemented for cloud_physics = .FALSE. an&' // &
2459                                 'd humidity = .FALSE.'
2460                CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
2461             ENDIF
2462
2463          CASE ( 'w*qv*' )
2464             IF ( humidity  .AND.  .NOT. cloud_physics ) &
2465             THEN
2466                dopr_index(i) = 49
2467                dopr_unit(i)  = 'kg/kg m/s'
2468                hom(:,2,49,:) = SPREAD( zw, 2, statistic_regions+1 )
2469             ELSEIF( humidity .AND. cloud_physics ) THEN
2470                dopr_index(i) = 52
2471                dopr_unit(i)  = 'kg/kg m/s'
2472                hom(:,2,52,:) = SPREAD( zw, 2, statistic_regions+1 )
2473             ELSE
2474                message_string = 'data_output_pr = ' // &
2475                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2476                                 'lemented for cloud_physics = .FALSE. an&' // &
2477                                 'd humidity = .FALSE.'
2478                CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
2479             ENDIF
2480
2481          CASE ( 'wqv' )
2482             IF ( humidity  .AND.  .NOT. cloud_physics ) &
2483             THEN
2484                dopr_index(i) = 50
2485                dopr_unit(i)  = 'kg/kg m/s'
2486                hom(:,2,50,:) = SPREAD( zw, 2, statistic_regions+1 )
2487             ELSEIF( humidity .AND. cloud_physics ) THEN
2488                dopr_index(i) = 53
2489                dopr_unit(i)  = 'kg/kg m/s'
2490                hom(:,2,53,:) = SPREAD( zw, 2, statistic_regions+1 )
2491             ELSE
2492                message_string = 'data_output_pr = ' //                        &
2493                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2494                                 'lemented for cloud_physics = .FALSE. an&' // &
2495                                 'd humidity = .FALSE.'
2496                CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
2497             ENDIF
2498
2499          CASE ( 'ql' )
2500             IF ( .NOT. cloud_physics  .AND.  .NOT. cloud_droplets )  THEN
2501                message_string = 'data_output_pr = ' //                        &
2502                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2503                                 'lemented for cloud_physics = .FALSE. or'  // &
2504                                 '&cloud_droplets = .FALSE.'
2505                CALL message( 'check_parameters', 'PA0096', 1, 2, 0, 6, 0 )
2506             ELSE
2507                dopr_index(i) = 54
2508                dopr_unit(i)  = 'kg/kg'
2509                hom(:,2,54,:)  = SPREAD( zu, 2, statistic_regions+1 )
2510             ENDIF
2511
2512          CASE ( 'w*u*u*:dz' )
2513             dopr_index(i) = 55
2514             dopr_unit(i)  = 'm2/s3'
2515             hom(:,2,55,:) = SPREAD( zu, 2, statistic_regions+1 )
2516
2517          CASE ( 'w*p*:dz' )
2518             dopr_index(i) = 56
2519             dopr_unit(i)  = 'm2/s3'
2520             hom(:,2,56,:) = SPREAD( zw, 2, statistic_regions+1 )
2521
2522          CASE ( 'w"e:dz' )
2523             dopr_index(i) = 57
2524             dopr_unit(i)  = 'm2/s3'
2525             hom(:,2,57,:) = SPREAD( zu, 2, statistic_regions+1 )
2526
2527
2528          CASE ( 'u"pt"' )
2529             dopr_index(i) = 58
2530             dopr_unit(i)  = 'K m/s'
2531             hom(:,2,58,:) = SPREAD( zu, 2, statistic_regions+1 )
2532
2533          CASE ( 'u*pt*' )
2534             dopr_index(i) = 59
2535             dopr_unit(i)  = 'K m/s'
2536             hom(:,2,59,:) = SPREAD( zu, 2, statistic_regions+1 )
2537
2538          CASE ( 'upt_t' )
2539             dopr_index(i) = 60
2540             dopr_unit(i)  = 'K m/s'
2541             hom(:,2,60,:) = SPREAD( zu, 2, statistic_regions+1 )
2542
2543          CASE ( 'v"pt"' )
2544             dopr_index(i) = 61
2545             dopr_unit(i)  = 'K m/s'
2546             hom(:,2,61,:) = SPREAD( zu, 2, statistic_regions+1 )
2547             
2548          CASE ( 'v*pt*' )
2549             dopr_index(i) = 62
2550             dopr_unit(i)  = 'K m/s'
2551             hom(:,2,62,:) = SPREAD( zu, 2, statistic_regions+1 )
2552
2553          CASE ( 'vpt_t' )
2554             dopr_index(i) = 63
2555             dopr_unit(i)  = 'K m/s'
2556             hom(:,2,63,:) = SPREAD( zu, 2, statistic_regions+1 )
2557
2558          CASE ( 'rho' )
2559             IF ( .NOT. ocean ) THEN
2560                message_string = 'data_output_pr = ' //                        &
2561                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2562                                 'lemented for ocean = .FALSE.'
2563                CALL message( 'check_parameters', 'PA0091', 1, 2, 0, 6, 0 )
2564             ELSE
2565                dopr_index(i) = 64
2566                dopr_unit(i)  = 'kg/m3'
2567                hom(:,2,64,:) = SPREAD( zu, 2, statistic_regions+1 )
2568                IF ( data_output_pr(i)(1:1) == '#' )  THEN
2569                   dopr_initial_index(i) = 77
2570                   hom(:,2,77,:)         = SPREAD( zu, 2, statistic_regions+1 )
2571                   hom(nzb,2,77,:)       = 0.0_wp    ! because zu(nzb) is negative
2572                   data_output_pr(i)     = data_output_pr(i)(2:)
2573                ENDIF
2574             ENDIF
2575
2576          CASE ( 'w"sa"' )
2577             IF ( .NOT. ocean ) THEN
2578                message_string = 'data_output_pr = ' //                        &
2579                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2580                                 'lemented for ocean = .FALSE.'
2581                CALL message( 'check_parameters', 'PA0091', 1, 2, 0, 6, 0 )
2582             ELSE
2583                dopr_index(i) = 65
2584                dopr_unit(i)  = 'psu m/s'
2585                hom(:,2,65,:) = SPREAD( zw, 2, statistic_regions+1 )
2586             ENDIF
2587
2588          CASE ( 'w*sa*' )
2589             IF ( .NOT. ocean ) THEN
2590                message_string = 'data_output_pr = ' //                        &
2591                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2592                                 'lemented for ocean = .FALSE.'
2593                CALL message( 'check_parameters', 'PA0091', 1, 2, 0, 6, 0 )
2594             ELSE
2595                dopr_index(i) = 66
2596                dopr_unit(i)  = 'psu m/s'
2597                hom(:,2,66,:) = SPREAD( zw, 2, statistic_regions+1 )
2598             ENDIF
2599
2600          CASE ( 'wsa' )
2601             IF ( .NOT. ocean ) THEN
2602                message_string = 'data_output_pr = ' //                        &
2603                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2604                                 'lemented for ocean = .FALSE.'
2605                CALL message( 'check_parameters', 'PA0091', 1, 2, 0, 6, 0 )
2606             ELSE
2607                dopr_index(i) = 67
2608                dopr_unit(i)  = 'psu m/s'
2609                hom(:,2,67,:) = SPREAD( zw, 2, statistic_regions+1 )
2610             ENDIF
2611
2612          CASE ( 'w*p*' )
2613             dopr_index(i) = 68
2614             dopr_unit(i)  = 'm3/s3'
2615             hom(:,2,68,:) = SPREAD( zu, 2, statistic_regions+1 )
2616
2617          CASE ( 'w"e' )
2618             dopr_index(i) = 69
2619             dopr_unit(i)  = 'm3/s3'
2620             hom(:,2,69,:) = SPREAD( zu, 2, statistic_regions+1 )
2621
2622          CASE ( 'q*2' )
2623             IF ( .NOT. humidity )  THEN
2624                message_string = 'data_output_pr = ' //                        &
2625                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2626                                 'lemented for humidity = .FALSE.'
2627                CALL message( 'check_parameters', 'PA0092', 1, 2, 0, 6, 0 )
2628             ELSE
2629                dopr_index(i) = 70
2630                dopr_unit(i)  = 'kg2/kg2'
2631                hom(:,2,70,:) = SPREAD( zu, 2, statistic_regions+1 )
2632             ENDIF
2633
2634          CASE ( 'prho' )
2635             IF ( .NOT. ocean ) THEN
2636                message_string = 'data_output_pr = ' //                        &
2637                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2638                                 'lemented for ocean = .FALSE.'
2639                CALL message( 'check_parameters', 'PA0091', 1, 2, 0, 6, 0 )
2640             ELSE
2641                dopr_index(i) = 71
2642                dopr_unit(i)  = 'kg/m3'
2643                hom(:,2,71,:) = SPREAD( zu, 2, statistic_regions+1 )
2644             ENDIF
2645
2646          CASE ( 'hyp' )
2647             dopr_index(i) = 72
2648             dopr_unit(i)  = 'dbar'
2649             hom(:,2,72,:) = SPREAD( zu, 2, statistic_regions+1 )
2650
2651          CASE ( 'nr' )
2652             IF ( .NOT. cloud_physics )  THEN
2653                message_string = 'data_output_pr = ' //                        &
2654                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2655                                 'lemented for cloud_physics = .FALSE.'
2656                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
2657             ELSEIF ( icloud_scheme /= 0 )  THEN
2658                message_string = 'data_output_pr = ' //                        &
2659                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2660                                 'lemented for cloud_scheme /= seifert_beheng'
2661                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
2662             ELSEIF ( .NOT. precipitation )  THEN
2663                message_string = 'data_output_pr = ' //                        &
2664                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2665                                 'lemented for precipitation = .FALSE.'
2666                CALL message( 'check_parameters', 'PA0361', 1, 2, 0, 6, 0 )
2667             ELSE
2668                dopr_index(i) = 73
2669                dopr_unit(i)  = '1/m3'
2670                hom(:,2,73,:)  = SPREAD( zu, 2, statistic_regions+1 )
2671             ENDIF
2672
2673          CASE ( 'qr' )
2674             IF ( .NOT. cloud_physics )  THEN
2675                message_string = 'data_output_pr = ' //                        &
2676                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2677                                 'lemented for cloud_physics = .FALSE.'
2678                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
2679             ELSEIF ( icloud_scheme /= 0 )  THEN
2680                message_string = 'data_output_pr = ' //                        &
2681                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2682                                 'lemented for cloud_scheme /= seifert_beheng'
2683                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
2684             ELSEIF ( .NOT. precipitation )  THEN
2685                message_string = 'data_output_pr = ' //                        &
2686                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2687                                 'lemented for precipitation = .FALSE.'
2688                CALL message( 'check_parameters', 'PA0361', 1, 2, 0, 6, 0 )
2689             ELSE
2690                dopr_index(i) = 74
2691                dopr_unit(i)  = 'kg/kg'
2692                hom(:,2,74,:)  = SPREAD( zu, 2, statistic_regions+1 )
2693             ENDIF
2694
2695          CASE ( 'qc' )
2696             IF ( .NOT. cloud_physics )  THEN
2697                message_string = 'data_output_pr = ' //                        &
2698                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2699                                 'lemented for cloud_physics = .FALSE.'
2700                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
2701             ELSEIF ( icloud_scheme /= 0 )  THEN
2702                message_string = 'data_output_pr = ' //                        &
2703                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2704                                 'lemented for cloud_scheme /= seifert_beheng'
2705                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
2706             ELSE
2707                dopr_index(i) = 75
2708                dopr_unit(i)  = 'kg/kg'
2709                hom(:,2,75,:)  = SPREAD( zu, 2, statistic_regions+1 )
2710             ENDIF
2711
2712          CASE ( 'prr' )
2713             IF ( .NOT. cloud_physics )  THEN
2714                message_string = 'data_output_pr = ' //                        &
2715                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2716                                 'lemented for cloud_physics = .FALSE.'
2717                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
2718             ELSEIF ( icloud_scheme /= 0 )  THEN
2719                message_string = 'data_output_pr = ' //                        &
2720                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2721                                 'lemented for cloud_scheme /= seifert_beheng'
2722                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
2723             ELSEIF ( .NOT. precipitation )  THEN
2724                message_string = 'data_output_pr = ' //                        &
2725                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2726                                 'lemented for precipitation = .FALSE.'
2727                CALL message( 'check_parameters', 'PA0361', 1, 2, 0, 6, 0 )
2728
2729             ELSE
2730                dopr_index(i) = 76
2731                dopr_unit(i)  = 'kg/kg m/s'
2732                hom(:,2,76,:)  = SPREAD( zu, 2, statistic_regions+1 )
2733             ENDIF
2734
2735          CASE ( 'ug' )
2736             dopr_index(i) = 78
2737             dopr_unit(i)  = 'm/s'
2738             hom(:,2,78,:) = SPREAD( zu, 2, statistic_regions+1 )
2739
2740          CASE ( 'vg' )
2741             dopr_index(i) = 79
2742             dopr_unit(i)  = 'm/s'
2743             hom(:,2,79,:) = SPREAD( zu, 2, statistic_regions+1 )
2744
2745          CASE ( 'w_subs' )
2746             IF ( .NOT. large_scale_subsidence )  THEN
2747                message_string = 'data_output_pr = ' //                        &
2748                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2749                                 'lemented for large_scale_subsidence = .FALSE.'
2750                CALL message( 'check_parameters', 'PA0382', 1, 2, 0, 6, 0 )
2751             ELSE
2752                dopr_index(i) = 80
2753                dopr_unit(i)  = 'm/s'
2754                hom(:,2,80,:) = SPREAD( zu, 2, statistic_regions+1 )
2755             ENDIF
2756
2757          CASE ( 'td_lsa_lpt' )
2758             IF ( .NOT. large_scale_forcing )  THEN
2759                message_string = 'data_output_pr = ' //                        &
2760                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2761                                 'lemented for large_scale_forcing = .FALSE.'
2762                CALL message( 'check_parameters', 'PA0393', 1, 2, 0, 6, 0 )
2763             ELSE
2764                dopr_index(i) = 81
2765                dopr_unit(i)  = 'K/s'
2766                hom(:,2,81,:) = SPREAD( zu, 2, statistic_regions+1 )
2767             ENDIF
2768
2769          CASE ( 'td_lsa_q' )
2770             IF ( .NOT. large_scale_forcing )  THEN
2771                message_string = 'data_output_pr = ' //                        &
2772                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2773                                 'lemented for large_scale_forcing = .FALSE.'
2774                CALL message( 'check_parameters', 'PA0393', 1, 2, 0, 6, 0 )
2775             ELSE
2776                dopr_index(i) = 82
2777                dopr_unit(i)  = 'kg/kgs'
2778                hom(:,2,82,:) = SPREAD( zu, 2, statistic_regions+1 )
2779             ENDIF
2780
2781          CASE ( 'td_sub_lpt' )
2782             IF ( .NOT. large_scale_forcing )  THEN
2783                message_string = 'data_output_pr = ' //                        &
2784                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2785                                 'lemented for large_scale_forcing = .FALSE.'
2786                CALL message( 'check_parameters', 'PA0393', 1, 2, 0, 6, 0 )
2787             ELSE
2788                dopr_index(i) = 83
2789                dopr_unit(i)  = 'K/s'
2790                hom(:,2,83,:) = SPREAD( zu, 2, statistic_regions+1 )
2791             ENDIF
2792
2793          CASE ( 'td_sub_q' )
2794             IF ( .NOT. large_scale_forcing )  THEN
2795                message_string = 'data_output_pr = ' //                        &
2796                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2797                                 'lemented for large_scale_forcing = .FALSE.'
2798                CALL message( 'check_parameters', 'PA0393', 1, 2, 0, 6, 0 )
2799             ELSE
2800                dopr_index(i) = 84
2801                dopr_unit(i)  = 'kg/kgs'
2802                hom(:,2,84,:) = SPREAD( zu, 2, statistic_regions+1 )
2803             ENDIF
2804
2805          CASE ( 'td_nud_lpt' )
2806             IF ( .NOT. nudging )  THEN
2807                message_string = 'data_output_pr = ' //                        &
2808                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2809                                 'lemented for nudging = .FALSE.'
2810                CALL message( 'check_parameters', 'PA0394', 1, 2, 0, 6, 0 )
2811             ELSE
2812                dopr_index(i) = 85
2813                dopr_unit(i)  = 'K/s'
2814                hom(:,2,85,:) = SPREAD( zu, 2, statistic_regions+1 )
2815             ENDIF
2816
2817          CASE ( 'td_nud_q' )
2818             IF ( .NOT. nudging )  THEN
2819                message_string = 'data_output_pr = ' //                        &
2820                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2821                                 'lemented for nudging = .FALSE.'
2822                CALL message( 'check_parameters', 'PA0394', 1, 2, 0, 6, 0 )
2823             ELSE
2824                dopr_index(i) = 86
2825                dopr_unit(i)  = 'kg/kgs'
2826                hom(:,2,86,:) = SPREAD( zu, 2, statistic_regions+1 )
2827             ENDIF
2828
2829          CASE ( 'td_nud_u' )
2830             IF ( .NOT. nudging )  THEN
2831                message_string = 'data_output_pr = ' //                        &
2832                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2833                                 'lemented for nudging = .FALSE.'
2834                CALL message( 'check_parameters', 'PA0394', 1, 2, 0, 6, 0 )
2835             ELSE
2836                dopr_index(i) = 87
2837                dopr_unit(i)  = 'm/s2'
2838                hom(:,2,87,:) = SPREAD( zu, 2, statistic_regions+1 )
2839             ENDIF
2840
2841          CASE ( 'td_nud_v' )
2842             IF ( .NOT. nudging )  THEN
2843                message_string = 'data_output_pr = ' //                        &
2844                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
2845                                 'lemented for nudging = .FALSE.'
2846                CALL message( 'check_parameters', 'PA0394', 1, 2, 0, 6, 0 )
2847             ELSE
2848                dopr_index(i) = 88
2849                dopr_unit(i)  = 'm/s2'
2850                hom(:,2,88,:) = SPREAD( zu, 2, statistic_regions+1 )
2851             ENDIF
2852
2853
2854          CASE DEFAULT
2855
2856             CALL user_check_data_output_pr( data_output_pr(i), i, unit )
2857
2858             IF ( unit == 'illegal' )  THEN
2859                IF ( data_output_pr_user(1) /= ' ' )  THEN
2860                   message_string = 'illegal value for data_output_pr or ' //  &
2861                                    'data_output_pr_user = "' //               &
2862                                    TRIM( data_output_pr(i) ) // '"'
2863                   CALL message( 'check_parameters', 'PA0097', 1, 2, 0, 6, 0 )
2864                ELSE
2865                   message_string = 'illegal value for data_output_pr = "' //  &
2866                                    TRIM( data_output_pr(i) ) // '"'
2867                   CALL message( 'check_parameters', 'PA0098', 1, 2, 0, 6, 0 )
2868                ENDIF
2869             ENDIF
2870
2871       END SELECT
2872
2873    ENDDO
2874
2875
2876!
2877!-- Append user-defined data output variables to the standard data output
2878    IF ( data_output_user(1) /= ' ' )  THEN
2879       i = 1
2880       DO  WHILE ( data_output(i) /= ' '  .AND.  i <= 100 )
2881          i = i + 1
2882       ENDDO
2883       j = 1
2884       DO  WHILE ( data_output_user(j) /= ' '  .AND.  j <= 100 )
2885          IF ( i > 100 )  THEN
2886             message_string = 'number of output quantitities given by data' // &
2887                '_output and data_output_user exceeds the limit of 100'
2888             CALL message( 'check_parameters', 'PA0102', 1, 2, 0, 6, 0 )
2889          ENDIF
2890          data_output(i) = data_output_user(j)
2891          i = i + 1
2892          j = j + 1
2893       ENDDO
2894    ENDIF
2895
2896!
2897!-- Check and set steering parameters for 2d/3d data output and averaging
2898    i   = 1
2899    DO  WHILE ( data_output(i) /= ' '  .AND.  i <= 100 )
2900!
2901!--    Check for data averaging
2902       ilen = LEN_TRIM( data_output(i) )
2903       j = 0                                                 ! no data averaging
2904       IF ( ilen > 3 )  THEN
2905          IF ( data_output(i)(ilen-2:ilen) == '_av' )  THEN
2906             j = 1                                           ! data averaging
2907             data_output(i) = data_output(i)(1:ilen-3)
2908          ENDIF
2909       ENDIF
2910!
2911!--    Check for cross section or volume data
2912       ilen = LEN_TRIM( data_output(i) )
2913       k = 0                                                   ! 3d data
2914       var = data_output(i)(1:ilen)
2915       IF ( ilen > 3 )  THEN
2916          IF ( data_output(i)(ilen-2:ilen) == '_xy'  .OR.                      &
2917               data_output(i)(ilen-2:ilen) == '_xz'  .OR.                      &
2918               data_output(i)(ilen-2:ilen) == '_yz' )  THEN
2919             k = 1                                             ! 2d data
2920             var = data_output(i)(1:ilen-3)
2921          ENDIF
2922       ENDIF
2923!
2924!--    Check for allowed value and set units
2925       SELECT CASE ( TRIM( var ) )
2926
2927          CASE ( 'e' )
2928             IF ( constant_diffusion )  THEN
2929                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2930                                 'res constant_diffusion = .FALSE.'
2931                CALL message( 'check_parameters', 'PA0103', 1, 2, 0, 6, 0 )
2932             ENDIF
2933             unit = 'm2/s2'
2934
2935          CASE ( 'lpt' )
2936             IF ( .NOT. cloud_physics )  THEN
2937                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2938                         'res cloud_physics = .TRUE.'
2939                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
2940             ENDIF
2941             unit = 'K'
2942
2943          CASE ( 'nr' )
2944             IF ( .NOT. cloud_physics )  THEN
2945                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2946                         'res cloud_physics = .TRUE.'
2947                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
2948             ELSEIF ( icloud_scheme /= 0 )  THEN
2949                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2950                         'res cloud_scheme = seifert_beheng'
2951                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
2952             ENDIF
2953             unit = '1/m3'
2954
2955          CASE ( 'pc', 'pr' )
2956             IF ( .NOT. particle_advection )  THEN
2957                message_string = 'output of "' // TRIM( var ) // '" requir' // &
2958                   'es a "particles_par"-NAMELIST in the parameter file (PARIN)'
2959                CALL message( 'check_parameters', 'PA0104', 1, 2, 0, 6, 0 )
2960             ENDIF
2961             IF ( TRIM( var ) == 'pc' )  unit = 'number'
2962             IF ( TRIM( var ) == 'pr' )  unit = 'm'
2963
2964          CASE ( 'prr' )
2965             IF ( .NOT. cloud_physics )  THEN
2966                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2967                         'res cloud_physics = .TRUE.'
2968                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
2969             ELSEIF ( icloud_scheme /= 0 )  THEN
2970                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2971                         'res cloud_scheme = seifert_beheng'
2972                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
2973             ELSEIF ( .NOT. precipitation )  THEN
2974                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2975                                 'res precipitation = .TRUE.'
2976                CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 )
2977             ENDIF
2978             unit = 'kg/kg m/s'
2979
2980          CASE ( 'q', 'vpt' )
2981             IF ( .NOT. humidity )  THEN
2982                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2983                                 'res humidity = .TRUE.'
2984                CALL message( 'check_parameters', 'PA0105', 1, 2, 0, 6, 0 )
2985             ENDIF
2986             IF ( TRIM( var ) == 'q'   )  unit = 'kg/kg'
2987             IF ( TRIM( var ) == 'vpt' )  unit = 'K'
2988
2989          CASE ( 'qc' )
2990             IF ( .NOT. cloud_physics )  THEN
2991                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2992                         'res cloud_physics = .TRUE.'
2993                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
2994             ELSEIF ( icloud_scheme /= 0 ) THEN
2995                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
2996                         'res cloud_scheme = seifert_beheng'
2997                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
2998             ENDIF
2999             unit = 'kg/kg'
3000
3001          CASE ( 'ql' )
3002             IF ( .NOT. ( cloud_physics  .OR.  cloud_droplets ) )  THEN
3003                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3004                         'res cloud_physics = .TRUE. or cloud_droplets = .TRUE.'
3005                CALL message( 'check_parameters', 'PA0106', 1, 2, 0, 6, 0 )
3006             ENDIF
3007             unit = 'kg/kg'
3008
3009          CASE ( 'ql_c', 'ql_v', 'ql_vp' )
3010             IF ( .NOT. cloud_droplets )  THEN
3011                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3012                                 'res cloud_droplets = .TRUE.'
3013                CALL message( 'check_parameters', 'PA0107', 1, 2, 0, 6, 0 )
3014             ENDIF
3015             IF ( TRIM( var ) == 'ql_c'  )  unit = 'kg/kg'
3016             IF ( TRIM( var ) == 'ql_v'  )  unit = 'm3'
3017             IF ( TRIM( var ) == 'ql_vp' )  unit = 'none'
3018
3019          CASE ( 'qr' )
3020             IF ( .NOT. cloud_physics )  THEN
3021                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3022                         'res cloud_physics = .TRUE.'
3023                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
3024             ELSEIF ( icloud_scheme /= 0 ) THEN
3025                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3026                         'res cloud_scheme = seifert_beheng'
3027                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
3028             ELSEIF ( .NOT. precipitation )  THEN
3029                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3030                                 'res precipitation = .TRUE.'
3031                CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 )
3032             ENDIF
3033             unit = 'kg/kg'
3034
3035          CASE ( 'qv' )
3036             IF ( .NOT. cloud_physics )  THEN
3037                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3038                                 'res cloud_physics = .TRUE.'
3039                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
3040             ENDIF
3041             unit = 'kg/kg'
3042
3043          CASE ( 'rho' )
3044             IF ( .NOT. ocean )  THEN
3045                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3046                                 'res ocean = .TRUE.'
3047                CALL message( 'check_parameters', 'PA0109', 1, 2, 0, 6, 0 )
3048             ENDIF
3049             unit = 'kg/m3'
3050
3051          CASE ( 's' )
3052             IF ( .NOT. passive_scalar )  THEN
3053                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3054                                 'res passive_scalar = .TRUE.'
3055                CALL message( 'check_parameters', 'PA0110', 1, 2, 0, 6, 0 )
3056             ENDIF
3057             unit = 'conc'
3058
3059          CASE ( 'sa' )
3060             IF ( .NOT. ocean )  THEN
3061                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3062                                 'res ocean = .TRUE.'
3063                CALL message( 'check_parameters', 'PA0109', 1, 2, 0, 6, 0 )
3064             ENDIF
3065             unit = 'psu'
3066
3067          CASE ( 'u*', 't*', 'lwp*', 'pra*', 'prr*', 'qsws*', 'shf*', 'z0*', 'z0h*' )
3068             IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
3069                message_string = 'illegal value for data_output: "' //         &
3070                                 TRIM( var ) // '" & only 2d-horizontal ' //   &
3071                                 'cross sections are allowed for this value'
3072                CALL message( 'check_parameters', 'PA0111', 1, 2, 0, 6, 0 )
3073             ENDIF
3074             IF ( TRIM( var ) == 'lwp*'  .AND.  .NOT. cloud_physics )  THEN
3075                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3076                                 'res cloud_physics = .TRUE.'
3077                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
3078             ENDIF
3079             IF ( TRIM( var ) == 'pra*'  .AND.  .NOT. precipitation )  THEN
3080                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3081                                 'res precipitation = .TRUE.'
3082                CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 )
3083             ENDIF
3084             IF ( TRIM( var ) == 'pra*'  .AND.  j == 1 )  THEN
3085                message_string = 'temporal averaging of precipitation ' //     &
3086                          'amount "' // TRIM( var ) // '" is not possible'
3087                CALL message( 'check_parameters', 'PA0113', 1, 2, 0, 6, 0 )
3088             ENDIF
3089             IF ( TRIM( var ) == 'prr*'  .AND.  .NOT. precipitation )  THEN
3090                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3091                                 'res precipitation = .TRUE.'
3092                CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 )
3093             ENDIF
3094             IF ( TRIM( var ) == 'qsws*'  .AND.  .NOT. humidity )  THEN
3095                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
3096                                 'res humidity = .TRUE.'
3097                CALL message( 'check_parameters', 'PA0322', 1, 2, 0, 6, 0 )
3098             ENDIF
3099
3100             IF ( TRIM( var ) == 'lwp*'   )  unit = 'kg/kg*m'
3101             IF ( TRIM( var ) == 'pra*'   )  unit = 'mm'
3102             IF ( TRIM( var ) == 'prr*'   )  unit = 'mm/s'
3103             IF ( TRIM( var ) == 'qsws*'  )  unit = 'kgm/kgs'
3104             IF ( TRIM( var ) == 'shf*'   )  unit = 'K*m/s'
3105             IF ( TRIM( var ) == 't*'     )  unit = 'K'
3106             IF ( TRIM( var ) == 'u*'     )  unit = 'm/s'
3107             IF ( TRIM( var ) == 'z0*'    )  unit = 'm'
3108             IF ( TRIM( var ) == 'z0h*'   )  unit = 'm'
3109
3110
3111          CASE ( 'p', 'pt', 'u', 'v', 'w' )
3112             IF ( TRIM( var ) == 'p'  )  unit = 'Pa'
3113             IF ( TRIM( var ) == 'pt' )  unit = 'K'
3114             IF ( TRIM( var ) == 'u'  )  unit = 'm/s'
3115             IF ( TRIM( var ) == 'v'  )  unit = 'm/s'
3116             IF ( TRIM( var ) == 'w'  )  unit = 'm/s'
3117             CONTINUE
3118
3119          CASE DEFAULT
3120             CALL user_check_data_output( var, unit )
3121
3122             IF ( unit == 'illegal' )  THEN
3123                IF ( data_output_user(1) /= ' ' )  THEN
3124                   message_string = 'illegal value for data_output or ' //     &
3125                         'data_output_user = "' // TRIM( data_output(i) ) // '"'
3126                   CALL message( 'check_parameters', 'PA0114', 1, 2, 0, 6, 0 )
3127                ELSE
3128                   message_string = 'illegal value for data_output =' //       &
3129                                    TRIM( data_output(i) ) // '"'
3130                   CALL message( 'check_parameters', 'PA0115', 1, 2, 0, 6, 0 )
3131                ENDIF
3132             ENDIF
3133
3134       END SELECT
3135!
3136!--    Set the internal steering parameters appropriately
3137       IF ( k == 0 )  THEN
3138          do3d_no(j)              = do3d_no(j) + 1
3139          do3d(j,do3d_no(j))      = data_output(i)
3140          do3d_unit(j,do3d_no(j)) = unit
3141       ELSE
3142          do2d_no(j)              = do2d_no(j) + 1
3143          do2d(j,do2d_no(j))      = data_output(i)
3144          do2d_unit(j,do2d_no(j)) = unit
3145          IF ( data_output(i)(ilen-2:ilen) == '_xy' )  THEN
3146             data_output_xy(j) = .TRUE.
3147          ENDIF
3148          IF ( data_output(i)(ilen-2:ilen) == '_xz' )  THEN
3149             data_output_xz(j) = .TRUE.
3150          ENDIF
3151          IF ( data_output(i)(ilen-2:ilen) == '_yz' )  THEN
3152             data_output_yz(j) = .TRUE.
3153          ENDIF
3154       ENDIF
3155
3156       IF ( j == 1 )  THEN
3157!
3158!--       Check, if variable is already subject to averaging
3159          found = .FALSE.
3160          DO  k = 1, doav_n
3161             IF ( TRIM( doav(k) ) == TRIM( var ) )  found = .TRUE.
3162          ENDDO
3163
3164          IF ( .NOT. found )  THEN
3165             doav_n = doav_n + 1
3166             doav(doav_n) = var
3167          ENDIF
3168       ENDIF
3169
3170       i = i + 1
3171    ENDDO
3172
3173!
3174!-- Averaged 2d or 3d output requires that an averaging interval has been set
3175    IF ( doav_n > 0  .AND.  averaging_interval == 0.0_wp )  THEN
3176       WRITE( message_string, * )  'output of averaged quantity "',            &
3177                                   TRIM( doav(1) ), '_av" requires to set a ', &
3178                                   'non-zero & averaging interval'
3179       CALL message( 'check_parameters', 'PA0323', 1, 2, 0, 6, 0 )
3180    ENDIF
3181
3182!
3183!-- Check sectional planes and store them in one shared array
3184    IF ( ANY( section_xy > nz + 1 ) )  THEN
3185       WRITE( message_string, * )  'section_xy must be <= nz + 1 = ', nz + 1
3186       CALL message( 'check_parameters', 'PA0319', 1, 2, 0, 6, 0 )
3187    ENDIF
3188    IF ( ANY( section_xz > ny + 1 ) )  THEN
3189       WRITE( message_string, * )  'section_xz must be <= ny + 1 = ', ny + 1
3190       CALL message( 'check_parameters', 'PA0320', 1, 2, 0, 6, 0 )
3191    ENDIF
3192    IF ( ANY( section_yz > nx + 1 ) )  THEN
3193       WRITE( message_string, * )  'section_yz must be <= nx + 1 = ', nx + 1
3194       CALL message( 'check_parameters', 'PA0321', 1, 2, 0, 6, 0 )
3195    ENDIF
3196    section(:,1) = section_xy
3197    section(:,2) = section_xz
3198    section(:,3) = section_yz
3199
3200!
3201!-- Upper plot limit for 2D vertical sections
3202    IF ( z_max_do2d == -1.0_wp )  z_max_do2d = zu(nzt)
3203    IF ( z_max_do2d < zu(nzb+1)  .OR.  z_max_do2d > zu(nzt) )  THEN
3204       WRITE( message_string, * )  'z_max_do2d = ', z_max_do2d,                &
3205                    ' must be >= ', zu(nzb+1), '(zu(nzb+1)) and <= ', zu(nzt), &
3206                    ' (zu(nzt))'
3207       CALL message( 'check_parameters', 'PA0116', 1, 2, 0, 6, 0 )
3208    ENDIF
3209
3210!
3211!-- Upper plot limit for 3D arrays
3212    IF ( nz_do3d == -9999 )  nz_do3d = nzt + 1
3213
3214!
3215!-- Set output format string (used in header)
3216    SELECT CASE ( netcdf_data_format )
3217       CASE ( 1 )
3218          output_format_netcdf = 'netCDF classic'
3219       CASE ( 2 )
3220          output_format_netcdf = 'netCDF 64bit offset'
3221       CASE ( 3 )
3222          output_format_netcdf = 'netCDF4/HDF5'
3223       CASE ( 4 )
3224          output_format_netcdf = 'netCDF4/HDF5 classic'
3225       CASE ( 5 )
3226          output_format_netcdf = 'parallel netCDF4/HDF5'
3227       CASE ( 6 )
3228          output_format_netcdf = 'parallel netCDF4/HDF5 classic'
3229
3230    END SELECT
3231
3232#if defined( __spectra )
3233!
3234!-- Check the number of spectra level to be output
3235    i = 1
3236    DO WHILE ( comp_spectra_level(i) /= 999999  .AND.  i <= 100 )
3237       i = i + 1
3238    ENDDO
3239    i = i - 1
3240    IF ( i == 0 )  THEN
3241       WRITE( message_string, * )  'no spectra levels given'
3242       CALL message( 'check_parameters', 'PA0019', 1, 2, 0, 6, 0 )
3243    ENDIF
3244#endif
3245
3246!
3247!-- Check mask conditions
3248    DO mid = 1, max_masks
3249       IF ( data_output_masks(mid,1) /= ' ' .OR.                               &
3250            data_output_masks_user(mid,1) /= ' ' ) THEN
3251          masks = masks + 1
3252       ENDIF
3253    ENDDO
3254   
3255    IF ( masks < 0 .OR. masks > max_masks )  THEN
3256       WRITE( message_string, * )  'illegal value: masks must be >= 0 and ',   &
3257            '<= ', max_masks, ' (=max_masks)'
3258       CALL message( 'check_parameters', 'PA0325', 1, 2, 0, 6, 0 )
3259    ENDIF
3260    IF ( masks > 0 )  THEN
3261       mask_scale(1) = mask_scale_x
3262       mask_scale(2) = mask_scale_y
3263       mask_scale(3) = mask_scale_z
3264       IF ( ANY( mask_scale <= 0.0_wp ) )  THEN
3265          WRITE( message_string, * )                                           &
3266               'illegal value: mask_scale_x, mask_scale_y and mask_scale_z',   &
3267               'must be > 0.0'
3268          CALL message( 'check_parameters', 'PA0326', 1, 2, 0, 6, 0 )
3269       ENDIF
3270!
3271!--    Generate masks for masked data output
3272!--    Parallel netcdf output is not tested so far for masked data, hence
3273!--    netcdf_data_format is switched back to non-paralell output.
3274       netcdf_data_format_save = netcdf_data_format
3275       IF ( netcdf_data_format > 4 )  THEN
3276          IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
3277          IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
3278          message_string = 'netCDF file formats '//                            &
3279                           '5 (parallel netCDF 4) and ' //                     &
3280                           '6 (parallel netCDF 4 Classic model) '//            &
3281                           '&are currently not supported (not yet tested) ' // &
3282                           'for masked data.&Using respective non-parallel' // & 
3283                           ' output for masked data.'
3284          CALL message( 'check_parameters', 'PA0383', 0, 0, 0, 6, 0 )
3285       ENDIF
3286       CALL init_masks
3287       netcdf_data_format = netcdf_data_format_save
3288    ENDIF
3289
3290!
3291!-- Check the NetCDF data format
3292#if ! defined ( __check )
3293    IF ( netcdf_data_format > 2 )  THEN
3294#if defined( __netcdf4 )
3295       CONTINUE
3296#else
3297       message_string = 'netCDF: netCDF4 format requested but no ' //          &
3298                        'cpp-directive __netcdf4 given & switch '  //          &
3299                        'back to 64-bit offset format'
3300       CALL message( 'check_parameters', 'PA0171', 0, 1, 0, 6, 0 )
3301       netcdf_data_format = 2
3302#endif
3303    ENDIF
3304    IF ( netcdf_data_format > 4 )  THEN
3305#if defined( __netcdf4 ) && defined( __netcdf4_parallel )
3306       CONTINUE
3307#else
3308       message_string = 'netCDF: netCDF4 parallel output requested but no ' // &
3309                        'cpp-directive __netcdf4_parallel given & switch '  // &
3310                        'back to netCDF4 non-parallel output'
3311       CALL message( 'check_parameters', 'PA0099', 0, 1, 0, 6, 0 )
3312       netcdf_data_format = netcdf_data_format - 2
3313#endif
3314    ENDIF
3315#endif
3316
3317!
3318!-- Calculate fixed number of output time levels for parallel netcdf output.
3319!-- The time dimension has to be defined as limited for parallel output,
3320!-- because otherwise the I/O performance drops significantly.
3321    IF ( netcdf_data_format > 4 )  THEN
3322
3323       ntdim_3d(0)    = INT( ( end_time - skip_time_do3d ) / dt_do3d )
3324       IF ( do3d_at_begin ) ntdim_3d(0) = ntdim_3d(0) + 1
3325       ntdim_3d(1)    = INT( ( end_time - skip_time_data_output_av )           &
3326                             / dt_data_output_av )
3327       ntdim_2d_xy(0) = INT( ( end_time - skip_time_do2d_xy ) / dt_do2d_xy )
3328       ntdim_2d_xz(0) = INT( ( end_time - skip_time_do2d_xz ) / dt_do2d_xz )
3329       ntdim_2d_yz(0) = INT( ( end_time - skip_time_do2d_yz ) / dt_do2d_yz )
3330       IF ( do2d_at_begin )  THEN
3331          ntdim_2d_xy(0) = ntdim_2d_xy(0) + 1
3332          ntdim_2d_xz(0) = ntdim_2d_xz(0) + 1
3333          ntdim_2d_yz(0) = ntdim_2d_yz(0) + 1
3334       ENDIF
3335       ntdim_2d_xy(1) = ntdim_3d(1)
3336       ntdim_2d_xz(1) = ntdim_3d(1)
3337       ntdim_2d_yz(1) = ntdim_3d(1)
3338
3339    ENDIF
3340
3341#if ! defined( __check )
3342!
3343!-- Check netcdf precison
3344    ldum = .FALSE.
3345    CALL define_netcdf_header( 'ch', ldum, 0 )
3346#endif
3347!
3348!-- Check, whether a constant diffusion coefficient shall be used
3349    IF ( km_constant /= -1.0_wp )  THEN
3350       IF ( km_constant < 0.0_wp )  THEN
3351          WRITE( message_string, * )  'km_constant = ', km_constant, ' < 0.0'
3352          CALL message( 'check_parameters', 'PA0121', 1, 2, 0, 6, 0 )
3353       ELSE
3354          IF ( prandtl_number < 0.0_wp )  THEN
3355             WRITE( message_string, * )  'prandtl_number = ', prandtl_number,  &
3356                                         ' < 0.0'
3357             CALL message( 'check_parameters', 'PA0122', 1, 2, 0, 6, 0 )
3358          ENDIF
3359          constant_diffusion = .TRUE.
3360
3361          IF ( prandtl_layer )  THEN
3362             message_string = 'prandtl_layer is not allowed with fixed ' //    &
3363                              'value of km'
3364             CALL message( 'check_parameters', 'PA0123', 1, 2, 0, 6, 0 )
3365          ENDIF
3366       ENDIF
3367    ENDIF
3368
3369!
3370!-- In case of non-cyclic lateral boundaries and a damping layer for the
3371!-- potential temperature, check the width of the damping layer
3372    IF ( bc_lr /= 'cyclic' ) THEN
3373       IF ( pt_damping_width < 0.0_wp  .OR.                                    &
3374            pt_damping_width > REAL( nx * dx ) )  THEN
3375          message_string = 'pt_damping_width out of range'
3376          CALL message( 'check_parameters', 'PA0124', 1, 2, 0, 6, 0 )
3377       ENDIF
3378    ENDIF
3379
3380    IF ( bc_ns /= 'cyclic' )  THEN
3381       IF ( pt_damping_width < 0.0_wp  .OR.                                    &
3382            pt_damping_width > REAL( ny * dy ) )  THEN
3383          message_string = 'pt_damping_width out of range'
3384          CALL message( 'check_parameters', 'PA0124', 1, 2, 0, 6, 0 )
3385       ENDIF
3386    ENDIF
3387
3388!
3389!-- Check value range for rif
3390    IF ( rif_min >= rif_max )  THEN
3391       WRITE( message_string, * )  'rif_min = ', rif_min, ' must be less ',    &
3392                                   'than rif_max = ', rif_max
3393       CALL message( 'check_parameters', 'PA0125', 1, 2, 0, 6, 0 )
3394    ENDIF
3395
3396!
3397!-- Check random generator
3398    IF ( (random_generator /= 'system-specific'     .AND.                      &
3399          random_generator /= 'random-parallel'   ) .AND.                      &
3400          random_generator /= 'numerical-recipes' )  THEN
3401       message_string = 'unknown random generator: random_generator = "' //    &
3402                        TRIM( random_generator ) // '"'
3403       CALL message( 'check_parameters', 'PA0135', 1, 2, 0, 6, 0 )
3404    ENDIF
3405
3406!
3407!-- Determine upper and lower hight level indices for random perturbations
3408    IF ( disturbance_level_b == -9999999.9_wp )  THEN
3409       IF ( ocean ) THEN
3410          disturbance_level_b     = zu((nzt*2)/3)
3411          disturbance_level_ind_b = ( nzt * 2 ) / 3
3412       ELSE
3413          disturbance_level_b     = zu(nzb+3)
3414          disturbance_level_ind_b = nzb + 3
3415       ENDIF
3416    ELSEIF ( disturbance_level_b < zu(3) )  THEN
3417       WRITE( message_string, * )  'disturbance_level_b = ',                   &
3418                           disturbance_level_b, ' must be >= ', zu(3), '(zu(3))'
3419       CALL message( 'check_parameters', 'PA0126', 1, 2, 0, 6, 0 )
3420    ELSEIF ( disturbance_level_b > zu(nzt-2) )  THEN
3421       WRITE( message_string, * )  'disturbance_level_b = ',                   &
3422                   disturbance_level_b, ' must be <= ', zu(nzt-2), '(zu(nzt-2))'
3423       CALL message( 'check_parameters', 'PA0127', 1, 2, 0, 6, 0 )
3424    ELSE
3425       DO  k = 3, nzt-2
3426          IF ( disturbance_level_b <= zu(k) )  THEN
3427             disturbance_level_ind_b = k
3428             EXIT
3429          ENDIF
3430       ENDDO
3431    ENDIF
3432
3433    IF ( disturbance_level_t == -9999999.9_wp )  THEN
3434       IF ( ocean )  THEN
3435          disturbance_level_t     = zu(nzt-3)
3436          disturbance_level_ind_t = nzt - 3
3437       ELSE
3438          disturbance_level_t     = zu(nzt/3)
3439          disturbance_level_ind_t = nzt / 3
3440       ENDIF
3441    ELSEIF ( disturbance_level_t > zu(nzt-2) )  THEN
3442       WRITE( message_string, * )  'disturbance_level_t = ',                   &
3443                   disturbance_level_t, ' must be <= ', zu(nzt-2), '(zu(nzt-2))'
3444       CALL message( 'check_parameters', 'PA0128', 1, 2, 0, 6, 0 )
3445    ELSEIF ( disturbance_level_t < disturbance_level_b )  THEN
3446       WRITE( message_string, * )  'disturbance_level_t = ',                   &
3447                   disturbance_level_t, ' must be >= disturbance_level_b = ',  &
3448                   disturbance_level_b
3449       CALL message( 'check_parameters', 'PA0129', 1, 2, 0, 6, 0 )
3450    ELSE
3451       DO  k = 3, nzt-2
3452          IF ( disturbance_level_t <= zu(k) )  THEN
3453             disturbance_level_ind_t = k
3454             EXIT
3455          ENDIF
3456       ENDDO
3457    ENDIF
3458
3459!
3460!-- Check again whether the levels determined this way are ok.
3461!-- Error may occur at automatic determination and too few grid points in
3462!-- z-direction.
3463    IF ( disturbance_level_ind_t < disturbance_level_ind_b )  THEN
3464       WRITE( message_string, * )  'disturbance_level_ind_t = ',               &
3465                disturbance_level_ind_t, ' must be >= disturbance_level_b = ', &
3466                disturbance_level_b
3467       CALL message( 'check_parameters', 'PA0130', 1, 2, 0, 6, 0 )
3468    ENDIF
3469
3470!
3471!-- Determine the horizontal index range for random perturbations.
3472!-- In case of non-cyclic horizontal boundaries, no perturbations are imposed
3473!-- near the inflow and the perturbation area is further limited to ...(1)
3474!-- after the initial phase of the flow.
3475   
3476    IF ( bc_lr /= 'cyclic' )  THEN
3477       IF ( inflow_disturbance_begin == -1 )  THEN
3478          inflow_disturbance_begin = MIN( 10, nx/2 )
3479       ENDIF
3480       IF ( inflow_disturbance_begin < 0  .OR.  inflow_disturbance_begin > nx )&
3481       THEN
3482          message_string = 'inflow_disturbance_begin out of range'
3483          CALL message( 'check_parameters', 'PA0131', 1, 2, 0, 6, 0 )
3484       ENDIF
3485       IF ( inflow_disturbance_end == -1 )  THEN
3486          inflow_disturbance_end = MIN( 100, 3*nx/4 )
3487       ENDIF
3488       IF ( inflow_disturbance_end < 0  .OR.  inflow_disturbance_end > nx )    &
3489       THEN
3490          message_string = 'inflow_disturbance_end out of range'
3491          CALL message( 'check_parameters', 'PA0132', 1, 2, 0, 6, 0 )
3492       ENDIF
3493    ELSEIF ( bc_ns /= 'cyclic' )  THEN
3494       IF ( inflow_disturbance_begin == -1 )  THEN
3495          inflow_disturbance_begin = MIN( 10, ny/2 )
3496       ENDIF
3497       IF ( inflow_disturbance_begin < 0  .OR.  inflow_disturbance_begin > ny )&
3498       THEN
3499          message_string = 'inflow_disturbance_begin out of range'
3500          CALL message( 'check_parameters', 'PA0131', 1, 2, 0, 6, 0 )
3501       ENDIF
3502       IF ( inflow_disturbance_end == -1 )  THEN
3503          inflow_disturbance_end = MIN( 100, 3*ny/4 )
3504       ENDIF
3505       IF ( inflow_disturbance_end < 0  .OR.  inflow_disturbance_end > ny )    &
3506       THEN
3507          message_string = 'inflow_disturbance_end out of range'
3508          CALL message( 'check_parameters', 'PA0132', 1, 2, 0, 6, 0 )
3509       ENDIF
3510    ENDIF
3511
3512    IF ( random_generator == 'random-parallel' )  THEN
3513       dist_nxl = nxl;  dist_nxr = nxr
3514       dist_nys = nys;  dist_nyn = nyn
3515       IF ( bc_lr == 'radiation/dirichlet' )  THEN
3516          dist_nxr    = MIN( nx - inflow_disturbance_begin, nxr )
3517          dist_nxl(1) = MAX( nx - inflow_disturbance_end, nxl )
3518       ELSEIF ( bc_lr == 'dirichlet/radiation' )  THEN
3519          dist_nxl    = MAX( inflow_disturbance_begin, nxl )
3520          dist_nxr(1) = MIN( inflow_disturbance_end, nxr )
3521       ENDIF
3522       IF ( bc_ns == 'dirichlet/radiation' )  THEN
3523          dist_nyn    = MIN( ny - inflow_disturbance_begin, nyn )
3524          dist_nys(1) = MAX( ny - inflow_disturbance_end, nys )
3525       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
3526          dist_nys    = MAX( inflow_disturbance_begin, nys )
3527          dist_nyn(1) = MIN( inflow_disturbance_end, nyn )
3528       ENDIF
3529    ELSE
3530       dist_nxl = 0;  dist_nxr = nx
3531       dist_nys = 0;  dist_nyn = ny
3532       IF ( bc_lr == 'radiation/dirichlet' )  THEN
3533          dist_nxr    = nx - inflow_disturbance_begin
3534          dist_nxl(1) = nx - inflow_disturbance_end
3535       ELSEIF ( bc_lr == 'dirichlet/radiation' )  THEN
3536          dist_nxl    = inflow_disturbance_begin
3537          dist_nxr(1) = inflow_disturbance_end
3538       ENDIF
3539       IF ( bc_ns == 'dirichlet/radiation' )  THEN
3540          dist_nyn    = ny - inflow_disturbance_begin
3541          dist_nys(1) = ny - inflow_disturbance_end
3542       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
3543          dist_nys    = inflow_disturbance_begin
3544          dist_nyn(1) = inflow_disturbance_end
3545       ENDIF
3546    ENDIF
3547
3548!
3549!-- A turbulent inflow requires Dirichlet conditions at the respective inflow
3550!-- boundary (so far, a turbulent inflow is realized from the left side only)
3551    IF ( turbulent_inflow  .AND.  bc_lr /= 'dirichlet/radiation' )  THEN
3552       message_string = 'turbulent_inflow = .T. requires a Dirichlet ' //      &
3553                        'condition at the inflow boundary'
3554       CALL message( 'check_parameters', 'PA0133', 1, 2, 0, 6, 0 )
3555    ENDIF
3556
3557!
3558!-- Turbulent inflow requires that 3d arrays have been cyclically filled with
3559!-- data from prerun in the first main run
3560    IF ( turbulent_inflow  .AND.  initializing_actions /= 'cyclic_fill'  .AND. &
3561         initializing_actions /= 'read_restart_data' )  THEN
3562       message_string = 'turbulent_inflow = .T. requires ' //                  &
3563                        'initializing_actions = ''cyclic_fill'' '
3564       CALL message( 'check_parameters', 'PA0055', 1, 2, 0, 6, 0 )
3565    ENDIF
3566
3567!
3568!-- In case of turbulent inflow calculate the index of the recycling plane
3569    IF ( turbulent_inflow )  THEN
3570       IF ( recycling_width == 9999999.9_wp )  THEN
3571!
3572!--       Set the default value for the width of the recycling domain
3573          recycling_width = 0.1_wp * nx * dx
3574       ELSE
3575          IF ( recycling_width < dx  .OR.  recycling_width > nx * dx )  THEN
3576             WRITE( message_string, * )  'illegal value for recycling_width:', &
3577                                         ' ', recycling_width
3578             CALL message( 'check_parameters', 'PA0134', 1, 2, 0, 6, 0 )
3579          ENDIF
3580       ENDIF
3581!
3582!--    Calculate the index
3583       recycling_plane = recycling_width / dx
3584    ENDIF
3585
3586!
3587!-- Determine damping level index for 1D model
3588    IF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
3589       IF ( damp_level_1d == -1.0_wp )  THEN
3590          damp_level_1d     = zu(nzt+1)
3591          damp_level_ind_1d = nzt + 1
3592       ELSEIF ( damp_level_1d < 0.0_wp  .OR.  damp_level_1d > zu(nzt+1) )  THEN
3593          WRITE( message_string, * )  'damp_level_1d = ', damp_level_1d,       &
3594                 ' must be > 0.0 and < ', zu(nzt+1), '(zu(nzt+1))'
3595          CALL message( 'check_parameters', 'PA0136', 1, 2, 0, 6, 0 )
3596       ELSE
3597          DO  k = 1, nzt+1
3598             IF ( damp_level_1d <= zu(k) )  THEN
3599                damp_level_ind_1d = k
3600                EXIT
3601             ENDIF
3602          ENDDO
3603       ENDIF
3604    ENDIF
3605
3606!
3607!-- Check some other 1d-model parameters
3608    IF ( TRIM( mixing_length_1d ) /= 'as_in_3d_model'  .AND.                   &
3609         TRIM( mixing_length_1d ) /= 'blackadar' )  THEN
3610       message_string = 'mixing_length_1d = "' // TRIM( mixing_length_1d ) //  &
3611                        '" is unknown'
3612       CALL message( 'check_parameters', 'PA0137', 1, 2, 0, 6, 0 )
3613    ENDIF
3614    IF ( TRIM( dissipation_1d ) /= 'as_in_3d_model'  .AND.                     &
3615         TRIM( dissipation_1d ) /= 'detering' )  THEN
3616       message_string = 'dissipation_1d = "' // TRIM( dissipation_1d ) //      &
3617                        '" is unknown'
3618       CALL message( 'check_parameters', 'PA0138', 1, 2, 0, 6, 0 )
3619    ENDIF
3620
3621!
3622!-- Set time for the next user defined restart (time_restart is the
3623!-- internal parameter for steering restart events)
3624    IF ( restart_time /= 9999999.9_wp )  THEN
3625       IF ( restart_time > time_since_reference_point )  THEN
3626          time_restart = restart_time
3627       ENDIF
3628    ELSE
3629!
3630!--    In case of a restart run, set internal parameter to default (no restart)
3631!--    if the NAMELIST-parameter restart_time is omitted
3632       time_restart = 9999999.9_wp
3633    ENDIF
3634
3635!
3636!-- Set default value of the time needed to terminate a model run
3637    IF ( termination_time_needed == -1.0_wp )  THEN
3638       IF ( host(1:3) == 'ibm' )  THEN
3639          termination_time_needed = 300.0_wp
3640       ELSE
3641          termination_time_needed = 35.0_wp
3642       ENDIF
3643    ENDIF
3644
3645!
3646!-- Check the time needed to terminate a model run
3647    IF ( host(1:3) == 't3e' )  THEN
3648!
3649!--    Time needed must be at least 30 seconds on all CRAY machines, because
3650!--    MPP_TREMAIN gives the remaining CPU time only in steps of 30 seconds
3651       IF ( termination_time_needed <= 30.0_wp )  THEN
3652          WRITE( message_string, * )  'termination_time_needed = ',            &
3653                 termination_time_needed, ' must be > 30.0 on host "',         &
3654                 TRIM( host ), '"'
3655          CALL message( 'check_parameters', 'PA0139', 1, 2, 0, 6, 0 )
3656       ENDIF
3657    ELSEIF ( host(1:3) == 'ibm' )  THEN
3658!
3659!--    On IBM-regatta machines the time should be at least 300 seconds,
3660!--    because the job time consumed before executing palm (for compiling,
3661!--    copying of files, etc.) has to be regarded
3662       IF ( termination_time_needed < 300.0_wp )  THEN
3663          WRITE( message_string, * )  'termination_time_needed = ',            &
3664                 termination_time_needed, ' should be >= 300.0 on host "',     &
3665                 TRIM( host ), '"'
3666          CALL message( 'check_parameters', 'PA0140', 1, 2, 0, 6, 0 )
3667       ENDIF
3668    ENDIF
3669
3670!
3671!-- Check pressure gradient conditions
3672    IF ( dp_external .AND. conserve_volume_flow )  THEN
3673       WRITE( message_string, * )  'Both dp_external and conserve_volume_flo', &
3674            'w are .TRUE. but one of them must be .FALSE.'
3675       CALL message( 'check_parameters', 'PA0150', 1, 2, 0, 6, 0 )
3676    ENDIF
3677    IF ( dp_external )  THEN
3678       IF ( dp_level_b < zu(nzb) .OR. dp_level_b > zu(nzt) )  THEN
3679          WRITE( message_string, * )  'dp_level_b = ', dp_level_b, ' is out ', &
3680               ' of range'
3681          CALL message( 'check_parameters', 'PA0151', 1, 2, 0, 6, 0 )
3682       ENDIF
3683       IF ( .NOT. ANY( dpdxy /= 0.0_wp ) )  THEN
3684          WRITE( message_string, * )  'dp_external is .TRUE. but dpdxy is ze', &
3685               'ro, i.e. the external pressure gradient & will not be applied'
3686          CALL message( 'check_parameters', 'PA0152', 0, 1, 0, 6, 0 )
3687       ENDIF
3688    ENDIF
3689    IF ( ANY( dpdxy /= 0.0_wp ) .AND. .NOT. dp_external )  THEN
3690       WRITE( message_string, * )  'dpdxy is nonzero but dp_external is ',     &
3691            '.FALSE., i.e. the external pressure gradient & will not be applied'
3692       CALL message( 'check_parameters', 'PA0153', 0, 1, 0, 6, 0 )
3693    ENDIF
3694    IF ( conserve_volume_flow )  THEN
3695       IF ( TRIM( conserve_volume_flow_mode ) == 'default' )  THEN
3696
3697          conserve_volume_flow_mode = 'initial_profiles'
3698
3699       ELSEIF ( TRIM( conserve_volume_flow_mode ) /= 'initial_profiles' .AND.  &
3700            TRIM( conserve_volume_flow_mode ) /= 'inflow_profile' .AND.        &
3701            TRIM( conserve_volume_flow_mode ) /= 'bulk_velocity' )  THEN
3702          WRITE( message_string, * )  'unknown conserve_volume_flow_mode: ',   &
3703               conserve_volume_flow_mode
3704          CALL message( 'check_parameters', 'PA0154', 1, 2, 0, 6, 0 )
3705       ENDIF
3706       IF ( (bc_lr /= 'cyclic'  .OR.  bc_ns /= 'cyclic')  .AND.                &
3707          TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' )  THEN
3708          WRITE( message_string, * )  'non-cyclic boundary conditions ',       &
3709               'require  conserve_volume_flow_mode = ''initial_profiles'''
3710          CALL message( 'check_parameters', 'PA0155', 1, 2, 0, 6, 0 )
3711       ENDIF
3712       IF ( bc_lr == 'cyclic'  .AND.  bc_ns == 'cyclic'  .AND.                 &
3713            TRIM( conserve_volume_flow_mode ) == 'inflow_profile' )  THEN
3714          WRITE( message_string, * )  'cyclic boundary conditions ',           &
3715               'require conserve_volume_flow_mode = ''initial_profiles''',     &
3716               ' or ''bulk_velocity'''
3717          CALL message( 'check_parameters', 'PA0156', 1, 2, 0, 6, 0 )
3718       ENDIF
3719    ENDIF
3720    IF ( ( u_bulk /= 0.0_wp .OR. v_bulk /= 0.0_wp ) .AND.                      &
3721         ( .NOT. conserve_volume_flow .OR.                                     &
3722         TRIM( conserve_volume_flow_mode ) /= 'bulk_velocity' ) )  THEN
3723       WRITE( message_string, * )  'nonzero bulk velocity requires ',          &
3724            'conserve_volume_flow = .T. and ',                                 &
3725            'conserve_volume_flow_mode = ''bulk_velocity'''
3726       CALL message( 'check_parameters', 'PA0157', 1, 2, 0, 6, 0 )
3727    ENDIF
3728
3729!
3730!-- Check particle attributes
3731    IF ( particle_color /= 'none' )  THEN
3732       IF ( particle_color /= 'absuv'  .AND.  particle_color /= 'pt*'  .AND.   &
3733            particle_color /= 'z' )  THEN
3734          message_string = 'illegal value for parameter particle_color: ' //   &
3735                           TRIM( particle_color)
3736          CALL message( 'check_parameters', 'PA0313', 1, 2, 0, 6, 0 )
3737       ELSE
3738          IF ( color_interval(2) <= color_interval(1) )  THEN
3739             message_string = 'color_interval(2) <= color_interval(1)'
3740             CALL message( 'check_parameters', 'PA0315', 1, 2, 0, 6, 0 )
3741          ENDIF
3742       ENDIF
3743    ENDIF
3744
3745    IF ( particle_dvrpsize /= 'none' )  THEN
3746       IF ( particle_dvrpsize /= 'absw' )  THEN
3747          message_string = 'illegal value for parameter particle_dvrpsize:' // &
3748                           ' ' // TRIM( particle_color)
3749          CALL message( 'check_parameters', 'PA0314', 1, 2, 0, 6, 0 )
3750       ELSE
3751          IF ( dvrpsize_interval(2) <= dvrpsize_interval(1) )  THEN
3752             message_string = 'dvrpsize_interval(2) <= dvrpsize_interval(1)'
3753             CALL message( 'check_parameters', 'PA0316', 1, 2, 0, 6, 0 )
3754          ENDIF
3755       ENDIF
3756    ENDIF
3757
3758!
3759!-- Check nudging and large scale forcing from external file
3760    IF ( nudging .AND. ( .NOT. large_scale_forcing ) )  THEN
3761       message_string = 'Nudging requires large_scale_forcing = .T.. &'//      &
3762                        'Surface fluxes and geostrophic wind should be &'//    &
3763                        'prescribed in file LSF_DATA'
3764       CALL message( 'check_parameters', 'PA0374', 1, 2, 0, 6, 0 )
3765    ENDIF
3766
3767    IF ( large_scale_forcing .AND. ( bc_lr /= 'cyclic'  .OR.                   &
3768                                    bc_ns /= 'cyclic' ) )  THEN
3769       message_string = 'Non-cyclic lateral boundaries do not allow for &' //  &
3770                        'the usage of large scale forcing from external file.'
3771       CALL message( 'check_parameters', 'PA0375', 1, 2, 0, 6, 0 )
3772     ENDIF
3773
3774    IF ( large_scale_forcing .AND. ( .NOT. humidity ) )  THEN
3775       message_string = 'The usage of large scale forcing from external &'//   & 
3776                        'file LSF_DATA requires humidity = .T..'
3777       CALL message( 'check_parameters', 'PA0376', 1, 2, 0, 6, 0 )
3778     ENDIF
3779
3780    IF ( large_scale_forcing .AND. topography /= 'flat' )  THEN
3781       message_string = 'The usage of large scale forcing from external &'//   & 
3782                        'file LSF_DATA is not implemented for non-flat topography'
3783       CALL message( 'check_parameters', 'PA0377', 1, 2, 0, 6, 0 )
3784    ENDIF
3785
3786    IF ( large_scale_forcing .AND.  ocean  )  THEN
3787       message_string = 'The usage of large scale forcing from external &'//   & 
3788                        'file LSF_DATA is not implemented for ocean runs'
3789       CALL message( 'check_parameters', 'PA0378', 1, 2, 0, 6, 0 )
3790    ENDIF
3791
3792    CALL location_message( 'finished', .TRUE. )
3793
3794!
3795!-- Prevent empty time records in volume, cross-section and masked data in case of
3796!-- non-parallel netcdf-output in restart runs
3797    IF ( netcdf_data_format < 5 )  THEN
3798       IF ( TRIM( initializing_actions ) == 'read_restart_data' )  THEN
3799          do3d_time_count    = 0
3800          do2d_xy_time_count = 0
3801          do2d_xz_time_count = 0
3802          do2d_yz_time_count = 0
3803          domask_time_count  = 0
3804       ENDIF
3805    ENDIF
3806
3807!
3808!-- Check &userpar parameters
3809    CALL user_check_parameters
3810
3811
3812 END SUBROUTINE check_parameters
Note: See TracBrowser for help on using the repository browser.