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

Last change on this file since 866 was 866, checked in by raasch, 12 years ago

bugfix for timestep calculation in case of Galilei transformation

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