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

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

last commit documented

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