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

Last change on this file since 772 was 772, checked in by heinze, 13 years ago

last commit documented

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