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

Last change on this file since 799 was 775, checked in by letzel, 12 years ago

last commit documented

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