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

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