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

Last change on this file since 852 was 846, checked in by maronga, 12 years ago

Last commit documented

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