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

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

bugfix in check_parameters.f90

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