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

Last change on this file since 767 was 767, checked in by raasch, 13 years ago

New:
---

Flow field initialization with given (e.g. measured) profiles. Profile data
for u-,v-velocity components + respective heights are given with new
inipar-parameters u_profile, v_profile, and uv_heights. Final profiles are
calculated from these given profiles by linear interpolation.
(check_parameters, header, init_3d_model, modules, parin)

Changed:


ug,vg replaced by u_init,v_init as the Dirichlet top boundary condition
(boundary_conds)

dirichlet_0 conditions moved from init_3d_model to
check_parameters (check_parameters, init_3d_model)

Errors:


bugfix: dirichlet_0 conditions moved from init_3d_model to
check_parameters (check_parameters, init_3d_model)

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