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

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

preliminary checkin of new curvature/solution effects on droplet growth

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