source: palm/trunk/SOURCE/init_3d_model.f90 @ 2934

Last change on this file since 2934 was 2934, checked in by suehring, 6 years ago

Synchronize parent and child model after initialization and spinup phase; Check for consistent setting of spinup times in parent and child model; remove obsolete masking of tendency arrays during initialization

  • Property svn:keywords set to Id
  • Property svn:mergeinfo set to False
    /palm/branches/forwind/SOURCE/init_3d_model.f901564-1913
    /palm/branches/palm4u/SOURCE/init_3d_model.f902540-2692
File size: 96.0 KB
RevLine 
[1682]1!> @file init_3d_model.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
[2718]17! Copyright 1997-2018 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[254]20! Current revisions:
[732]21! ------------------
[2233]22!
[2701]23!
[2233]24! Former revisions:
25! -----------------
26! $Id: init_3d_model.f90 2934 2018-03-26 19:13:22Z suehring $
[2934]27! Synchronize parent and child models after initialization.
28! Remove obsolete masking of topography grid points for Runge-Kutta weighted
29! tendency arrays.
30!
31! 2920 2018-03-22 11:22:01Z kanani
[2920]32! Add call for precalculating apparent solar positions (moh.hefny)
33!
34! 2906 2018-03-19 08:56:40Z Giersch
[2906]35! The variables read/write_svf_on_init have been removed. Instead ENVIRONMENT
36! variables read/write_svf have been introduced. Location_message has been
37! added.
38!
39! 2894 2018-03-15 09:17:58Z Giersch
[2894]40! Renamed routines with respect to reading restart data, file 13 is closed in
41! rrd_read_parts_of_global now
42!
43! 2867 2018-03-09 09:40:23Z suehring
[2867]44! Further bugfix concerning call of user_init.
45!
46! 2864 2018-03-08 11:57:45Z suehring
[2864]47! Bugfix, move call of user_init in front of initialization of grid-point
48! arrays
49!
50! 2817 2018-02-19 16:32:21Z knoop
[2817]51! Preliminary gust module interface implemented
52!
53! 2776 2018-01-31 10:44:42Z Giersch
[2776]54! Variable use_synthetic_turbulence_generator has been abbreviated
55!
56! 2766 2018-01-22 17:17:47Z kanani
[2766]57! Removed preprocessor directive __chem
58!
59! 2758 2018-01-17 12:55:21Z suehring
[2758]60! In case of spinup of land- and urban-surface model, do not mask wind velocity
61! at first computational grid level
62!
63! 2746 2018-01-15 12:06:04Z suehring
[2746]64! Move flag plant canopy to modules
65!
66! 2718 2018-01-02 08:49:38Z maronga
[2716]67! Corrected "Former revisions" section
68!
69! 2705 2017-12-18 11:26:23Z maronga
[2705]70! Bugfix for reading initial profiles from ls/nuding file
[2716]71!
72! 2701 2017-12-15 15:40:50Z suehring
73! Changes from last commit documented
[2705]74!
[2716]75! 2700 2017-12-15 14:12:35Z suehring
[2701]76! Bugfix, missing initialization of surface attributes in case of
77! inifor-initialization branch
[2716]78!
79! 2698 2017-12-14 18:46:24Z suehring
80! Bugfix in get_topography_top_index
81!
82! 2696 2017-12-14 17:12:51Z kanani
83! Change in file header (GPL part)
[2696]84! Implementation of uv exposure model (FK)
85! Moved initialisation of diss, e, kh, km to turbulence_closure_mod (TG)
86! Added chemical emissions (FK)
87! Initialize masking arrays and number-of-grid-points arrays before initialize
88! LSM, USM and radiation module
89! Initialization with inifor (MS)
90!
91! 2618 2017-11-16 15:37:30Z suehring
[2618]92! Reorder calls of init_surfaces.
93!
94! 2564 2017-10-19 15:56:56Z Giersch
[2564]95! Variable wind_turbine was added to control_parameters.
96!
97! 2550 2017-10-16 17:12:01Z boeske
[2550]98! Modifications to cyclic fill method and turbulence recycling method in case of
99! complex terrain simulations
100!
101! 2513 2017-10-04 09:24:39Z kanani
[2513]102! Bugfix in storing initial scalar profile (wrong index)
103!
104! 2350 2017-08-15 11:48:26Z kanani
[2350]105! Bugfix in nopointer version
106!
107! 2339 2017-08-07 13:55:26Z gronemeier
[2339]108! corrected timestamp in header
109!
110! 2338 2017-08-07 12:15:38Z gronemeier
[2338]111! Modularize 1D model
112!
[2339]113! 2329 2017-08-03 14:24:56Z knoop
[2329]114! Removed temporary bugfix (r2327) as bug is properly resolved by this revision
115!
116! 2327 2017-08-02 07:40:57Z maronga
[2327]117! Temporary bugfix
118!
119! 2320 2017-07-21 12:47:43Z suehring
[2320]120! Modularize large-scale forcing and nudging
121!
122! 2292 2017-06-20 09:51:42Z schwenkel
[2292]123! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
124! includes two more prognostic equations for cloud drop concentration (nc) 
125! and cloud water content (qc).
126!
127! 2277 2017-06-12 10:47:51Z kanani
[2277]128! Removed unused variable sums_up_fraction_l
129!
130! 2270 2017-06-09 12:18:47Z maronga
[2270]131! dots_num must be increased when LSM and/or radiation is used
132!
133! 2259 2017-06-08 09:09:11Z gronemeier
[2259]134! Implemented synthetic turbulence generator
135!
136! 2252 2017-06-07 09:35:37Z knoop
[2252]137! rho_air now depending on surface_pressure even in Boussinesq mode
138!
139! 2233 2017-05-30 18:08:54Z suehring
[2233]140!
141! 2232 2017-05-30 17:47:52Z suehring
[2232]142! Adjustments to new topography and surface concept:
143!   - Modify passed parameters for disturb_field
144!   - Topography representation via flags
145!   - Remove unused arrays.
146!   - Move initialization of surface-related quantities to surface_mod
[1961]147!
[2173]148! 2172 2017-03-08 15:55:25Z knoop
149! Bugfix: moved parallel random generator initialization into its module
150!
[2119]151! 2118 2017-01-17 16:38:49Z raasch
152! OpenACC directives removed
153!
[2038]154! 2037 2016-10-26 11:15:40Z knoop
155! Anelastic approximation implemented
156!
[2032]157! 2031 2016-10-21 15:11:58Z knoop
158! renamed variable rho to rho_ocean
159!
[2012]160! 2011 2016-09-19 17:29:57Z kanani
161! Flag urban_surface is now defined in module control_parameters.
162!
[2008]163! 2007 2016-08-24 15:47:17Z kanani
164! Added support for urban surface model,
165! adjusted location_message in case of plant_canopy
166!
[2001]167! 2000 2016-08-20 18:09:15Z knoop
168! Forced header and separation lines into 80 columns
169!
[1993]170! 1992 2016-08-12 15:14:59Z suehring
171! Initializaton of scalarflux at model top
172! Bugfixes in initialization of surface and top salinity flux, top scalar and
173! humidity fluxes
174!
[1961]175! 1960 2016-07-12 16:34:24Z suehring
[1960]176! Separate humidity and passive scalar
177! Increase dimension for mean_inflow_profiles
178! Remove inadvertent write-statement
179! Bugfix, large-scale forcing is still not implemented for passive scalars
[1919]180!
[1958]181! 1957 2016-07-07 10:43:48Z suehring
182! flight module added
183!
[1921]184! 1920 2016-05-30 10:50:15Z suehring
185! Initialize us with very small number to avoid segmentation fault during
186! calculation of Obukhov length
187!
[1919]188! 1918 2016-05-27 14:35:57Z raasch
189! intermediate_timestep_count is set 0 instead 1 for first call of pres,
190! bugfix: initialization of local sum arrays are moved to the beginning of the
191!         routine because otherwise results from pres are overwritten
192!
[1917]193! 1914 2016-05-26 14:44:07Z witha
194! Added initialization of the wind turbine model
195!
[1879]196! 1878 2016-04-19 12:30:36Z hellstea
197! The zeroth element of weight_pres removed as unnecessary
198!
[1851]199! 1849 2016-04-08 11:33:18Z hoffmann
[1849]200! Adapted for modularization of microphysics.
201! precipitation_amount, precipitation_rate, prr moved to arrays_3d.
[1852]202! Initialization of nc_1d, nr_1d, pt_1d, qc_1d, qr_1d, q_1d moved to
[1849]203! microphysics_init.
204!
[1846]205! 1845 2016-04-08 08:29:13Z raasch
206! nzb_2d replaced by nzb_u|v_inner
[1914]207!
[1834]208! 1833 2016-04-07 14:23:03Z raasch
209! initialization of spectra quantities moved to spectra_mod
210!
[1832]211! 1831 2016-04-07 13:15:51Z hoffmann
212! turbulence renamed collision_turbulence
213!
[1827]214! 1826 2016-04-07 12:01:39Z maronga
215! Renamed radiation calls.
216! Renamed canopy model calls.
217!
[1823]218! 1822 2016-04-07 07:49:42Z hoffmann
219! icloud_scheme replaced by microphysics_*
[1914]220!
[1818]221! 1817 2016-04-06 15:44:20Z maronga
222! Renamed lsm calls.
223!
[1816]224! 1815 2016-04-06 13:49:59Z raasch
225! zero-settings for velocities inside topography re-activated (was deactivated
226! in r1762)
227!
[1789]228! 1788 2016-03-10 11:01:04Z maronga
229! Added z0q.
230! Syntax layout improved.
231!
[1784]232! 1783 2016-03-06 18:36:17Z raasch
233! netcdf module name changed + related changes
234!
[1765]235! 1764 2016-02-28 12:45:19Z raasch
236! bugfix: increase size of volume_flow_area_l and volume_flow_initial_l by 1
237!
[1763]238! 1762 2016-02-25 12:31:13Z hellstea
239! Introduction of nested domain feature
240!
[1739]241! 1738 2015-12-18 13:56:05Z raasch
242! calculate mean surface level height for each statistic region
243!
[1735]244! 1734 2015-12-02 12:17:12Z raasch
245! no initial disturbances in case that the disturbance energy limit has been
246! set zero
247!
[1708]248! 1707 2015-11-02 15:24:52Z maronga
249! Bugfix: transfer of Richardson number from 1D model to Obukhov length caused
250! devision by zero in neutral stratification
251!
[1692]252! 1691 2015-10-26 16:17:44Z maronga
253! Call to init_surface_layer added. rif is replaced by ol and zeta.
254!
[1683]255! 1682 2015-10-07 23:56:08Z knoop
256! Code annotations made doxygen readable
257!
[1616]258! 1615 2015-07-08 18:49:19Z suehring
259! Enable turbulent inflow for passive_scalar and humidity
260!
[1586]261! 1585 2015-04-30 07:05:52Z maronga
262! Initialization of radiation code is now done after LSM initializtion
263!
[1576]264! 1575 2015-03-27 09:56:27Z raasch
265! adjustments for psolver-queries
266!
[1552]267! 1551 2015-03-03 14:18:16Z maronga
[1817]268! Allocation of land surface arrays is now done in the subroutine lsm_init_arrays,
[1552]269! which is part of land_surface_model.
270!
[1508]271! 1507 2014-12-10 12:14:18Z suehring
272! Bugfix: set horizontal velocity components to zero inside topography
273!
[1497]274! 1496 2014-12-02 17:25:50Z maronga
275! Added initialization of the land surface and radiation schemes
276!
[1485]277! 1484 2014-10-21 10:53:05Z kanani
[1484]278! Changes due to new module structure of the plant canopy model:
[1508]279! canopy-related initialization (e.g. lad and canopy_heat_flux) moved to new
280! subroutine init_plant_canopy within the module plant_canopy_model_mod,
281! call of subroutine init_plant_canopy added.
[1341]282!
[1432]283! 1431 2014-07-15 14:47:17Z suehring
284! var_d added, in order to normalize spectra.
285!
[1430]286! 1429 2014-07-15 12:53:45Z knoop
287! Ensemble run capability added to parallel random number generator
288!
[1412]289! 1411 2014-05-16 18:01:51Z suehring
290! Initial horizontal velocity profiles were not set to zero at the first vertical
291! grid level in case of non-cyclic lateral boundary conditions.
292!
[1407]293! 1406 2014-05-16 13:47:01Z raasch
294! bugfix: setting of initial velocities at k=1 to zero not in case of a
295! no-slip boundary condition for uv
296!
[1403]297! 1402 2014-05-09 14:25:13Z raasch
298! location messages modified
299!
[1401]300! 1400 2014-05-09 14:03:54Z knoop
301! Parallel random number generator added
302!
[1385]303! 1384 2014-05-02 14:31:06Z raasch
304! location messages added
305!
[1362]306! 1361 2014-04-16 15:17:48Z hoffmann
307! tend_* removed
308! Bugfix: w_subs is not allocated anymore if it is already allocated
309!
[1360]310! 1359 2014-04-11 17:15:14Z hoffmann
311! module lpm_init_mod added to use statements, because lpm_init has become a
312! module
313!
[1354]314! 1353 2014-04-08 15:21:23Z heinze
315! REAL constants provided with KIND-attribute
316!
[1341]317! 1340 2014-03-25 19:45:13Z kanani
318! REAL constants defined as wp-kind
319!
[1323]320! 1322 2014-03-20 16:38:49Z raasch
321! REAL constants defined as wp-kind
322! module interfaces removed
323!
[1321]324! 1320 2014-03-20 08:40:49Z raasch
325! ONLY-attribute added to USE-statements,
326! kind-parameters added to all INTEGER and REAL declaration statements,
327! kinds are defined in new module kinds,
328! revision history before 2012 removed,
329! comment fields (!:) to be used for variable explanations added to
330! all variable declaration statements
331!
[1317]332! 1316 2014-03-17 07:44:59Z heinze
333! Bugfix: allocation of w_subs
334!
[1300]335! 1299 2014-03-06 13:15:21Z heinze
336! Allocate w_subs due to extension of large scale subsidence in combination
337! with large scale forcing data (LSF_DATA)
338!
[1242]339! 1241 2013-10-30 11:36:58Z heinze
340! Overwrite initial profiles in case of nudging
341! Inititialize shf and qsws in case of large_scale_forcing
342!
[1222]343! 1221 2013-09-10 08:59:13Z raasch
344! +rflags_s_inner in copyin statement, use copyin for most arrays instead of
345! copy
346!
[1213]347! 1212 2013-08-15 08:46:27Z raasch
348! array tri is allocated and included in data copy statement
349!
[1196]350! 1195 2013-07-01 12:27:57Z heinze
351! Bugfix: move allocation of ref_state to parin.f90 and read_var_list.f90
352!
[1182]353! 1179 2013-06-14 05:57:58Z raasch
354! allocate and set ref_state to be used in buoyancy terms
355!
[1172]356! 1171 2013-05-30 11:27:45Z raasch
357! diss array is allocated with full size if accelerator boards are used
358!
[1160]359! 1159 2013-05-21 11:58:22Z fricke
360! -bc_lr_dirneu, bc_lr_neudir, bc_ns_dirneu, bc_ns_neudir
361!
[1154]362! 1153 2013-05-10 14:33:08Z raasch
363! diss array is allocated with dummy elements even if it is not needed
[1171]364! (required by PGI 13.4 / CUDA 5.0)
[1154]365!
[1116]366! 1115 2013-03-26 18:16:16Z hoffmann
367! unused variables removed
368!
[1114]369! 1113 2013-03-10 02:48:14Z raasch
370! openACC directive modified
371!
[1112]372! 1111 2013-03-08 23:54:10Z raasch
373! openACC directives added for pres
374! array diss allocated only if required
375!
[1093]376! 1092 2013-02-02 11:24:22Z raasch
377! unused variables removed
378!
[1066]379! 1065 2012-11-22 17:42:36Z hoffmann
380! allocation of diss (dissipation rate) in case of turbulence = .TRUE. added
381!
[1054]382! 1053 2012-11-13 17:11:03Z hoffmann
[1053]383! allocation and initialisation of necessary data arrays for the two-moment
384! cloud physics scheme the two new prognostic equations (nr, qr):
385! +dr, lambda_r, mu_r, sed_*, xr, *s, *sws, *swst, *, *_p, t*_m, *_1, *_2, *_3,
386! +tend_*, prr
[979]387!
[1037]388! 1036 2012-10-22 13:43:42Z raasch
389! code put under GPL (PALM 3.9)
390!
[1033]391! 1032 2012-10-21 13:03:21Z letzel
392! save memory by not allocating pt_2 in case of neutral = .T.
393!
[1026]394! 1025 2012-10-07 16:04:41Z letzel
395! bugfix: swap indices of mask for ghost boundaries
396!
[1017]397! 1015 2012-09-27 09:23:24Z raasch
398! mask is set to zero for ghost boundaries
399!
[1011]400! 1010 2012-09-20 07:59:54Z raasch
401! cpp switch __nopointer added for pointer free version
402!
[1004]403! 1003 2012-09-14 14:35:53Z raasch
404! nxra,nyna, nzta replaced ny nxr, nyn, nzt
405!
[1002]406! 1001 2012-09-13 14:08:46Z raasch
407! all actions concerning leapfrog scheme removed
408!
[997]409! 996 2012-09-07 10:41:47Z raasch
410! little reformatting
411!
[979]412! 978 2012-08-09 08:28:32Z fricke
[978]413! outflow damping layer removed
414! roughness length for scalar quantites z0h added
415! damping zone for the potential temperatur in case of non-cyclic lateral
416! boundaries added
417! initialization of ptdf_x, ptdf_y
418! initialization of c_u_m, c_u_m_l, c_v_m, c_v_m_l, c_w_m, c_w_m_l
[708]419!
[850]420! 849 2012-03-15 10:35:09Z raasch
421! init_particles renamed lpm_init
422!
[826]423! 825 2012-02-19 03:03:44Z raasch
424! wang_collision_kernel renamed wang_kernel
425!
[1]426! Revision 1.1  1998/03/09 16:22:22  raasch
427! Initial revision
428!
429!
430! Description:
431! ------------
[1682]432!> Allocation of arrays and initialization of the 3D model via
433!> a) pre-run the 1D model
434!> or
435!> b) pre-set constant linear profiles
436!> or
437!> c) read values of a previous run
[1]438!------------------------------------------------------------------------------!
[1682]439 SUBROUTINE init_3d_model
440 
[1]441
[667]442    USE advec_ws
[1320]443
[1]444    USE arrays_3d
[1849]445
[2696]446    USE chemistry_model_mod,                                                   &
447        ONLY:  chem_emissions
448
[2037]449    USE cloud_parameters,                                                      &
450        ONLY:  cp, l_v, r_d
451
[1320]452    USE constants,                                                             &
453        ONLY:  pi
454   
[1]455    USE control_parameters
[1320]456   
[1957]457    USE flight_mod,                                                            &
458        ONLY:  flight_init
459   
[1320]460    USE grid_variables,                                                        &
[2037]461        ONLY:  dx, dy, ddx2_mg, ddy2_mg
[2817]462
463    USE gust_mod,                                                              &
464        ONLY:  gust_init, gust_init_arrays, gust_module_enabled
[1320]465   
[1]466    USE indices
[1359]467
[1429]468    USE lpm_init_mod,                                                          &
[1359]469        ONLY:  lpm_init
[1320]470   
471    USE kinds
[1496]472
473    USE land_surface_model_mod,                                                &
[2232]474        ONLY:  lsm_init, lsm_init_arrays
[1496]475 
[2320]476    USE lsf_nudging_mod,                                                       &
[2696]477        ONLY:  lsf_init, ls_forcing_surf, nudge_init
[1849]478
479    USE microphysics_mod,                                                      &
480        ONLY:  collision_turbulence, microphysics_init
481
[2338]482    USE model_1d_mod,                                                          &
483        ONLY:  e1d, init_1d_model, kh1d, km1d, l1d, rif1d, u1d, us1d, usws1d,  &
484               v1d, vsws1d 
485
[1783]486    USE netcdf_interface,                                                      &
[2817]487        ONLY:  dots_max, dots_num, dots_unit, dots_label
[2696]488
[2906]489    USE netcdf_data_input_mod,                                                 &
[2696]490        ONLY:  init_3d, netcdf_data_input_interpolate, netcdf_data_input_init_3d
[1320]491   
492    USE particle_attributes,                                                   &
493        ONLY:  particle_advection, use_sgs_for_particles, wang_kernel
494   
[1]495    USE pegrid
[1320]496   
[1484]497    USE plant_canopy_model_mod,                                                &
[2746]498        ONLY:  pcm_init
[1496]499
[2934]500    USE pmc_interface,                                                         &
501        ONLY:  nested_run
502
[1496]503    USE radiation_model_mod,                                                   &
[2696]504        ONLY:  radiation_init, radiation, radiation_control, radiation_scheme, &
[2906]505               radiation_calc_svf, radiation_write_svf,                        &
[2696]506               radiation_interaction, radiation_interactions,                  &
[2920]507               radiation_interaction_init, radiation_read_svf,                 &
508               radiation_presimulate_solar_pos
[1484]509   
[1320]510    USE random_function_mod 
511   
[1400]512    USE random_generator_parallel,                                             &
[2172]513        ONLY:  init_parallel_random_generator
[2894]514
515    USE read_restart_data_mod,                                                 &
516        ONLY:  rrd_read_parts_of_global, rrd_local                                     
[1400]517   
[1320]518    USE statistics,                                                            &
[1738]519        ONLY:  hom, hom_sum, mean_surface_level_height, pr_palm, rmask,        &
[1833]520               statistic_regions, sums, sums_divnew_l, sums_divold_l, sums_l,  &
[2277]521               sums_l_l, sums_wsts_bc_l, ts_value,                             &
[1833]522               weight_pres, weight_substep
[2259]523
524    USE synthetic_turbulence_generator_mod,                                    &
[2776]525        ONLY:  stg_init, use_syn_turb_gen
[2259]526
[1691]527    USE surface_layer_fluxes_mod,                                              &
528        ONLY:  init_surface_layer_fluxes
[2232]529
530    USE surface_mod,                                                           &
531        ONLY :  init_surface_arrays, init_surfaces, surf_def_h, surf_lsm_h,    &
[2698]532                surf_usm_h, get_topography_top_index_ji
[1691]533   
[2007]534    USE transpose_indices
[1]535
[2696]536    USE turbulence_closure_mod,                                                &
537        ONLY:  tcm_init_arrays, tcm_init
538
[2007]539    USE urban_surface_mod,                                                     &
[2696]540        ONLY:  usm_init_urban_surface, usm_allocate_surface
[2007]541
[2696]542    USE uv_exposure_model_mod,                                                 &
543        ONLY:  uvem_init, uvem_init_arrays
544
[1914]545    USE wind_turbine_model_mod,                                                &
[2564]546        ONLY:  wtm_init, wtm_init_arrays
[1914]547
[1]548    IMPLICIT NONE
549
[1682]550    INTEGER(iwp) ::  i             !<
551    INTEGER(iwp) ::  ind_array(1)  !<
552    INTEGER(iwp) ::  j             !<
553    INTEGER(iwp) ::  k             !<
[2232]554    INTEGER(iwp) ::  k_surf        !< surface level index
555    INTEGER(iwp) ::  m             !< index of surface element in surface data type
556    INTEGER(iwp) ::  sr            !< index of statistic region
[1]557
[1682]558    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  ngp_2dh_l  !<
[1]559
[1682]560    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_outer_l    !<
561    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_s_inner_l  !<
[1]562
[2037]563    REAL(wp)     ::  t_surface !< air temperature at the surface
564
565    REAL(wp), DIMENSION(:), ALLOCATABLE ::  p_hydrostatic !< hydrostatic pressure
566
567    INTEGER(iwp) ::  l       !< loop variable
568    INTEGER(iwp) ::  nzt_l   !< index of top PE boundary for multigrid level
569    REAL(wp) ::  dx_l !< grid spacing along x on different multigrid level
570    REAL(wp) ::  dy_l !< grid spacing along y on different multigrid level
571
[1764]572    REAL(wp), DIMENSION(1:3) ::  volume_flow_area_l     !<
573    REAL(wp), DIMENSION(1:3) ::  volume_flow_initial_l  !<
[1]574
[1738]575    REAL(wp), DIMENSION(:), ALLOCATABLE ::  mean_surface_level_height_l    !<
[1682]576    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_l    !<
577    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_tmp  !<
[1]578
[2550]579    INTEGER(iwp) ::  nz_u_shift   !<
580    INTEGER(iwp) ::  nz_v_shift   !<
581    INTEGER(iwp) ::  nz_w_shift   !<
582    INTEGER(iwp) ::  nz_s_shift   !<
583    INTEGER(iwp) ::  nz_u_shift_l !<
584    INTEGER(iwp) ::  nz_v_shift_l !<
585    INTEGER(iwp) ::  nz_w_shift_l !<
586    INTEGER(iwp) ::  nz_s_shift_l !<
[485]587
[1402]588    CALL location_message( 'allocating arrays', .FALSE. )
[1]589!
590!-- Allocate arrays
[1788]591    ALLOCATE( mean_surface_level_height(0:statistic_regions),                  &
592              mean_surface_level_height_l(0:statistic_regions),                &
593              ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions),    &
594              ngp_3d(0:statistic_regions),                                     &
595              ngp_3d_inner(0:statistic_regions),                               &
596              ngp_3d_inner_l(0:statistic_regions),                             &
597              ngp_3d_inner_tmp(0:statistic_regions),                           &
598              sums_divnew_l(0:statistic_regions),                              &
[1]599              sums_divold_l(0:statistic_regions) )
[1195]600    ALLOCATE( dp_smooth_factor(nzb:nzt), rdf(nzb+1:nzt), rdf_sc(nzb+1:nzt) )
[1788]601    ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions),                    &
602              ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions),                  &
603              ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions),                  &
604              ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions),                &
605              rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions),                  &
606              sums(nzb:nzt+1,pr_palm+max_pr_user),                             &
607              sums_l(nzb:nzt+1,pr_palm+max_pr_user,0:threads_per_task-1),      &
608              sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1),    &
609              sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions),                   &
[394]610              ts_value(dots_max,0:statistic_regions) )
[978]611    ALLOCATE( ptdf_x(nxlg:nxrg), ptdf_y(nysg:nyng) )
[1]612
[1788]613    ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr),                                    &
614              p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
[1010]615              tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
616
617#if defined( __nopointer )
[2696]618    ALLOCATE( pt(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                               &
[1788]619              pt_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
620              u(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
621              u_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
622              v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
623              v_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
624              w(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
625              w_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
626              tpt_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                            &
627              tu_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
628              tv_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
[1010]629              tw_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
630#else
[2696]631    ALLOCATE( pt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
[1788]632              pt_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
633              u_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
634              u_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
635              u_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
636              v_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
637              v_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
638              v_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
639              w_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
640              w_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
[667]641              w_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1788]642    IF (  .NOT.  neutral )  THEN
[1032]643       ALLOCATE( pt_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
644    ENDIF
[1010]645#endif
646
[673]647!
[707]648!-- Following array is required for perturbation pressure within the iterative
649!-- pressure solvers. For the multistep schemes (Runge-Kutta), array p holds
650!-- the weighted average of the substeps and cannot be used in the Poisson
651!-- solver.
652    IF ( psolver == 'sor' )  THEN
653       ALLOCATE( p_loc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1575]654    ELSEIF ( psolver(1:9) == 'multigrid' )  THEN
[707]655!
656!--    For performance reasons, multigrid is using one ghost layer only
657       ALLOCATE( p_loc(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
[673]658    ENDIF
[1]659
[1111]660!
661!-- Array for storing constant coeffficients of the tridiagonal solver
662    IF ( psolver == 'poisfft' )  THEN
[1212]663       ALLOCATE( tri(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1,2) )
[1111]664       ALLOCATE( tric(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) )
665    ENDIF
666
[1960]667    IF ( humidity )  THEN
[1]668!
[1960]669!--    3D-humidity
[1010]670#if defined( __nopointer )
[1788]671       ALLOCATE( q(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
672                 q_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[1010]673                 tq_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
674#else
[1788]675       ALLOCATE( q_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
676                 q_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[667]677                 q_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]678#endif
[1]679
680!
[1960]681!--    3D-arrays needed for humidity
[75]682       IF ( humidity )  THEN
[1010]683#if defined( __nopointer )
684          ALLOCATE( vpt(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
685#else
[667]686          ALLOCATE( vpt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]687#endif
[1]688
[1788]689          IF ( cloud_physics )  THEN
[1]690!
691!--          Liquid water content
[1010]692#if defined( __nopointer )
693             ALLOCATE ( ql(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
694#else
[667]695             ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]696#endif
[1053]697
698!
[1822]699!--          3D-cloud water content
[2292]700             IF ( .NOT. microphysics_morrison )  THEN
[1053]701#if defined( __nopointer )
[2292]702                ALLOCATE( qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1053]703#else
[2292]704                ALLOCATE( qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1053]705#endif
[2292]706             ENDIF
[1822]707!
[2292]708!--          Precipitation amount and rate (only needed if output is switched)
709             ALLOCATE( precipitation_amount(nysg:nyng,nxlg:nxrg),              &
710                       precipitation_rate(nysg:nyng,nxlg:nxrg) )
711
712!
[1822]713!--          3d-precipitation rate
714             ALLOCATE( prr(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]715
[2292]716             IF ( microphysics_morrison )  THEN
717!
718!--             3D-cloud drop water content, cloud drop concentration arrays
719#if defined( __nopointer )
720                ALLOCATE( nc(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                &
721                          nc_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
722                          qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                &
723                          qc_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
[2350]724                          tnc_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),             & 
[2292]725                          tqc_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
726#else
727                ALLOCATE( nc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
728                          nc_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
729                          nc_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
730                          qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
731                          qc_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
732                          qc_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
733#endif
734             ENDIF
735
[1822]736             IF ( microphysics_seifert )  THEN
[1053]737!
[1822]738!--             3D-rain water content, rain drop concentration arrays
[1115]739#if defined( __nopointer )
[1822]740                ALLOCATE( nr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                &
741                          nr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
742                          qr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                &
743                          qr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
744                          tnr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),             &
745                          tqr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]746#else
[1822]747                ALLOCATE( nr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
748                          nr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
749                          nr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
750                          qr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
751                          qr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
752                          qr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]753#endif
[1822]754             ENDIF
[1053]755
[1]756          ENDIF
757
758          IF ( cloud_droplets )  THEN
759!
[1010]760!--          Liquid water content, change in liquid water content
761#if defined( __nopointer )
[1788]762             ALLOCATE ( ql(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                     &
[1010]763                        ql_c(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
764#else
[1788]765             ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   &
[1010]766                        ql_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
767#endif
768!
769!--          Real volume of particles (with weighting), volume of particles
[1788]770             ALLOCATE ( ql_v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   &
[667]771                        ql_vp(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]772          ENDIF
773
774       ENDIF
775
776    ENDIF
[1960]777   
778   
779    IF ( passive_scalar )  THEN
[1]780
[1960]781!
782!--    3D scalar arrays
783#if defined( __nopointer )
784       ALLOCATE( s(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
785                 s_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
786                 ts_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
787#else
788       ALLOCATE( s_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
789                 s_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
790                 s_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
791#endif
792    ENDIF
793
[94]794    IF ( ocean )  THEN
[1010]795#if defined( __nopointer )
[1788]796       ALLOCATE( prho(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[2031]797                 rho_ocean(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[1788]798                 sa(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                            &
799                 sa_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[1010]800                 tsa_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
801#else
[1788]802       ALLOCATE( prho_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                        &
803                 rho_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                         &
804                 sa_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
805                 sa_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[667]806                 sa_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[388]807       prho => prho_1
[2031]808       rho_ocean  => rho_1  ! routines calc_mean_profile and diffusion_e require
[388]809                      ! density to be apointer
[1010]810#endif
[94]811    ENDIF
812
[1]813!
[2037]814!-- Allocation of anelastic and Boussinesq approximation specific arrays
815    ALLOCATE( p_hydrostatic(nzb:nzt+1) )
816    ALLOCATE( rho_air(nzb:nzt+1) )
817    ALLOCATE( rho_air_zw(nzb:nzt+1) )
818    ALLOCATE( drho_air(nzb:nzt+1) )
819    ALLOCATE( drho_air_zw(nzb:nzt+1) )
820
821!
822!-- Density profile calculation for anelastic approximation
[2252]823    t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**( r_d / cp )
[2037]824    IF ( TRIM( approximation ) == 'anelastic' ) THEN
825       DO  k = nzb, nzt+1
826          p_hydrostatic(k)    = surface_pressure * 100.0_wp *                  &
827                                ( 1 - ( g * zu(k) ) / ( cp * t_surface )       &
828                                )**( cp / r_d )
829          rho_air(k)          = ( p_hydrostatic(k) *                           &
830                                  ( 100000.0_wp / p_hydrostatic(k)             &
831                                  )**( r_d / cp )                              &
832                                ) / ( r_d * pt_init(k) )
833       ENDDO
834       DO  k = nzb, nzt
835          rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
836       ENDDO
837       rho_air_zw(nzt+1)  = rho_air_zw(nzt)                                    &
838                            + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
839    ELSE
[2252]840       DO  k = nzb, nzt+1
841          p_hydrostatic(k)    = surface_pressure * 100.0_wp *                  &
842                                ( 1 - ( g * zu(nzb) ) / ( cp * t_surface )       &
843                                )**( cp / r_d )
844          rho_air(k)          = ( p_hydrostatic(k) *                           &
845                                  ( 100000.0_wp / p_hydrostatic(k)             &
846                                  )**( r_d / cp )                              &
847                                ) / ( r_d * pt_init(nzb) )
848       ENDDO
849       DO  k = nzb, nzt
850          rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
851       ENDDO
852       rho_air_zw(nzt+1)  = rho_air_zw(nzt)                                    &
853                            + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
[2037]854    ENDIF
[2696]855!
[2037]856!-- compute the inverse density array in order to avoid expencive divisions
857    drho_air    = 1.0_wp / rho_air
858    drho_air_zw = 1.0_wp / rho_air_zw
859
860!
861!-- Allocation of flux conversion arrays
862    ALLOCATE( heatflux_input_conversion(nzb:nzt+1) )
863    ALLOCATE( waterflux_input_conversion(nzb:nzt+1) )
864    ALLOCATE( momentumflux_input_conversion(nzb:nzt+1) )
865    ALLOCATE( heatflux_output_conversion(nzb:nzt+1) )
866    ALLOCATE( waterflux_output_conversion(nzb:nzt+1) )
867    ALLOCATE( momentumflux_output_conversion(nzb:nzt+1) )
868
869!
870!-- calculate flux conversion factors according to approximation and in-/output mode
871    DO  k = nzb, nzt+1
872
873        IF ( TRIM( flux_input_mode ) == 'kinematic' )  THEN
874            heatflux_input_conversion(k)      = rho_air_zw(k)
875            waterflux_input_conversion(k)     = rho_air_zw(k)
876            momentumflux_input_conversion(k)  = rho_air_zw(k)
877        ELSEIF ( TRIM( flux_input_mode ) == 'dynamic' ) THEN
878            heatflux_input_conversion(k)      = 1.0_wp / cp
879            waterflux_input_conversion(k)     = 1.0_wp / l_v
880            momentumflux_input_conversion(k)  = 1.0_wp
881        ENDIF
882
883        IF ( TRIM( flux_output_mode ) == 'kinematic' )  THEN
884            heatflux_output_conversion(k)     = drho_air_zw(k)
885            waterflux_output_conversion(k)    = drho_air_zw(k)
886            momentumflux_output_conversion(k) = drho_air_zw(k)
887        ELSEIF ( TRIM( flux_output_mode ) == 'dynamic' ) THEN
888            heatflux_output_conversion(k)     = cp
889            waterflux_output_conversion(k)    = l_v
890            momentumflux_output_conversion(k) = 1.0_wp
891        ENDIF
892
893        IF ( .NOT. humidity ) THEN
894            waterflux_input_conversion(k)  = 1.0_wp
895            waterflux_output_conversion(k) = 1.0_wp
896        ENDIF
897
898    ENDDO
899
900!
901!-- In case of multigrid method, compute grid lengths and grid factors for the
902!-- grid levels with respective density on each grid
903    IF ( psolver(1:9) == 'multigrid' )  THEN
904
905       ALLOCATE( ddx2_mg(maximum_grid_level) )
906       ALLOCATE( ddy2_mg(maximum_grid_level) )
907       ALLOCATE( dzu_mg(nzb+1:nzt+1,maximum_grid_level) )
908       ALLOCATE( dzw_mg(nzb+1:nzt+1,maximum_grid_level) )
909       ALLOCATE( f1_mg(nzb+1:nzt,maximum_grid_level) )
910       ALLOCATE( f2_mg(nzb+1:nzt,maximum_grid_level) )
911       ALLOCATE( f3_mg(nzb+1:nzt,maximum_grid_level) )
912       ALLOCATE( rho_air_mg(nzb:nzt+1,maximum_grid_level) )
913       ALLOCATE( rho_air_zw_mg(nzb:nzt+1,maximum_grid_level) )
914
915       dzu_mg(:,maximum_grid_level) = dzu
916       rho_air_mg(:,maximum_grid_level) = rho_air
917!       
918!--    Next line to ensure an equally spaced grid.
919       dzu_mg(1,maximum_grid_level) = dzu(2)
920       rho_air_mg(nzb,maximum_grid_level) = rho_air(nzb) +                     &
921                                             (rho_air(nzb) - rho_air(nzb+1))
922
923       dzw_mg(:,maximum_grid_level) = dzw
924       rho_air_zw_mg(:,maximum_grid_level) = rho_air_zw
925       nzt_l = nzt
926       DO  l = maximum_grid_level-1, 1, -1
927           dzu_mg(nzb+1,l) = 2.0_wp * dzu_mg(nzb+1,l+1)
928           dzw_mg(nzb+1,l) = 2.0_wp * dzw_mg(nzb+1,l+1)
929           rho_air_mg(nzb,l)    = rho_air_mg(nzb,l+1) + (rho_air_mg(nzb,l+1) - rho_air_mg(nzb+1,l+1))
930           rho_air_zw_mg(nzb,l) = rho_air_zw_mg(nzb,l+1) + (rho_air_zw_mg(nzb,l+1) - rho_air_zw_mg(nzb+1,l+1))
931           rho_air_mg(nzb+1,l)    = rho_air_mg(nzb+1,l+1)
932           rho_air_zw_mg(nzb+1,l) = rho_air_zw_mg(nzb+1,l+1)
933           nzt_l = nzt_l / 2
934           DO  k = 2, nzt_l+1
935              dzu_mg(k,l) = dzu_mg(2*k-2,l+1) + dzu_mg(2*k-1,l+1)
936              dzw_mg(k,l) = dzw_mg(2*k-2,l+1) + dzw_mg(2*k-1,l+1)
937              rho_air_mg(k,l)    = rho_air_mg(2*k-1,l+1)
938              rho_air_zw_mg(k,l) = rho_air_zw_mg(2*k-1,l+1)
939           ENDDO
940       ENDDO
941
942       nzt_l = nzt
943       dx_l  = dx
944       dy_l  = dy
945       DO  l = maximum_grid_level, 1, -1
946          ddx2_mg(l) = 1.0_wp / dx_l**2
947          ddy2_mg(l) = 1.0_wp / dy_l**2
948          DO  k = nzb+1, nzt_l
949             f2_mg(k,l) = rho_air_zw_mg(k,l) / ( dzu_mg(k+1,l) * dzw_mg(k,l) )
950             f3_mg(k,l) = rho_air_zw_mg(k-1,l) / ( dzu_mg(k,l)   * dzw_mg(k,l) )
951             f1_mg(k,l) = 2.0_wp * ( ddx2_mg(l) + ddy2_mg(l) ) &
952                          * rho_air_mg(k,l) + f2_mg(k,l) + f3_mg(k,l)
953          ENDDO
954          nzt_l = nzt_l / 2
955          dx_l  = dx_l * 2.0_wp
956          dy_l  = dy_l * 2.0_wp
957       ENDDO
958
959    ENDIF
960
961!
[1299]962!-- 1D-array for large scale subsidence velocity
[1361]963    IF ( .NOT. ALLOCATED( w_subs ) )  THEN
964       ALLOCATE ( w_subs(nzb:nzt+1) )
965       w_subs = 0.0_wp
966    ENDIF
[1299]967
968!
[106]969!-- Arrays to store velocity data from t-dt and the phase speeds which
970!-- are needed for radiation boundary conditions
[73]971    IF ( outflow_l )  THEN
[1788]972       ALLOCATE( u_m_l(nzb:nzt+1,nysg:nyng,1:2),                               &
973                 v_m_l(nzb:nzt+1,nysg:nyng,0:1),                               &
[667]974                 w_m_l(nzb:nzt+1,nysg:nyng,0:1) )
[73]975    ENDIF
976    IF ( outflow_r )  THEN
[1788]977       ALLOCATE( u_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                           &
978                 v_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                           &
[667]979                 w_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx) )
[73]980    ENDIF
[106]981    IF ( outflow_l  .OR.  outflow_r )  THEN
[1788]982       ALLOCATE( c_u(nzb:nzt+1,nysg:nyng), c_v(nzb:nzt+1,nysg:nyng),           &
[667]983                 c_w(nzb:nzt+1,nysg:nyng) )
[106]984    ENDIF
[73]985    IF ( outflow_s )  THEN
[1788]986       ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxlg:nxrg),                               &
987                 v_m_s(nzb:nzt+1,1:2,nxlg:nxrg),                               &
[667]988                 w_m_s(nzb:nzt+1,0:1,nxlg:nxrg) )
[73]989    ENDIF
990    IF ( outflow_n )  THEN
[1788]991       ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                           &
992                 v_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                           &
[667]993                 w_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg) )
[73]994    ENDIF
[106]995    IF ( outflow_s  .OR.  outflow_n )  THEN
[1788]996       ALLOCATE( c_u(nzb:nzt+1,nxlg:nxrg), c_v(nzb:nzt+1,nxlg:nxrg),           &
[667]997                 c_w(nzb:nzt+1,nxlg:nxrg) )
[106]998    ENDIF
[996]999    IF ( outflow_l  .OR.  outflow_r  .OR.  outflow_s  .OR.  outflow_n )  THEN
[978]1000       ALLOCATE( c_u_m_l(nzb:nzt+1), c_v_m_l(nzb:nzt+1), c_w_m_l(nzb:nzt+1) )                   
1001       ALLOCATE( c_u_m(nzb:nzt+1), c_v_m(nzb:nzt+1), c_w_m(nzb:nzt+1) )
1002    ENDIF
[73]1003
[978]1004
[1010]1005#if ! defined( __nopointer )
[73]1006!
[1]1007!-- Initial assignment of the pointers
[1032]1008    IF ( .NOT. neutral )  THEN
1009       pt => pt_1;  pt_p => pt_2;  tpt_m => pt_3
1010    ELSE
1011       pt => pt_1;  pt_p => pt_1;  tpt_m => pt_3
1012    ENDIF
[1001]1013    u  => u_1;   u_p  => u_2;   tu_m  => u_3
1014    v  => v_1;   v_p  => v_2;   tv_m  => v_3
1015    w  => w_1;   w_p  => w_2;   tw_m  => w_3
[1]1016
[1960]1017    IF ( humidity )  THEN
[1001]1018       q => q_1;  q_p => q_2;  tq_m => q_3
[1053]1019       IF ( humidity )  THEN
1020          vpt  => vpt_1   
1021          IF ( cloud_physics )  THEN
1022             ql => ql_1
[2292]1023             IF ( .NOT. microphysics_morrison )  THEN
1024                qc => qc_1
1025             ENDIF
1026             IF ( microphysics_morrison )  THEN
1027                qc => qc_1;  qc_p  => qc_2;  tqc_m  => qc_3
1028                nc => nc_1;  nc_p  => nc_2;  tnc_m  => nc_3
1029             ENDIF
[1822]1030             IF ( microphysics_seifert )  THEN
1031                qr => qr_1;  qr_p  => qr_2;  tqr_m  => qr_3
1032                nr => nr_1;  nr_p  => nr_2;  tnr_m  => nr_3
[1053]1033             ENDIF
1034          ENDIF
1035       ENDIF
[1001]1036       IF ( cloud_droplets )  THEN
1037          ql   => ql_1
1038          ql_c => ql_2
[1]1039       ENDIF
[1001]1040    ENDIF
[1960]1041   
1042    IF ( passive_scalar )  THEN
1043       s => s_1;  s_p => s_2;  ts_m => s_3
1044    ENDIF   
[1]1045
[1001]1046    IF ( ocean )  THEN
1047       sa => sa_1;  sa_p => sa_2;  tsa_m => sa_3
1048    ENDIF
[1010]1049#endif
[1]1050!
[2696]1051!-- Initialize arrays for turbulence closure
1052    CALL tcm_init_arrays
1053!
1054!-- Initialize surface arrays
[2232]1055    CALL init_surface_arrays
1056!
[1551]1057!-- Allocate land surface model arrays
1058    IF ( land_surface )  THEN
[1817]1059       CALL lsm_init_arrays
[1551]1060    ENDIF
1061
1062!
[1914]1063!-- Allocate wind turbine model arrays
1064    IF ( wind_turbine )  THEN
1065       CALL wtm_init_arrays
1066    ENDIF
[1957]1067!
[2817]1068!-- Allocate gust module arrays
1069    IF ( gust_module_enabled )  THEN
1070       CALL gust_init_arrays
1071    ENDIF
1072
1073!
[1957]1074!-- Initialize virtual flight measurements
1075    IF ( virtual_flight )  THEN
1076       CALL flight_init
1077    ENDIF
[1914]1078
1079!
[2696]1080!-- Read uv exposure input data
1081    IF ( uv_exposure )  THEN
1082       CALL uvem_init
[2320]1083    ENDIF
1084!
[2696]1085!-- Allocate uv exposure arrays
1086    IF ( uv_exposure )  THEN
1087       CALL uvem_init_arrays
[2320]1088    ENDIF
1089
1090!
[2705]1091!-- Initialize nudging if required
1092    IF ( nudging )  THEN
1093       CALL nudge_init
1094    ENDIF
1095
1096!
1097!-- Initialize reading of large scale forcing from external file - if required
1098    IF ( large_scale_forcing  .OR.  forcing )  THEN
1099       CALL lsf_init
1100    ENDIF
1101
1102!
[709]1103!-- Allocate arrays containing the RK coefficient for calculation of
1104!-- perturbation pressure and turbulent fluxes. At this point values are
1105!-- set for pressure calculation during initialization (where no timestep
1106!-- is done). Further below the values needed within the timestep scheme
1107!-- will be set.
[1788]1108    ALLOCATE( weight_substep(1:intermediate_timestep_count_max),               &
[1878]1109              weight_pres(1:intermediate_timestep_count_max) )
[1340]1110    weight_substep = 1.0_wp
1111    weight_pres    = 1.0_wp
[1918]1112    intermediate_timestep_count = 0  ! needed when simulated_time = 0.0
[673]1113       
[1402]1114    CALL location_message( 'finished', .TRUE. )
[1918]1115
[673]1116!
[1918]1117!-- Initialize local summation arrays for routine flow_statistics.
1118!-- This is necessary because they may not yet have been initialized when they
1119!-- are called from flow_statistics (or - depending on the chosen model run -
1120!-- are never initialized)
1121    sums_divnew_l      = 0.0_wp
1122    sums_divold_l      = 0.0_wp
1123    sums_l_l           = 0.0_wp
1124    sums_wsts_bc_l     = 0.0_wp
1125
[2696]1126
1127
[1918]1128!
[1]1129!-- Initialize model variables
[1788]1130    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
[328]1131         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
[1]1132!
[2696]1133!--    Initialization with provided input data derived from larger-scale model
1134       IF ( INDEX( initializing_actions, 'inifor' ) /= 0 )  THEN
1135          CALL location_message( 'initializing with INIFOR', .FALSE. )
1136!
1137!--       Read initial 1D profiles from NetCDF file if available.
1138!--       At the moment, only u, v, w, pt and q are provided.
1139          CALL netcdf_data_input_init_3d
1140!
1141!--       Please note, at the moment INIFOR assumes only an equidistant vertical
1142!--       grid. In case of vertical grid stretching, input of inital data
1143!--       need to be inter- and/or extrapolated.
1144!--       Therefore, check if zu grid on file is identical to numeric zw grid.
1145!--       Please note 
1146          IF ( ANY( zu(1:nzt+1) /= init_3d%zu_atmos(1:init_3d%nzu) ) )  THEN
[1384]1147
[2696]1148             CALL netcdf_data_input_interpolate( init_3d%u_init(nzb+1:nzt+1),  &
1149                                                 zu(nzb+1:nzt+1),              &
1150                                                 init_3d%zu_atmos )
1151             CALL netcdf_data_input_interpolate( init_3d%v_init(nzb+1:nzt+1),  &
1152                                                 zu(nzb+1:nzt+1),              &
1153                                                 init_3d%zu_atmos )
1154!              CALL netcdf_data_input_interpolate( init_3d%w_init(nzb+1:nzt),    &
1155!                                                  zw(nzb+1:nzt),                &
1156!                                                  init_3d%zw_atmos )
1157             IF ( .NOT. neutral )                                              &
1158                CALL netcdf_data_input_interpolate(                            &
1159                                             init_3d%pt_init(nzb+1:nzt+1),     &
1160                                             zu(nzb+1:nzt+1),                  &
1161                                             init_3d%zu_atmos )
1162             IF ( humidity )                                                   &
1163                CALL netcdf_data_input_interpolate(                            &
1164                                             init_3d%q_init(nzb+1:nzt+1),      &
1165                                             zu(nzb+1:nzt+1),                  &
1166                                             init_3d%zu_atmos )
1167          ENDIF
1168
1169          u_init = init_3d%u_init
1170          v_init = init_3d%v_init   
1171          IF( .NOT. neutral )  pt_init = init_3d%pt_init
1172          IF( humidity      )  q_init  = init_3d%q_init
1173
1174!
1175!--       Please note, Inifor provides data from nzb+1 to nzt+1.
1176!--       Initialize pt and q with Neumann condition at nzb.
1177          IF( .NOT. neutral )  pt_init(nzb) = pt_init(nzb+1)
1178          IF( humidity      )  q_init(nzb)  = q_init(nzb+1)
1179          DO  i = nxlg, nxrg
1180             DO  j = nysg, nyng
1181                u(:,j,i) = u_init(:)
1182                v(:,j,i) = v_init(:)
1183                IF( .NOT. neutral )  pt(:,j,i) = pt_init(:)
1184                IF( humidity      )  q(:,j,i)  = q_init(:)
1185             ENDDO
1186          ENDDO
1187!
1188!--       MS: What about the geostrophic wind profiles? Actually these
1189!--           are not identical to the initial wind profiles in this case.
1190!--           This need to be further revised.
1191!           ug(:) = u_init(:)
1192!           vg(:) = v_init(:)
1193!
1194!--       Set inital w to 0
1195          w = 0.0_wp
1196!
1197!--       Initialize the remaining quantities
1198          IF ( humidity )  THEN
1199             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1200                DO  i = nxlg, nxrg
1201                   DO  j = nysg, nyng
1202                      qc(:,j,i) = 0.0_wp
1203                      nc(:,j,i) = 0.0_wp
1204                   ENDDO
1205                ENDDO
1206             ENDIF
1207
1208             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
1209                DO  i = nxlg, nxrg
1210                   DO  j = nysg, nyng
1211                      qr(:,j,i) = 0.0_wp
1212                      nr(:,j,i) = 0.0_wp
1213                   ENDDO
1214                ENDDO
1215             ENDIF
1216
1217          ENDIF
1218
1219          IF ( passive_scalar )  THEN
1220             DO  i = nxlg, nxrg
1221                DO  j = nysg, nyng
1222                   s(:,j,i) = s_init
1223                ENDDO
1224             ENDDO
1225          ENDIF
1226
1227          IF ( ocean )  THEN
1228             DO  i = nxlg, nxrg
1229                DO  j = nysg, nyng
1230                   sa(:,j,i) = sa_init
1231                ENDDO
1232             ENDDO
1233          ENDIF
1234
1235!
1236!--       Set velocity components at non-atmospheric / oceanic grid points to
1237!--       zero.
1238          u = MERGE( u, 0.0_wp, BTEST( wall_flags_0, 1 ) )
1239          v = MERGE( v, 0.0_wp, BTEST( wall_flags_0, 2 ) )
1240          w = MERGE( w, 0.0_wp, BTEST( wall_flags_0, 3 ) )
[2700]1241!
1242!--       Initialize surface variables, e.g. friction velocity, momentum
1243!--       fluxes, etc.
1244          CALL init_surfaces
[2696]1245
1246          CALL location_message( 'finished', .TRUE. )
1247!
1248!--    Initialization via computed 1D-model profiles
1249       ELSEIF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
1250
[1402]1251          CALL location_message( 'initializing with 1D model profiles', .FALSE. )
[1]1252!
1253!--       Use solutions of the 1D model as initial profiles,
1254!--       start 1D model
1255          CALL init_1d_model
1256!
1257!--       Transfer initial profiles to the arrays of the 3D model
[667]1258          DO  i = nxlg, nxrg
1259             DO  j = nysg, nyng
[1]1260                pt(:,j,i) = pt_init
1261                u(:,j,i)  = u1d
1262                v(:,j,i)  = v1d
1263             ENDDO
1264          ENDDO
1265
[1960]1266          IF ( humidity )  THEN
[667]1267             DO  i = nxlg, nxrg
1268                DO  j = nysg, nyng
[1]1269                   q(:,j,i) = q_init
1270                ENDDO
1271             ENDDO
[2292]1272             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1273                DO  i = nxlg, nxrg
1274                   DO  j = nysg, nyng
1275                      qc(:,j,i) = 0.0_wp
1276                      nc(:,j,i) = 0.0_wp
1277                   ENDDO
1278                ENDDO
1279             ENDIF
[1822]1280             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1053]1281                DO  i = nxlg, nxrg
1282                   DO  j = nysg, nyng
[1340]1283                      qr(:,j,i) = 0.0_wp
1284                      nr(:,j,i) = 0.0_wp
[1053]1285                   ENDDO
1286                ENDDO
1287             ENDIF
[1]1288          ENDIF
[2292]1289
[1960]1290          IF ( passive_scalar )  THEN
1291             DO  i = nxlg, nxrg
1292                DO  j = nysg, nyng
1293                   s(:,j,i) = s_init
1294                ENDDO
1295             ENDDO   
1296          ENDIF
[1]1297!
1298!--          Store initial profiles for output purposes etc.
[2696]1299          IF ( .NOT. constant_diffusion )  THEN
[1]1300             hom(:,1,25,:) = SPREAD( l1d, 2, statistic_regions+1 )
1301          ENDIF
1302!
[2696]1303!--       Set velocities back to zero
[2758]1304          u = MERGE( u, 0.0_wp, BTEST( wall_flags_0, 1 ) )
1305          v = MERGE( v, 0.0_wp, BTEST( wall_flags_0, 2 ) )         
[1]1306!
[2696]1307!--       WARNING: The extra boundary conditions set after running the
1308!--       -------  1D model impose an error on the divergence one layer
1309!--                below the topography; need to correct later
1310!--       ATTENTION: Provisional correction for Piacsek & Williams
1311!--       ---------  advection scheme: keep u and v zero one layer below
1312!--                  the topography.
1313          IF ( ibc_uv_b == 1 )  THEN
[667]1314!
[2696]1315!--          Neumann condition
1316             DO  i = nxl-1, nxr+1
1317                DO  j = nys-1, nyn+1
1318                   u(nzb,j,i) = u(nzb+1,j,i)
1319                   v(nzb,j,i) = v(nzb+1,j,i)
[1]1320                ENDDO
[2696]1321             ENDDO
[1]1322
1323          ENDIF
[2618]1324!
1325!--       Initialize surface variables, e.g. friction velocity, momentum
1326!--       fluxes, etc.
1327          CALL init_surfaces
[1]1328
[1402]1329          CALL location_message( 'finished', .TRUE. )
[1384]1330
[1788]1331       ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 )    &
[1]1332       THEN
[1241]1333
[1402]1334          CALL location_message( 'initializing with constant profiles', .FALSE. )
[1]1335!
[2259]1336!--       Overwrite initial profiles in case of synthetic turbulence generator
[2776]1337          IF( use_syn_turb_gen ) THEN
[2259]1338             CALL stg_init
1339          ENDIF
1340
1341!
[1]1342!--       Use constructed initial profiles (velocity constant with height,
1343!--       temperature profile with constant gradient)
[667]1344          DO  i = nxlg, nxrg
1345             DO  j = nysg, nyng
[1]1346                pt(:,j,i) = pt_init
1347                u(:,j,i)  = u_init
1348                v(:,j,i)  = v_init
1349             ENDDO
1350          ENDDO
1351!
[2758]1352!--       Mask topography
1353          u = MERGE( u, 0.0_wp, BTEST( wall_flags_0, 1 ) )
1354          v = MERGE( v, 0.0_wp, BTEST( wall_flags_0, 2 ) )
1355!
[292]1356!--       Set initial horizontal velocities at the lowest computational grid
1357!--       levels to zero in order to avoid too small time steps caused by the
1358!--       diffusion limit in the initial phase of a run (at k=1, dz/2 occurs
[2758]1359!--       in the limiting formula!).
1360!--       Please note, in case land- or urban-surface model is used and a
1361!--       spinup is applied, masking the lowest computational level is not
1362!--       possible as MOST as well as energy-balance parametrizations will not
1363!--       work with zero wind velocity.
1364          IF ( ibc_uv_b /= 1  .AND.  .NOT.  spinup )  THEN
[1815]1365             DO  i = nxlg, nxrg
1366                DO  j = nysg, nyng
[2232]1367                   DO  k = nzb, nzt
1368                      u(k,j,i) = MERGE( u(k,j,i), 0.0_wp,                      &
1369                                        BTEST( wall_flags_0(k,j,i), 20 ) )
1370                      v(k,j,i) = MERGE( v(k,j,i), 0.0_wp,                      &
1371                                        BTEST( wall_flags_0(k,j,i), 21 ) )
1372                   ENDDO
[1815]1373                ENDDO
1374             ENDDO
1375          ENDIF
[1]1376
[1960]1377          IF ( humidity )  THEN
[667]1378             DO  i = nxlg, nxrg
1379                DO  j = nysg, nyng
[1]1380                   q(:,j,i) = q_init
1381                ENDDO
1382             ENDDO
[2292]1383             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1384                DO  i = nxlg, nxrg
1385                   DO  j = nysg, nyng
1386                      qc(:,j,i) = 0.0_wp
1387                      nc(:,j,i) = 0.0_wp
1388                   ENDDO
1389                ENDDO
1390             ENDIF
1391
[1822]1392             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
1393                DO  i = nxlg, nxrg
1394                   DO  j = nysg, nyng
1395                      qr(:,j,i) = 0.0_wp
1396                      nr(:,j,i) = 0.0_wp
[1053]1397                   ENDDO
[1822]1398                ENDDO
[2292]1399             ENDIF
[1115]1400
[1]1401          ENDIF
[1960]1402         
1403          IF ( passive_scalar )  THEN
1404             DO  i = nxlg, nxrg
1405                DO  j = nysg, nyng
1406                   s(:,j,i) = s_init
1407                ENDDO
1408             ENDDO
1409          ENDIF
[1]1410
[94]1411          IF ( ocean )  THEN
[667]1412             DO  i = nxlg, nxrg
1413                DO  j = nysg, nyng
[94]1414                   sa(:,j,i) = sa_init
1415                ENDDO
1416             ENDDO
1417          ENDIF
[1920]1418!
[1]1419!--       Compute initial temperature field and other constants used in case
1420!--       of a sloping surface
1421          IF ( sloping_surface )  CALL init_slope
[2618]1422!
1423!--       Initialize surface variables, e.g. friction velocity, momentum
1424!--       fluxes, etc.
1425          CALL init_surfaces
[1]1426
[1402]1427          CALL location_message( 'finished', .TRUE. )
[1384]1428
[1788]1429       ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 )                  &
[46]1430       THEN
[1384]1431
[1402]1432          CALL location_message( 'initializing by user', .FALSE. )
[46]1433!
[2618]1434!--       Pre-initialize surface variables, i.e. setting start- and end-indices
1435!--       at each (j,i)-location. Please note, this does not supersede
1436!--       user-defined initialization of surface quantities.
1437          CALL init_surfaces
1438!
[46]1439!--       Initialization will completely be done by the user
1440          CALL user_init_3d_model
1441
[1402]1442          CALL location_message( 'finished', .TRUE. )
[1384]1443
[1]1444       ENDIF
[1384]1445
[1402]1446       CALL location_message( 'initializing statistics, boundary conditions, etc.', &
1447                              .FALSE. )
[1384]1448
[667]1449!
1450!--    Bottom boundary
1451       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2  )  THEN
[1340]1452          u(nzb,:,:) = 0.0_wp
1453          v(nzb,:,:) = 0.0_wp
[667]1454       ENDIF
[1]1455
1456!
[151]1457!--    Apply channel flow boundary condition
[132]1458       IF ( TRIM( bc_uv_t ) == 'dirichlet_0' )  THEN
[1340]1459          u(nzt+1,:,:) = 0.0_wp
1460          v(nzt+1,:,:) = 0.0_wp
[132]1461       ENDIF
1462
1463!
[1]1464!--    Calculate virtual potential temperature
[1960]1465       IF ( humidity )  vpt = pt * ( 1.0_wp + 0.61_wp * q )
[1]1466
1467!
[2696]1468!--    Store initial profiles for output purposes etc.. Please note, in case of
1469!--    initialization of u, v, w, pt, and q via output data derived from larger
1470!--    scale models, data will not be horizontally homogeneous. Actually, a mean
1471!--    profile should be calculated before.   
[1]1472       hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 )
1473       hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 )
[667]1474       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2)  THEN
[1340]1475          hom(nzb,1,5,:) = 0.0_wp
1476          hom(nzb,1,6,:) = 0.0_wp
[1]1477       ENDIF
1478       hom(:,1,7,:)  = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
1479
[2696]1480
1481!
1482!--    Store initial salinity profile
[97]1483       IF ( ocean )  THEN
1484          hom(:,1,26,:)  = SPREAD( sa(:,nys,nxl), 2, statistic_regions+1 )
1485       ENDIF
[1]1486
[75]1487       IF ( humidity )  THEN
[1]1488!
1489!--       Store initial profile of total water content, virtual potential
1490!--       temperature
1491          hom(:,1,26,:) = SPREAD(   q(:,nys,nxl), 2, statistic_regions+1 )
1492          hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 )
[2696]1493!
1494!--       Store initial profile of specific humidity and potential
1495!--       temperature
[1]1496          IF ( cloud_physics  .OR.  cloud_droplets ) THEN
1497             hom(:,1,27,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
1498             hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
1499          ENDIF
1500       ENDIF
1501
[2696]1502!
1503!--    Store initial scalar profile
[1]1504       IF ( passive_scalar )  THEN
[2513]1505          hom(:,1,121,:) = SPREAD(  s(:,nys,nxl), 2, statistic_regions+1 )
[1]1506       ENDIF
1507
1508!
[1400]1509!--    Initialize the random number generators (from numerical recipes)
1510       CALL random_function_ini
[1429]1511       
[1400]1512       IF ( random_generator == 'random-parallel' )  THEN
[2172]1513          CALL init_parallel_random_generator(nx, ny, nys, nyn, nxl, nxr)
[1400]1514       ENDIF
1515!
[1179]1516!--    Set the reference state to be used in the buoyancy terms (for ocean runs
1517!--    the reference state will be set (overwritten) in init_ocean)
1518       IF ( use_single_reference_value )  THEN
[1788]1519          IF (  .NOT.  humidity )  THEN
[1179]1520             ref_state(:) = pt_reference
1521          ELSE
1522             ref_state(:) = vpt_reference
1523          ENDIF
1524       ELSE
[1788]1525          IF (  .NOT.  humidity )  THEN
[1179]1526             ref_state(:) = pt_init(:)
1527          ELSE
1528             ref_state(:) = vpt(:,nys,nxl)
1529          ENDIF
1530       ENDIF
[152]1531
1532!
[707]1533!--    For the moment, vertical velocity is zero
[1340]1534       w = 0.0_wp
[1]1535
1536!
1537!--    Initialize array sums (must be defined in first call of pres)
[1340]1538       sums = 0.0_wp
[1]1539
1540!
[707]1541!--    In case of iterative solvers, p must get an initial value
[1575]1542       IF ( psolver(1:9) == 'multigrid'  .OR.  psolver == 'sor' )  p = 0.0_wp
[707]1543
1544!
[72]1545!--    Treating cloud physics, liquid water content and precipitation amount
1546!--    are zero at beginning of the simulation
1547       IF ( cloud_physics )  THEN
[1340]1548          ql = 0.0_wp
[1822]1549          qc = 0.0_wp
1550
1551          precipitation_amount = 0.0_wp
[72]1552       ENDIF
[673]1553!
[1]1554!--    Impose vortex with vertical axis on the initial velocity profile
1555       IF ( INDEX( initializing_actions, 'initialize_vortex' ) /= 0 )  THEN
1556          CALL init_rankine
1557       ENDIF
1558
1559!
1560!--    Impose temperature anomaly (advection test only)
1561       IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0 )  THEN
1562          CALL init_pt_anomaly
1563       ENDIF
1564
1565!
1566!--    If required, change the surface temperature at the start of the 3D run
[1340]1567       IF ( pt_surface_initial_change /= 0.0_wp )  THEN
[1]1568          pt(nzb,:,:) = pt(nzb,:,:) + pt_surface_initial_change
1569       ENDIF
1570
1571!
1572!--    If required, change the surface humidity/scalar at the start of the 3D
1573!--    run
[1960]1574       IF ( humidity  .AND.  q_surface_initial_change /= 0.0_wp )              &
[1]1575          q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change
[1960]1576         
1577       IF ( passive_scalar .AND.  s_surface_initial_change /= 0.0_wp )         &
1578          s(nzb,:,:) = s(nzb,:,:) + s_surface_initial_change
1579       
[1]1580
1581!
1582!--    Initialize old and new time levels.
[2696]1583       tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
1584       pt_p = pt; u_p = u; v_p = v; w_p = w
[1]1585
[1960]1586       IF ( humidity  )  THEN
[1340]1587          tq_m = 0.0_wp
[1]1588          q_p = q
[2292]1589          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1590             tqc_m = 0.0_wp
1591             qc_p  = qc
1592             tnc_m = 0.0_wp
1593             nc_p  = nc
1594          ENDIF
[1822]1595          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1596             tqr_m = 0.0_wp
[1822]1597             qr_p  = qr
[1340]1598             tnr_m = 0.0_wp
[1822]1599             nr_p  = nr
[1053]1600          ENDIF
[1]1601       ENDIF
[1960]1602       
1603       IF ( passive_scalar )  THEN
1604          ts_m = 0.0_wp
1605          s_p  = s
1606       ENDIF       
[1]1607
[94]1608       IF ( ocean )  THEN
[1340]1609          tsa_m = 0.0_wp
[94]1610          sa_p  = sa
1611       ENDIF
[667]1612       
[1402]1613       CALL location_message( 'finished', .TRUE. )
[94]1614
[1788]1615    ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data'  .OR.         &
[2232]1616             TRIM( initializing_actions ) == 'cyclic_fill' )                   &
[1]1617    THEN
[1384]1618
[1402]1619       CALL location_message( 'initializing in case of restart / cyclic_fill', &
1620                              .FALSE. )
[1]1621!
[2232]1622!--    Initialize surface elements and its attributes, e.g. heat- and
1623!--    momentumfluxes, roughness, scaling parameters. As number of surface
1624!--    elements might be different between runs, e.g. in case of cyclic fill,
1625!--    and not all surface elements are read, surface elements need to be
1626!--    initialized before.     
1627       CALL init_surfaces
1628!
[767]1629!--    When reading data for cyclic fill of 3D prerun data files, read
1630!--    some of the global variables from the restart file which are required
1631!--    for initializing the inflow
[328]1632       IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
[559]1633
[759]1634          DO  i = 0, io_blocks-1
1635             IF ( i == io_group )  THEN
[2894]1636                CALL rrd_read_parts_of_global
[759]1637             ENDIF
1638#if defined( __parallel )
1639             CALL MPI_BARRIER( comm2d, ierr )
1640#endif
1641          ENDDO
[328]1642
[767]1643       ENDIF
1644
[151]1645!
[2894]1646!--    Read processor specific binary data from restart file
[767]1647       DO  i = 0, io_blocks-1
1648          IF ( i == io_group )  THEN
[2894]1649             CALL rrd_local
[767]1650          ENDIF
1651#if defined( __parallel )
1652          CALL MPI_BARRIER( comm2d, ierr )
1653#endif
1654       ENDDO
1655
[328]1656!
[2550]1657!--    In case of complex terrain and cyclic fill method as initialization,
1658!--    shift initial data in the vertical direction for each point in the
1659!--    x-y-plane depending on local surface height
1660       IF ( complex_terrain  .AND.                                             &
1661            TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1662          DO  i = nxlg, nxrg
1663             DO  j = nysg, nyng
[2698]1664                nz_u_shift = get_topography_top_index_ji( j, i, 'u' )
1665                nz_v_shift = get_topography_top_index_ji( j, i, 'v' )
1666                nz_w_shift = get_topography_top_index_ji( j, i, 'w' )
1667                nz_s_shift = get_topography_top_index_ji( j, i, 's' )
[2550]1668
1669                u(nz_u_shift:nzt+1,j,i)  = u(0:nzt+1-nz_u_shift,j,i)               
1670
1671                v(nz_v_shift:nzt+1,j,i)  = v(0:nzt+1-nz_v_shift,j,i)
1672
1673                w(nz_w_shift:nzt+1,j,i)  = w(0:nzt+1-nz_w_shift,j,i)
1674
1675                p(nz_s_shift:nzt+1,j,i)  =  p(0:nzt+1-nz_s_shift,j,i)
1676                pt(nz_s_shift:nzt+1,j,i) = pt(0:nzt+1-nz_s_shift,j,i)
1677             ENDDO
1678          ENDDO
1679       ENDIF
1680
1681!
[767]1682!--    Initialization of the turbulence recycling method
[1788]1683       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.               &
[767]1684            turbulent_inflow )  THEN
1685!
1686!--       First store the profiles to be used at the inflow.
1687!--       These profiles are the (temporally) and horizontally averaged vertical
1688!--       profiles from the prerun. Alternatively, prescribed profiles
1689!--       for u,v-components can be used.
[1960]1690          ALLOCATE( mean_inflow_profiles(nzb:nzt+1,7) )
[151]1691
[767]1692          IF ( use_prescribed_profile_data )  THEN
1693             mean_inflow_profiles(:,1) = u_init            ! u
1694             mean_inflow_profiles(:,2) = v_init            ! v
1695          ELSE
[328]1696             mean_inflow_profiles(:,1) = hom_sum(:,1,0)    ! u
1697             mean_inflow_profiles(:,2) = hom_sum(:,2,0)    ! v
[767]1698          ENDIF
1699          mean_inflow_profiles(:,4) = hom_sum(:,4,0)       ! pt
[1960]1700          IF ( humidity )                                                      &
1701             mean_inflow_profiles(:,6) = hom_sum(:,41,0)   ! q
1702          IF ( passive_scalar )                                                &
1703             mean_inflow_profiles(:,7) = hom_sum(:,115,0)   ! s
[2550]1704!
1705!--       In case of complex terrain, determine vertical displacement at inflow
1706!--       boundary and adjust mean inflow profiles
1707          IF ( complex_terrain )  THEN
1708             IF ( nxlg <= 0 .AND. nxrg >= 0 .AND. nysg <= 0 .AND. nyng >= 0 )  THEN
[2698]1709                nz_u_shift_l = get_topography_top_index_ji( 0, 0, 'u' )
1710                nz_v_shift_l = get_topography_top_index_ji( 0, 0, 'v' )
1711                nz_w_shift_l = get_topography_top_index_ji( 0, 0, 'w' )
1712                nz_s_shift_l = get_topography_top_index_ji( 0, 0, 's' )
[2550]1713             ELSE
1714                nz_u_shift_l = 0
1715                nz_v_shift_l = 0
1716                nz_w_shift_l = 0
1717                nz_s_shift_l = 0
1718             ENDIF
[151]1719
[2550]1720#if defined( __parallel )
1721             CALL MPI_ALLREDUCE(nz_u_shift_l, nz_u_shift, 1, MPI_INTEGER,      &
1722                                MPI_MAX, comm2d, ierr)
1723             CALL MPI_ALLREDUCE(nz_v_shift_l, nz_v_shift, 1, MPI_INTEGER,      &
1724                                MPI_MAX, comm2d, ierr)
1725             CALL MPI_ALLREDUCE(nz_w_shift_l, nz_w_shift, 1, MPI_INTEGER,      & 
1726                                MPI_MAX, comm2d, ierr)
1727             CALL MPI_ALLREDUCE(nz_s_shift_l, nz_s_shift, 1, MPI_INTEGER,      &
1728                                MPI_MAX, comm2d, ierr)
1729#else
1730             nz_u_shift = nz_u_shift_l
1731             nz_v_shift = nz_v_shift_l
1732             nz_w_shift = nz_w_shift_l
1733             nz_s_shift = nz_s_shift_l
1734#endif
1735
1736             mean_inflow_profiles(:,1) = 0.0_wp
1737             mean_inflow_profiles(nz_u_shift:nzt+1,1) = hom_sum(0:nzt+1-nz_u_shift,1,0)  ! u
1738
1739             mean_inflow_profiles(:,2) = 0.0_wp
1740             mean_inflow_profiles(nz_v_shift:nzt+1,2) = hom_sum(0:nzt+1-nz_v_shift,2,0)  ! v
1741
1742             mean_inflow_profiles(nz_s_shift:nzt+1,4) = hom_sum(0:nzt+1-nz_s_shift,4,0)  ! pt
1743
1744          ENDIF
1745
[151]1746!
[767]1747!--       If necessary, adjust the horizontal flow field to the prescribed
1748!--       profiles
1749          IF ( use_prescribed_profile_data )  THEN
1750             DO  i = nxlg, nxrg
[667]1751                DO  j = nysg, nyng
[328]1752                   DO  k = nzb, nzt+1
[767]1753                      u(k,j,i) = u(k,j,i) - hom_sum(k,1,0) + u_init(k)
1754                      v(k,j,i) = v(k,j,i) - hom_sum(k,2,0) + v_init(k)
[328]1755                   ENDDO
[151]1756                ENDDO
[767]1757             ENDDO
1758          ENDIF
[151]1759
1760!
[767]1761!--       Use these mean profiles at the inflow (provided that Dirichlet
1762!--       conditions are used)
1763          IF ( inflow_l )  THEN
1764             DO  j = nysg, nyng
1765                DO  k = nzb, nzt+1
1766                   u(k,j,nxlg:-1)  = mean_inflow_profiles(k,1)
1767                   v(k,j,nxlg:-1)  = mean_inflow_profiles(k,2)
[1340]1768                   w(k,j,nxlg:-1)  = 0.0_wp
[767]1769                   pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4)
[1960]1770                   IF ( humidity )                                             &
[1615]1771                      q(k,j,nxlg:-1)  = mean_inflow_profiles(k,6)
[1960]1772                   IF ( passive_scalar )                                       &
1773                      s(k,j,nxlg:-1)  = mean_inflow_profiles(k,7)                     
[767]1774                ENDDO
1775             ENDDO
1776          ENDIF
1777
[151]1778!
[767]1779!--       Calculate the damping factors to be used at the inflow. For a
1780!--       turbulent inflow the turbulent fluctuations have to be limited
1781!--       vertically because otherwise the turbulent inflow layer will grow
1782!--       in time.
[1340]1783          IF ( inflow_damping_height == 9999999.9_wp )  THEN
[767]1784!
1785!--          Default: use the inversion height calculated by the prerun; if
1786!--          this is zero, inflow_damping_height must be explicitly
1787!--          specified.
[1340]1788             IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0_wp )  THEN
[767]1789                inflow_damping_height = hom_sum(nzb+6,pr_palm,0)
1790             ELSE
[1788]1791                WRITE( message_string, * ) 'inflow_damping_height must be ',   &
1792                     'explicitly specified because&the inversion height ',     &
[767]1793                     'calculated by the prerun is zero.'
1794                CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 )
[292]1795             ENDIF
[151]1796
[767]1797          ENDIF
1798
[1340]1799          IF ( inflow_damping_width == 9999999.9_wp )  THEN
[151]1800!
[767]1801!--          Default for the transition range: one tenth of the undamped
1802!--          layer
[1340]1803             inflow_damping_width = 0.1_wp * inflow_damping_height
[151]1804
[767]1805          ENDIF
[151]1806
[767]1807          ALLOCATE( inflow_damping_factor(nzb:nzt+1) )
[151]1808
[767]1809          DO  k = nzb, nzt+1
[151]1810
[767]1811             IF ( zu(k) <= inflow_damping_height )  THEN
[1340]1812                inflow_damping_factor(k) = 1.0_wp
[996]1813             ELSEIF ( zu(k) <= ( inflow_damping_height + inflow_damping_width ) )  THEN
[1340]1814                inflow_damping_factor(k) = 1.0_wp -                            &
[996]1815                                           ( zu(k) - inflow_damping_height ) / &
1816                                           inflow_damping_width
[767]1817             ELSE
[1340]1818                inflow_damping_factor(k) = 0.0_wp
[767]1819             ENDIF
[151]1820
[767]1821          ENDDO
[151]1822
[147]1823       ENDIF
1824
[152]1825!
[2696]1826!--    Inside buildings set velocities back to zero
[1788]1827       IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND.                &
[359]1828            topography /= 'flat' )  THEN
1829!
[2696]1830!--       Inside buildings set velocities back to zero.
1831!--       Other scalars (pt, q, s, p, sa, ...) are ignored at present,
[359]1832!--       maybe revise later.
[1001]1833          DO  i = nxlg, nxrg
1834             DO  j = nysg, nyng
[2232]1835                DO  k = nzb, nzt
1836                   u(k,j,i)     = MERGE( u(k,j,i), 0.0_wp,                     &
1837                                         BTEST( wall_flags_0(k,j,i), 1 ) )
1838                   v(k,j,i)     = MERGE( v(k,j,i), 0.0_wp,                     &
1839                                         BTEST( wall_flags_0(k,j,i), 2 ) )
1840                   w(k,j,i)     = MERGE( w(k,j,i), 0.0_wp,                     &
1841                                         BTEST( wall_flags_0(k,j,i), 3 ) )
1842                ENDDO
[359]1843             ENDDO
[1001]1844          ENDDO
[359]1845
1846       ENDIF
1847
1848!
[1]1849!--    Calculate initial temperature field and other constants used in case
1850!--    of a sloping surface
1851       IF ( sloping_surface )  CALL init_slope
1852
1853!
1854!--    Initialize new time levels (only done in order to set boundary values
1855!--    including ghost points)
[2696]1856       pt_p = pt; u_p = u; v_p = v; w_p = w
[1960]1857       IF ( humidity )  THEN
[1053]1858          q_p = q
[2292]1859          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1860             qc_p = qc
1861             nc_p = nc
1862          ENDIF
[1822]1863          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1053]1864             qr_p = qr
1865             nr_p = nr
1866          ENDIF
1867       ENDIF
[1960]1868       IF ( passive_scalar )  s_p  = s
1869       IF ( ocean          )  sa_p = sa
[1]1870
[181]1871!
1872!--    Allthough tendency arrays are set in prognostic_equations, they have
1873!--    have to be predefined here because they are used (but multiplied with 0)
1874!--    there before they are set.
[2696]1875       tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
[1960]1876       IF ( humidity )  THEN
[1340]1877          tq_m = 0.0_wp
[2292]1878          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1879             tqc_m = 0.0_wp
1880             tnc_m = 0.0_wp
1881          ENDIF
[1822]1882          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1883             tqr_m = 0.0_wp
1884             tnr_m = 0.0_wp
[1053]1885          ENDIF
1886       ENDIF
[1960]1887       IF ( passive_scalar )  ts_m  = 0.0_wp
1888       IF ( ocean          )  tsa_m = 0.0_wp
[2259]1889!
1890!--    Initialize synthetic turbulence generator in case of restart.
1891       IF ( TRIM( initializing_actions ) == 'read_restart_data'  .AND.         &
[2776]1892            use_syn_turb_gen )  CALL stg_init
[181]1893
[1402]1894       CALL location_message( 'finished', .TRUE. )
[1384]1895
[1]1896    ELSE
1897!
1898!--    Actually this part of the programm should not be reached
[254]1899       message_string = 'unknown initializing problem'
1900       CALL message( 'init_3d_model', 'PA0193', 1, 2, 0, 6, 0 )
[1]1901    ENDIF
1902
[2696]1903!
1904!-- Initialize TKE, Kh and Km
1905    CALL tcm_init
[151]1906
[2696]1907
[151]1908    IF (  TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
[1]1909!
[151]1910!--    Initialize old timelevels needed for radiation boundary conditions
1911       IF ( outflow_l )  THEN
1912          u_m_l(:,:,:) = u(:,:,1:2)
1913          v_m_l(:,:,:) = v(:,:,0:1)
1914          w_m_l(:,:,:) = w(:,:,0:1)
1915       ENDIF
1916       IF ( outflow_r )  THEN
1917          u_m_r(:,:,:) = u(:,:,nx-1:nx)
1918          v_m_r(:,:,:) = v(:,:,nx-1:nx)
1919          w_m_r(:,:,:) = w(:,:,nx-1:nx)
1920       ENDIF
1921       IF ( outflow_s )  THEN
1922          u_m_s(:,:,:) = u(:,0:1,:)
1923          v_m_s(:,:,:) = v(:,1:2,:)
1924          w_m_s(:,:,:) = w(:,0:1,:)
1925       ENDIF
1926       IF ( outflow_n )  THEN
1927          u_m_n(:,:,:) = u(:,ny-1:ny,:)
1928          v_m_n(:,:,:) = v(:,ny-1:ny,:)
1929          w_m_n(:,:,:) = w(:,ny-1:ny,:)
1930       ENDIF
[667]1931       
[151]1932    ENDIF
[680]1933
[667]1934!
1935!-- Calculate the initial volume flow at the right and north boundary
[709]1936    IF ( conserve_volume_flow )  THEN
[151]1937
[767]1938       IF ( use_prescribed_profile_data )  THEN
[667]1939
[1340]1940          volume_flow_initial_l = 0.0_wp
1941          volume_flow_area_l    = 0.0_wp
[732]1942
[667]1943          IF ( nxr == nx )  THEN
1944             DO  j = nys, nyn
[2232]1945                DO  k = nzb+1, nzt
[1788]1946                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +       &
[2232]1947                                              u_init(k) * dzw(k)               &
1948                                     * MERGE( 1.0_wp, 0.0_wp,                  &
1949                                              BTEST( wall_flags_0(k,j,nxr), 1 )&
1950                                            )
1951
1952                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)   &
1953                                     * MERGE( 1.0_wp, 0.0_wp,                  &
1954                                              BTEST( wall_flags_0(k,j,nxr), 1 )&
1955                                            )
[767]1956                ENDDO
1957             ENDDO
1958          ENDIF
1959         
1960          IF ( nyn == ny )  THEN
1961             DO  i = nxl, nxr
[2232]1962                DO  k = nzb+1, nzt
1963                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +       &
1964                                              v_init(k) * dzw(k)               &       
1965                                     * MERGE( 1.0_wp, 0.0_wp,                  &
1966                                              BTEST( wall_flags_0(k,nyn,i), 2 )&
1967                                            )
1968                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)   &       
1969                                     * MERGE( 1.0_wp, 0.0_wp,                  &
1970                                              BTEST( wall_flags_0(k,nyn,i), 2 )&
1971                                            )
[767]1972                ENDDO
1973             ENDDO
1974          ENDIF
1975
1976#if defined( __parallel )
1977          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
1978                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1979          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
1980                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1981
1982#else
1983          volume_flow_initial = volume_flow_initial_l
1984          volume_flow_area    = volume_flow_area_l
1985#endif 
1986
1987       ELSEIF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1988
[1340]1989          volume_flow_initial_l = 0.0_wp
1990          volume_flow_area_l    = 0.0_wp
[767]1991
1992          IF ( nxr == nx )  THEN
1993             DO  j = nys, nyn
[2232]1994                DO  k = nzb+1, nzt
[1788]1995                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +       &
[2232]1996                                              hom_sum(k,1,0) * dzw(k)          &
1997                                     * MERGE( 1.0_wp, 0.0_wp,                  &
1998                                              BTEST( wall_flags_0(k,j,nx), 1 ) &
1999                                            )
2000                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)   &
2001                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2002                                              BTEST( wall_flags_0(k,j,nx), 1 ) &
2003                                            )
[667]2004                ENDDO
2005             ENDDO
2006          ENDIF
2007         
2008          IF ( nyn == ny )  THEN
2009             DO  i = nxl, nxr
[2232]2010                DO  k = nzb+1, nzt
[1788]2011                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +       &
[2232]2012                                              hom_sum(k,2,0) * dzw(k)          &       
2013                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2014                                              BTEST( wall_flags_0(k,ny,i), 2 ) &
2015                                            )
2016                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)   &       
2017                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2018                                              BTEST( wall_flags_0(k,ny,i), 2 ) &
2019                                            )
[667]2020                ENDDO
2021             ENDDO
2022          ENDIF
2023
[732]2024#if defined( __parallel )
2025          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
2026                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
2027          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
2028                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
2029
2030#else
2031          volume_flow_initial = volume_flow_initial_l
2032          volume_flow_area    = volume_flow_area_l
2033#endif 
2034
[667]2035       ELSEIF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
2036
[1340]2037          volume_flow_initial_l = 0.0_wp
2038          volume_flow_area_l    = 0.0_wp
[732]2039
[667]2040          IF ( nxr == nx )  THEN
2041             DO  j = nys, nyn
[2232]2042                DO  k = nzb+1, nzt
2043                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +       &
2044                                              u(k,j,nx) * dzw(k)               &
2045                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2046                                              BTEST( wall_flags_0(k,j,nx), 1 ) &
2047                                            )
2048                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)   &
2049                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2050                                              BTEST( wall_flags_0(k,j,nx), 1 ) &
2051                                            )
[667]2052                ENDDO
2053             ENDDO
2054          ENDIF
2055         
2056          IF ( nyn == ny )  THEN
2057             DO  i = nxl, nxr
[2232]2058                DO  k = nzb+1, nzt
[1788]2059                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +       &
[2232]2060                                              v(k,ny,i) * dzw(k)               &       
2061                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2062                                              BTEST( wall_flags_0(k,ny,i), 2 ) &
2063                                            )
2064                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)   &       
2065                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2066                                              BTEST( wall_flags_0(k,ny,i), 2 ) &
2067                                            )
[667]2068                ENDDO
2069             ENDDO
2070          ENDIF
2071
2072#if defined( __parallel )
[732]2073          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
2074                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
2075          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
2076                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
[667]2077
2078#else
[732]2079          volume_flow_initial = volume_flow_initial_l
2080          volume_flow_area    = volume_flow_area_l
[667]2081#endif 
2082
[732]2083       ENDIF
2084
[151]2085!
[709]2086!--    In case of 'bulk_velocity' mode, volume_flow_initial is calculated
2087!--    from u|v_bulk instead
[680]2088       IF ( TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' )  THEN
2089          volume_flow_initial(1) = u_bulk * volume_flow_area(1)
2090          volume_flow_initial(2) = v_bulk * volume_flow_area(2)
2091       ENDIF
[667]2092
[680]2093    ENDIF
[2232]2094!
[2618]2095!-- Finally, if random_heatflux is set, disturb shf at horizontal
2096!-- surfaces. Actually, this should be done in surface_mod, where all other
2097!-- initializations of surface quantities are done. However, this
2098!-- would create a ring dependency, hence, it is done here. Maybe delete
2099!-- disturb_heatflux and tranfer the respective code directly into the
2100!-- initialization in surface_mod.         
[2232]2101    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
2102         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
[2618]2103 
[2232]2104       IF ( use_surface_fluxes  .AND.  constant_heatflux  .AND.                &
2105            random_heatflux )  THEN
2106          IF ( surf_def_h(0)%ns >= 1 )  CALL disturb_heatflux( surf_def_h(0) )
2107          IF ( surf_lsm_h%ns    >= 1 )  CALL disturb_heatflux( surf_lsm_h    )
2108          IF ( surf_usm_h%ns    >= 1 )  CALL disturb_heatflux( surf_usm_h    )
2109       ENDIF
2110    ENDIF
[680]2111
[787]2112!
[2696]2113!-- Before initializing further modules, compute total sum of active mask
2114!-- grid points and the mean surface level height for each statistic region.
2115!-- ngp_2dh: number of grid points of a horizontal cross section through the
2116!--          total domain
2117!-- ngp_3d:  number of grid points of the total domain
2118    ngp_2dh_outer_l   = 0
2119    ngp_2dh_outer     = 0
2120    ngp_2dh_s_inner_l = 0
2121    ngp_2dh_s_inner   = 0
2122    ngp_2dh_l         = 0
2123    ngp_2dh           = 0
2124    ngp_3d_inner_l    = 0.0_wp
2125    ngp_3d_inner      = 0
2126    ngp_3d            = 0
2127    ngp_sums          = ( nz + 2 ) * ( pr_palm + max_pr_user )
2128
2129    mean_surface_level_height   = 0.0_wp
2130    mean_surface_level_height_l = 0.0_wp
2131!
2132!-- Pre-set masks for regional statistics. Default is the total model domain.
2133!-- Ghost points are excluded because counting values at the ghost boundaries
2134!-- would bias the statistics
2135    rmask = 1.0_wp
2136    rmask(:,nxlg:nxl-1,:) = 0.0_wp;  rmask(:,nxr+1:nxrg,:) = 0.0_wp
2137    rmask(nysg:nys-1,:,:) = 0.0_wp;  rmask(nyn+1:nyng,:,:) = 0.0_wp
2138!
[2867]2139!-- User-defined initializing actions
2140    CALL user_init
2141!
[2696]2142!-- To do: New concept for these non-topography grid points!
2143    DO  sr = 0, statistic_regions
2144       DO  i = nxl, nxr
2145          DO  j = nys, nyn
2146             IF ( rmask(j,i,sr) == 1.0_wp )  THEN
2147!
2148!--             All xy-grid points
2149                ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1
2150!
2151!--             Determine mean surface-level height. In case of downward-
2152!--             facing walls are present, more than one surface level exist.
2153!--             In this case, use the lowest surface-level height.
2154                IF ( surf_def_h(0)%start_index(j,i) <=                         &
2155                     surf_def_h(0)%end_index(j,i) )  THEN
2156                   m = surf_def_h(0)%start_index(j,i)
2157                   k = surf_def_h(0)%k(m)
2158                   mean_surface_level_height_l(sr) =                           &
2159                                       mean_surface_level_height_l(sr) + zw(k-1)
2160                ENDIF
2161                IF ( surf_lsm_h%start_index(j,i) <=                            &
2162                     surf_lsm_h%end_index(j,i) )  THEN
2163                   m = surf_lsm_h%start_index(j,i)
2164                   k = surf_lsm_h%k(m)
2165                   mean_surface_level_height_l(sr) =                           &
2166                                       mean_surface_level_height_l(sr) + zw(k-1)
2167                ENDIF
2168                IF ( surf_usm_h%start_index(j,i) <=                            &
2169                     surf_usm_h%end_index(j,i) )  THEN
2170                   m = surf_usm_h%start_index(j,i)
2171                   k = surf_usm_h%k(m)
2172                   mean_surface_level_height_l(sr) =                           &
2173                                       mean_surface_level_height_l(sr) + zw(k-1)
2174                ENDIF
2175
2176                k_surf = k - 1
2177
2178                DO  k = nzb, nzt+1
2179!
2180!--                xy-grid points above topography
2181                   ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr)     +         &
2182                                  MERGE( 1, 0, BTEST( wall_flags_0(k,j,i), 24 ) )
2183
2184                   ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) +         &
2185                                  MERGE( 1, 0, BTEST( wall_flags_0(k,j,i), 22 ) )
2186
2187                ENDDO
2188!
2189!--             All grid points of the total domain above topography
2190                ngp_3d_inner_l(sr) = ngp_3d_inner_l(sr) + ( nz - k_surf + 2 )
2191
2192
2193
2194             ENDIF
2195          ENDDO
2196       ENDDO
2197    ENDDO
[2864]2198!
2199!-- Initialize arrays encompassing number of grid-points in inner and outer
2200!-- domains, statistic regions, etc. Mainly used for horizontal averaging
2201!-- of turbulence statistics. Please note, user_init must be called before
2202!-- doing this.   
[2696]2203    sr = statistic_regions + 1
2204#if defined( __parallel )
2205    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2206    CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM,    &
2207                        comm2d, ierr )
2208    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2209    CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr,   &
2210                        MPI_INTEGER, MPI_SUM, comm2d, ierr )
2211    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2212    CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0),          &
2213                        (nz+2)*sr, MPI_INTEGER, MPI_SUM, comm2d, ierr )
2214    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2215    CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner_tmp(0), sr, MPI_REAL,  &
2216                        MPI_SUM, comm2d, ierr )
2217    ngp_3d_inner = INT( ngp_3d_inner_tmp, KIND = SELECTED_INT_KIND( 18 ) )
2218    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2219    CALL MPI_ALLREDUCE( mean_surface_level_height_l(0),                        &
2220                        mean_surface_level_height(0), sr, MPI_REAL,            &
2221                        MPI_SUM, comm2d, ierr )
2222    mean_surface_level_height = mean_surface_level_height / REAL( ngp_2dh )
2223#else
2224    ngp_2dh         = ngp_2dh_l
2225    ngp_2dh_outer   = ngp_2dh_outer_l
2226    ngp_2dh_s_inner = ngp_2dh_s_inner_l
2227    ngp_3d_inner    = INT( ngp_3d_inner_l, KIND = SELECTED_INT_KIND( 18 ) )
2228    mean_surface_level_height = mean_surface_level_height_l / REAL( ngp_2dh_l )
2229#endif
2230
2231    ngp_3d = INT ( ngp_2dh, KIND = SELECTED_INT_KIND( 18 ) ) * &
2232             INT ( (nz + 2 ), KIND = SELECTED_INT_KIND( 18 ) )
2233
2234!
2235!-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics,
2236!-- buoyancy, etc. A zero value will occur for cases where all grid points of
2237!-- the respective subdomain lie below the surface topography
2238    ngp_2dh_outer   = MAX( 1, ngp_2dh_outer(:,:)   ) 
2239    ngp_3d_inner    = MAX( INT(1, KIND = SELECTED_INT_KIND( 18 )),             &
2240                           ngp_3d_inner(:) )
2241    ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) ) 
2242
2243    DEALLOCATE( mean_surface_level_height_l, ngp_2dh_l, ngp_2dh_outer_l,       &
2244                ngp_3d_inner_l, ngp_3d_inner_tmp )
2245
2246!
[2232]2247!-- Initialize surface forcing corresponding to large-scale forcing. Therein,
2248!-- initialize heat-fluxes, etc. via datatype. Revise it later!
2249    IF ( large_scale_forcing .AND. lsf_surf )  THEN
2250       IF ( use_surface_fluxes  .AND.  constant_heatflux )  THEN
2251          CALL ls_forcing_surf ( simulated_time )
2252       ENDIF
2253    ENDIF
2254!
[787]2255!-- Initialize quantities for special advections schemes
2256    CALL init_advec
[680]2257
[667]2258!
[680]2259!-- Impose random perturbation on the horizontal velocity field and then
2260!-- remove the divergences from the velocity field at the initial stage
[1788]2261    IF ( create_disturbances  .AND.  disturbance_energy_limit /= 0.0_wp  .AND. &
2262         TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
[680]2263         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
2264
[1402]2265       CALL location_message( 'creating initial disturbances', .FALSE. )
[2232]2266       CALL disturb_field( 'u', tend, u )
2267       CALL disturb_field( 'v', tend, v )
[1402]2268       CALL location_message( 'finished', .TRUE. )
[1384]2269
[1402]2270       CALL location_message( 'calling pressure solver', .FALSE. )
[680]2271       n_sor = nsor_ini
2272       CALL pres
2273       n_sor = nsor
[1402]2274       CALL location_message( 'finished', .TRUE. )
[1384]2275
[680]2276    ENDIF
2277
2278!
[1484]2279!-- If required, initialize quantities needed for the plant canopy model
[2007]2280    IF ( plant_canopy )  THEN
2281       CALL location_message( 'initializing plant canopy model', .FALSE. )   
2282       CALL pcm_init
2283       CALL location_message( 'finished', .TRUE. )
2284    ENDIF
[138]2285
2286!
[1]2287!-- If required, initialize dvrp-software
[1340]2288    IF ( dt_dvrp /= 9999999.9_wp )  CALL init_dvrp
[1]2289
[96]2290    IF ( ocean )  THEN
[1]2291!
[96]2292!--    Initialize quantities needed for the ocean model
2293       CALL init_ocean
[388]2294
[96]2295    ELSE
2296!
2297!--    Initialize quantities for handling cloud physics
[849]2298!--    This routine must be called before lpm_init, because
[96]2299!--    otherwise, array pt_d_t, needed in data_output_dvrp (called by
[849]2300!--    lpm_init) is not defined.
[96]2301       CALL init_cloud_physics
[1849]2302!
2303!--    Initialize bulk cloud microphysics
2304       CALL microphysics_init
[96]2305    ENDIF
[1]2306
2307!
2308!-- If required, initialize particles
[849]2309    IF ( particle_advection )  CALL lpm_init
[1]2310
[1585]2311!
2312!-- If required, initialize quantities needed for the LSM
2313    IF ( land_surface )  THEN
2314       CALL location_message( 'initializing land surface model', .FALSE. )
[1817]2315       CALL lsm_init
[1585]2316       CALL location_message( 'finished', .TRUE. )
2317    ENDIF
[1496]2318
[1]2319!
[2696]2320!-- If required, allocate USM and LSM surfaces
2321    IF ( urban_surface )  THEN
2322       CALL location_message( 'initializing and allocating urban surfaces', .FALSE. )
2323       CALL usm_allocate_surface
2324       CALL location_message( 'finished', .TRUE. )
2325    ENDIF
2326!
2327!-- If required, initialize urban surface model
2328    IF ( urban_surface )  THEN
2329       CALL location_message( 'initializing urban surface model', .FALSE. )
2330       CALL usm_init_urban_surface
2331       CALL location_message( 'finished', .TRUE. )
2332    ENDIF
2333
2334!
[1691]2335!-- Initialize surface layer (done after LSM as roughness length are required
2336!-- for initialization
2337    IF ( constant_flux_layer )  THEN
2338       CALL location_message( 'initializing surface layer', .FALSE. )
2339       CALL init_surface_layer_fluxes
2340       CALL location_message( 'finished', .TRUE. )
2341    ENDIF
2342
2343!
[2696]2344!-- If required, set chemical emissions
2345!-- (todo(FK): This should later on be CALLed time-dependently in init_3d_model)
2346    IF ( air_chemistry ) THEN
2347       CALL chem_emissions
2348    ENDIF
2349
2350!
2351!-- Initialize radiation processes
[1496]2352    IF ( radiation )  THEN
[2696]2353!
2354!--    If required, initialize radiation interactions between surfaces
[2920]2355!--    via sky-view factors. This must be done before radiation is initialized.
[2696]2356       IF ( radiation_interactions )  CALL radiation_interaction_init
2357
2358!
2359!--    Initialize radiation model
[1585]2360       CALL location_message( 'initializing radiation model', .FALSE. )
[1826]2361       CALL radiation_init
[1585]2362       CALL location_message( 'finished', .TRUE. )
[2696]2363
2364!
[2920]2365!--    Find all discretized apparent solar positions for radiation interaction.
2366!--    This must be done after radiation_init.
2367       IF ( radiation_interactions )  CALL radiation_presimulate_solar_pos
2368
2369!
[2696]2370!--    If required, read or calculate and write out the SVF
[2906]2371       IF ( radiation_interactions .AND. read_svf)  THEN
[2696]2372!
2373!--       Read sky-view factors and further required data from file
2374          CALL location_message( '    Start reading SVF from file', .FALSE. )
2375          CALL radiation_read_svf()
2376          CALL location_message( '    Reading SVF from file has finished', .TRUE. )
2377
[2906]2378       ELSEIF ( radiation_interactions .AND. .NOT. read_svf)  THEN
[2696]2379!
2380!--       calculate SFV and CSF
2381          CALL location_message( '    Start calculation of SVF', .FALSE. )
2382          CALL radiation_calc_svf()
2383          CALL location_message( '    Calculation of SVF has finished', .TRUE. )
2384       ENDIF
2385
[2906]2386       IF ( radiation_interactions .AND. write_svf)  THEN
[2696]2387!
2388!--       Write svf, csf svfsurf and csfsurf data to file
[2906]2389          CALL location_message( '    Start writing SVF in file', .FALSE. )
[2696]2390          CALL radiation_write_svf()
[2906]2391          CALL location_message( '    Writing SVF in file has finished', .TRUE. )
[2696]2392       ENDIF
2393
2394!
2395!--    Adjust radiative fluxes. In case of urban and land surfaces, also
2396!--    call an initial interaction.
2397       CALL radiation_control 
2398       IF ( radiation_interactions )  THEN
2399          CALL radiation_interaction
2400       ENDIF
[1496]2401    ENDIF
[2270]2402   
[1914]2403!
[2270]2404!-- Temporary solution to add LSM and radiation time series to the default
2405!-- output
2406    IF ( land_surface  .OR.  radiation )  THEN
2407       IF ( TRIM( radiation_scheme ) == 'rrtmg' )  THEN
2408          dots_num = dots_num + 15
2409       ELSE
2410          dots_num = dots_num + 11
2411       ENDIF
2412    ENDIF
2413   
[2007]2414
[2696]2415
[2007]2416!
[1914]2417!-- If required, initialize quantities needed for the wind turbine model
2418    IF ( wind_turbine )  THEN
2419       CALL location_message( 'initializing wind turbine model', .FALSE. )
2420       CALL wtm_init
2421       CALL location_message( 'finished', .TRUE. )
2422    ENDIF
[1496]2423
[2817]2424!
2425!-- If required, initialize quantities needed for the gust module
2426    IF ( gust_module_enabled )  THEN
2427       CALL gust_init( dots_label, dots_unit, dots_num, dots_max )
2428    ENDIF
[1914]2429
[1496]2430!
[673]2431!-- Initialize the ws-scheme.   
2432    IF ( ws_scheme_sca .OR. ws_scheme_mom )  CALL ws_init       
[1]2433
2434!
[709]2435!-- Setting weighting factors for calculation of perturbation pressure
[1762]2436!-- and turbulent quantities from the RK substeps
[709]2437    IF ( TRIM(timestep_scheme) == 'runge-kutta-3' )  THEN      ! for RK3-method
2438
[1322]2439       weight_substep(1) = 1._wp/6._wp
2440       weight_substep(2) = 3._wp/10._wp
2441       weight_substep(3) = 8._wp/15._wp
[709]2442
[1322]2443       weight_pres(1)    = 1._wp/3._wp
2444       weight_pres(2)    = 5._wp/12._wp
2445       weight_pres(3)    = 1._wp/4._wp
[709]2446
2447    ELSEIF ( TRIM(timestep_scheme) == 'runge-kutta-2' )  THEN  ! for RK2-method
2448
[1322]2449       weight_substep(1) = 1._wp/2._wp
2450       weight_substep(2) = 1._wp/2._wp
[673]2451         
[1322]2452       weight_pres(1)    = 1._wp/2._wp
2453       weight_pres(2)    = 1._wp/2._wp       
[709]2454
[1001]2455    ELSE                                     ! for Euler-method
[709]2456
[1340]2457       weight_substep(1) = 1.0_wp     
2458       weight_pres(1)    = 1.0_wp                   
[709]2459
[673]2460    ENDIF
2461
2462!
[1]2463!-- Initialize Rayleigh damping factors
[1340]2464    rdf    = 0.0_wp
2465    rdf_sc = 0.0_wp
2466    IF ( rayleigh_damping_factor /= 0.0_wp )  THEN
[1788]2467       IF (  .NOT.  ocean )  THEN
[108]2468          DO  k = nzb+1, nzt
2469             IF ( zu(k) >= rayleigh_damping_height )  THEN
[1788]2470                rdf(k) = rayleigh_damping_factor *                             &
[1340]2471                      ( SIN( pi * 0.5_wp * ( zu(k) - rayleigh_damping_height ) &
[1788]2472                             / ( zu(nzt) - rayleigh_damping_height ) )         &
[1]2473                      )**2
[108]2474             ENDIF
2475          ENDDO
2476       ELSE
2477          DO  k = nzt, nzb+1, -1
2478             IF ( zu(k) <= rayleigh_damping_height )  THEN
[1788]2479                rdf(k) = rayleigh_damping_factor *                             &
[1340]2480                      ( SIN( pi * 0.5_wp * ( rayleigh_damping_height - zu(k) ) &
[1788]2481                             / ( rayleigh_damping_height - zu(nzb+1) ) )       &
[108]2482                      )**2
2483             ENDIF
2484          ENDDO
2485       ENDIF
[1]2486    ENDIF
[785]2487    IF ( scalar_rayleigh_damping )  rdf_sc = rdf
[1]2488
2489!
[240]2490!-- Initialize the starting level and the vertical smoothing factor used for
2491!-- the external pressure gradient
[1340]2492    dp_smooth_factor = 1.0_wp
[240]2493    IF ( dp_external )  THEN
2494!
2495!--    Set the starting level dp_level_ind_b only if it has not been set before
2496!--    (e.g. in init_grid).
2497       IF ( dp_level_ind_b == 0 )  THEN
2498          ind_array = MINLOC( ABS( dp_level_b - zu ) )
2499          dp_level_ind_b = ind_array(1) - 1 + nzb 
2500                                        ! MINLOC uses lower array bound 1
2501       ENDIF
2502       IF ( dp_smooth )  THEN
[1340]2503          dp_smooth_factor(:dp_level_ind_b) = 0.0_wp
[240]2504          DO  k = dp_level_ind_b+1, nzt
[1340]2505             dp_smooth_factor(k) = 0.5_wp * ( 1.0_wp + SIN( pi *               &
2506                        ( REAL( k - dp_level_ind_b, KIND=wp ) /                &
2507                          REAL( nzt - dp_level_ind_b, KIND=wp ) - 0.5_wp ) ) )
[240]2508          ENDDO
2509       ENDIF
2510    ENDIF
2511
2512!
[978]2513!-- Initialize damping zone for the potential temperature in case of
2514!-- non-cyclic lateral boundaries. The damping zone has the maximum value
2515!-- at the inflow boundary and decreases to zero at pt_damping_width.
[1340]2516    ptdf_x = 0.0_wp
2517    ptdf_y = 0.0_wp
[1159]2518    IF ( bc_lr_dirrad )  THEN
[996]2519       DO  i = nxl, nxr
[978]2520          IF ( ( i * dx ) < pt_damping_width )  THEN
[1340]2521             ptdf_x(i) = pt_damping_factor * ( SIN( pi * 0.5_wp *              &
2522                            REAL( pt_damping_width - i * dx, KIND=wp ) / (     &
[1788]2523                            REAL( pt_damping_width, KIND=wp ) ) ) )**2 
[73]2524          ENDIF
2525       ENDDO
[1159]2526    ELSEIF ( bc_lr_raddir )  THEN
[996]2527       DO  i = nxl, nxr
[978]2528          IF ( ( i * dx ) > ( nx * dx - pt_damping_width ) )  THEN
[1322]2529             ptdf_x(i) = pt_damping_factor *                                   &
[1340]2530                         SIN( pi * 0.5_wp *                                    &
2531                                 ( ( i - nx ) * dx + pt_damping_width ) /      &
2532                                 REAL( pt_damping_width, KIND=wp ) )**2
[73]2533          ENDIF
[978]2534       ENDDO 
[1159]2535    ELSEIF ( bc_ns_dirrad )  THEN
[996]2536       DO  j = nys, nyn
[978]2537          IF ( ( j * dy ) > ( ny * dy - pt_damping_width ) )  THEN
[1322]2538             ptdf_y(j) = pt_damping_factor *                                   &
[1340]2539                         SIN( pi * 0.5_wp *                                    &
2540                                 ( ( j - ny ) * dy + pt_damping_width ) /      &
2541                                 REAL( pt_damping_width, KIND=wp ) )**2
[1]2542          ENDIF
[978]2543       ENDDO 
[1159]2544    ELSEIF ( bc_ns_raddir )  THEN
[996]2545       DO  j = nys, nyn
[978]2546          IF ( ( j * dy ) < pt_damping_width )  THEN
[1322]2547             ptdf_y(j) = pt_damping_factor *                                   &
[1340]2548                         SIN( pi * 0.5_wp *                                    &
2549                                ( pt_damping_width - j * dy ) /                &
2550                                REAL( pt_damping_width, KIND=wp ) )**2
[1]2551          ENDIF
[73]2552       ENDDO
[1]2553    ENDIF
2554!
[2864]2555!-- Check if maximum number of allowed timeseries is exceeded
[51]2556    IF ( dots_num > dots_max )  THEN
[1788]2557       WRITE( message_string, * ) 'number of time series quantities exceeds',  &
2558                                  ' its maximum of dots_max = ', dots_max,     &
[254]2559                                  ' &Please increase dots_max in modules.f90.'
2560       CALL message( 'init_3d_model', 'PA0194', 1, 2, 0, 6, 0 )   
[51]2561    ENDIF
2562
[1]2563!
2564!-- Input binary data file is not needed anymore. This line must be placed
2565!-- after call of user_init!
2566    CALL close_file( 13 )
[2934]2567!
2568!-- In case of nesting, put an barrier to assure that all parent and child
2569!-- domains finished initialization.
2570#if defined( __parallel )
2571    IF ( nested_run )  CALL MPI_BARRIER( MPI_COMM_WORLD, ierr )
2572#endif
[1]2573
[2934]2574
[1402]2575    CALL location_message( 'leaving init_3d_model', .TRUE. )
[1]2576
2577 END SUBROUTINE init_3d_model
Note: See TracBrowser for help on using the repository browser.