source: palm/trunk/SOURCE/time_integration.f90 @ 3298

Last change on this file since 3298 was 3298, checked in by kanani, 6 years ago

Merge chemistry branch at r3297 to trunk

  • Property svn:keywords set to Id
File size: 56.1 KB
Line 
1!> @file time_integration.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
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.
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!
17! Copyright 1997-2018 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: time_integration.f90 3298 2018-10-02 12:21:11Z kanani $
27! - Formatting, clean-up, comments (kanani)
28! - Added CALL to chem_emissions_setup (Russo)
29! - Code added for decycling chemistry (basit)
30!
31! 3294 2018-10-01 02:37:10Z raasch
32! changes concerning modularization of ocean option
33!
34! 3274 2018-09-24 15:42:55Z knoop
35! Modularization of all bulk cloud physics code components
36!
37! 3241 2018-09-12 15:02:00Z raasch
38! unused variables removed
39!
40! 3198 2018-08-15 09:23:10Z sward
41! Added multi_agent_system_end; defined start time for MAS relative to
42! time_since_reference_point
43!
44! 3183 2018-07-27 14:25:55Z suehring
45! Replace simulated_time by time_since_reference_point in COSMO nesting mode.
46! Rename subroutines and variables in COSMO nesting mode
47!
48! 3182 2018-07-27 13:36:03Z suehring
49! Added multi agent system
50!
51! 3042 2018-05-25 10:44:37Z schwenkel
52! Changed the name specific humidity to mixing ratio
53!
54! 3040 2018-05-25 10:22:08Z schwenkel
55! Fixed bug in IF statement
56! Ensure that the time when calling the radiation to be the time step of the
57! pre-calculated time when first calculate the positions of the sun
58!
59! 3004 2018-04-27 12:33:25Z Giersch
60! First call of flow_statistics has been removed. It is already called in
61! run_control itself
62!
63! 2984 2018-04-18 11:51:30Z hellstea
64! CALL pmci_ensure_nest_mass_conservation is removed (so far only commented out)
65! as seemingly unnecessary.
66!
67! 2941 2018-04-03 11:54:58Z kanani
68! Deduct spinup_time from RUN_CONTROL output of main 3d run
69! (use time_since_reference_point instead of simulated_time)
70!
71! 2938 2018-03-27 15:52:42Z suehring
72! Nesting of dissipation rate in case of RANS mode and TKE-e closure is applied
73!
74! 2936 2018-03-27 14:49:27Z suehring
75! Little formatting adjustment.
76!
77! 2817 2018-02-19 16:32:21Z knoop
78! Preliminary gust module interface implemented
79!
80! 2801 2018-02-14 16:01:55Z thiele
81! Changed lpm from subroutine to module.
82! Introduce particle transfer in nested models.
83!
84! 2776 2018-01-31 10:44:42Z Giersch
85! Variable use_synthetic_turbulence_generator has been abbreviated
86!
87! 2773 2018-01-30 14:12:54Z suehring
88! - Nesting for chemical species
89!
90! 2766 2018-01-22 17:17:47Z kanani
91! Removed preprocessor directive __chem
92!
93! 2718 2018-01-02 08:49:38Z maronga
94! Corrected "Former revisions" section
95!
96! 2696 2017-12-14 17:12:51Z kanani
97! - Change in file header (GPL part)
98! - Implementation of uv exposure model (FK)
99! - Moved vnest_boundary_conds_khkm from tcm_diffusivities to here (TG)
100! - renamed diffusivities to tcm_diffusivities (TG)
101! - implement prognostic equation for diss (TG)
102! - Moved/commented CALL to chem_emissions (FK)
103! - Added CALL to chem_emissions (FK)
104! - Implementation of chemistry module (FK)
105! - Calls for setting boundary conditions in USM and LSM (MS)
106! - Large-scale forcing with larger-scale models implemented (MS)
107! - Rename usm_radiation into radiation_interactions; merge with branch
108!   radiation (MS)
109! - added call for usm_green_heat_model for green building surfaces (RvT)
110! - added call for usm_temperature_near_surface for use in indoor model (RvT)
111!
112! 2617 2017-11-16 12:47:24Z suehring
113! Bugfix, assure that the reference state does not become zero.
114!
115! 2563 2017-10-19 15:36:10Z Giersch
116! Variable wind_turbine moved to module control_parameters
117!
118! 2365 2017-08-21 14:59:59Z kanani
119! Vertical grid nesting implemented (SadiqHuq)
120!
121! 2320 2017-07-21 12:47:43Z suehring
122! Set bottom boundary conditions after nesting interpolation and anterpolation
123!
124! 2299 2017-06-29 10:14:38Z maronga
125! Call of soil model adjusted
126!
127! 2292 2017-06-20 09:51:42Z schwenkel
128! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
129! includes two more prognostic equations for cloud drop concentration (nc) 
130! and cloud water content (qc).
131!
132! 2271 2017-06-09 12:34:55Z sward
133! Start timestep message changed
134!
135! 2259 2017-06-08 09:09:11Z gronemeier
136! Implemented synthetic turbulence generator
137!
138! 2233 2017-05-30 18:08:54Z suehring
139!
140! 2232 2017-05-30 17:47:52Z suehring
141! Adjustments to new topography and surface concept
142! Modify passed parameters for disturb_field
143!
144! 2178 2017-03-17 11:07:39Z hellstea
145! Setting perturbations at all times near inflow boundary is removed
146! in case of nested boundaries
147!
148! 2174 2017-03-13 08:18:57Z maronga
149! Added support for nesting with cloud microphysics
150!
151! 2118 2017-01-17 16:38:49Z raasch
152! OpenACC directives and related code removed
153!
154! 2050 2016-11-08 15:00:55Z gronemeier
155! Implement turbulent outflow condition
156!
157! 2031 2016-10-21 15:11:58Z knoop
158! renamed variable rho to rho_ocean
159!
160! 2011 2016-09-19 17:29:57Z kanani
161! Flag urban_surface is now defined in module control_parameters,
162! removed commented CALLs of global_min_max.
163!
164! 2007 2016-08-24 15:47:17Z kanani
165! Added CALLs for new urban surface model
166!
167! 2000 2016-08-20 18:09:15Z knoop
168! Forced header and separation lines into 80 columns
169!
170! 1976 2016-07-27 13:28:04Z maronga
171! Simplified calls to radiation model
172!
173! 1960 2016-07-12 16:34:24Z suehring
174! Separate humidity and passive scalar
175!
176! 1957 2016-07-07 10:43:48Z suehring
177! flight module added
178!
179! 1919 2016-05-27 14:51:23Z raasch
180! Initial version of purely vertical nesting introduced.
181!
182! 1918 2016-05-27 14:35:57Z raasch
183! determination of time step moved to the end of the time step loop,
184! the first time step is now always calculated before the time step loop (i.e.
185! also in case of restart runs)
186!
187! 1914 2016-05-26 14:44:07Z witha
188! Added call for wind turbine model
189!
190! 1878 2016-04-19 12:30:36Z hellstea
191! Synchronization for nested runs rewritten
192!
193! 1853 2016-04-11 09:00:35Z maronga
194! Adjusted for use with radiation_scheme = constant
195!
196! 1849 2016-04-08 11:33:18Z hoffmann
197! Adapted for modularization of microphysics
198!
199! 1833 2016-04-07 14:23:03Z raasch
200! spectrum renamed spectra_mod, spectra related variables moved to spectra_mod
201!
202! 1831 2016-04-07 13:15:51Z hoffmann
203! turbulence renamed collision_turbulence
204!
205! 1822 2016-04-07 07:49:42Z hoffmann
206! icloud_scheme replaced by microphysics_*
207!
208! 1808 2016-04-05 19:44:00Z raasch
209! output message in case unscheduled radiation calls removed
210!
211! 1797 2016-03-21 16:50:28Z raasch
212! introduction of different datatransfer modes
213!
214! 1791 2016-03-11 10:41:25Z raasch
215! call of pmci_update_new removed
216!
217! 1786 2016-03-08 05:49:27Z raasch
218! +module spectrum
219!
220! 1783 2016-03-06 18:36:17Z raasch
221! switch back of netcdf data format for mask output moved to the mask output
222! routine
223!
224! 1781 2016-03-03 15:12:23Z raasch
225! some pmc calls removed at the beginning (before timeloop),
226! pmc initialization moved to the main program
227!
228! 1764 2016-02-28 12:45:19Z raasch
229! PMC_ACTIVE flags removed,
230! bugfix: nest synchronization after first call of timestep
231!
232! 1762 2016-02-25 12:31:13Z hellstea
233! Introduction of nested domain feature
234!
235! 1736 2015-12-04 08:56:33Z raasch
236! no perturbations added to total domain if energy limit has been set zero
237!
238! 1691 2015-10-26 16:17:44Z maronga
239! Added option for spin-ups without land surface and radiation models. Moved calls
240! for radiation and lan surface schemes.
241!
242! 1682 2015-10-07 23:56:08Z knoop
243! Code annotations made doxygen readable
244!
245! 1671 2015-09-25 03:29:37Z raasch
246! bugfix: ghostpoint exchange for array diss in case that sgs velocities are used
247! for particles
248!
249! 1585 2015-04-30 07:05:52Z maronga
250! Moved call of radiation scheme. Added support for RRTM
251!
252! 1551 2015-03-03 14:18:16Z maronga
253! Added interface for different radiation schemes.
254!
255! 1496 2014-12-02 17:25:50Z maronga
256! Added calls for the land surface model and radiation scheme
257!
258! 1402 2014-05-09 14:25:13Z raasch
259! location messages modified
260!
261! 1384 2014-05-02 14:31:06Z raasch
262! location messages added
263!
264! 1380 2014-04-28 12:40:45Z heinze
265! CALL of nudge_ref added
266! bc_pt_t_val and bc_q_t_val are updated in case nudging is used
267!
268! 1365 2014-04-22 15:03:56Z boeske
269! Reset sums_ls_l to zero at each timestep
270! +sums_ls_l
271! Calculation of reference state (previously in subroutine calc_mean_profile)
272
273! 1342 2014-03-26 17:04:47Z kanani
274! REAL constants defined as wp-kind
275!
276! 1320 2014-03-20 08:40:49Z raasch
277! ONLY-attribute added to USE-statements,
278! kind-parameters added to all INTEGER and REAL declaration statements,
279! kinds are defined in new module kinds,
280! old module precision_kind is removed,
281! revision history before 2012 removed,
282! comment fields (!:) to be used for variable explanations added to
283! all variable declaration statements
284! 1318 2014-03-17 13:35:16Z raasch
285! module interfaces removed
286!
287! 1308 2014-03-13 14:58:42Z fricke
288! +netcdf_data_format_save
289! For masked data, parallel netcdf output is not tested so far, hence
290! netcdf_data_format is switched back to non-paralell output.
291!
292! 1276 2014-01-15 13:40:41Z heinze
293! Use LSF_DATA also in case of Dirichlet bottom boundary condition for scalars
294!
295! 1257 2013-11-08 15:18:40Z raasch
296! acc-update-host directive for timestep removed
297!
298! 1241 2013-10-30 11:36:58Z heinze
299! Generalize calc_mean_profile for wider use
300! Determine shf and qsws in dependence on data from LSF_DATA
301! Determine ug and vg in dependence on data from LSF_DATA
302! 1221 2013-09-10 08:59:13Z raasch
303! host update of arrays before timestep is called
304!
305! 1179 2013-06-14 05:57:58Z raasch
306! mean profiles for reference state are only calculated if required,
307! small bugfix for background communication
308!
309! 1171 2013-05-30 11:27:45Z raasch
310! split of prognostic_equations deactivated (comment lines), for the time being
311!
312! 1128 2013-04-12 06:19:32Z raasch
313! asynchronous transfer of ghost point data realized for acc-optimized version:
314! prognostic_equations are first called two times for those points required for
315! the left-right and north-south exchange, respectively, and then for the
316! remaining points,
317! those parts requiring global communication moved from prognostic_equations to
318! here
319!
320! 1115 2013-03-26 18:16:16Z hoffmann
321! calculation of qr and nr is restricted to precipitation
322!
323! 1113 2013-03-10 02:48:14Z raasch
324! GPU-porting of boundary conditions,
325! openACC directives updated
326! formal parameter removed from routine boundary_conds
327!
328! 1111 2013-03-08 23:54:10Z raasch
329! +internal timestep counter for cpu statistics added,
330! openACC directives updated
331!
332! 1092 2013-02-02 11:24:22Z raasch
333! unused variables removed
334!
335! 1065 2012-11-22 17:42:36Z hoffmann
336! exchange of diss (dissipation rate) in case of turbulence = .TRUE. added
337!
338! 1053 2012-11-13 17:11:03Z hoffmann
339! exchange of ghost points for nr, qr added
340!
341! 1036 2012-10-22 13:43:42Z raasch
342! code put under GPL (PALM 3.9)
343!
344! 1019 2012-09-28 06:46:45Z raasch
345! non-optimized version of prognostic_equations removed
346!
347! 1015 2012-09-27 09:23:24Z raasch
348! +call of prognostic_equations_acc
349!
350! 1001 2012-09-13 14:08:46Z raasch
351! all actions concerning leapfrog- and upstream-spline-scheme removed
352!
353! 849 2012-03-15 10:35:09Z raasch
354! advec_particles renamed lpm, first_call_advec_particles renamed first_call_lpm
355!
356! 825 2012-02-19 03:03:44Z raasch
357! wang_collision_kernel renamed wang_kernel
358!
359! Revision 1.1  1997/08/11 06:19:04  raasch
360! Initial revision
361!
362!
363! Description:
364! ------------
365!> Integration in time of the model equations, statistical analysis and graphic
366!> output
367!------------------------------------------------------------------------------!
368 SUBROUTINE time_integration
369 
370
371    USE advec_ws,                                                              &
372        ONLY:  ws_statistics
373
374    USE arrays_3d,                                                             &
375        ONLY:  diss, diss_p, dzu, e, e_p, nc, nc_p, nr, nr_p, prho, pt, pt_p, pt_init, &
376               q_init, q, qc, qc_p, ql, ql_c, ql_v, ql_vp, qr, qr_p, q_p,      &
377               ref_state, rho_ocean, s, s_p, sa_p, tend, u, u_p, v, vpt,       &
378               v_p, w, w_p
379
380    USE bulk_cloud_model_mod,                                                  &
381        ONLY: bulk_cloud_model, calc_liquid_water_content,                     &
382              collision_turbulence, microphysics_morrison, microphysics_seifert
383
384    USE calc_mean_profile_mod,                                                 &
385        ONLY:  calc_mean_profile
386
387    USE chem_emissions_mod,                                                    &
388        ONLY:  chem_emissions_setup
389
390    USE chem_modules,                                                          &
391        ONLY:  bc_cs_t_val, call_chem_at_all_substeps, cs_name,                &
392               constant_csflux, do_emis, nspec, nspec_out
393
394    USE chemistry_model_mod,                                                   &
395        ONLY:  chem_boundary_conds, chem_species
396
397    USE control_parameters,                                                    &
398        ONLY:  advected_distance_x, advected_distance_y, air_chemistry,        &
399               average_count_3d, averaging_interval, averaging_interval_pr,    &
400               bc_lr_cyc, bc_ns_cyc, bc_pt_t_val, bc_q_t_val,                  &
401               call_psolver_at_all_substeps,  child_domain, cloud_droplets,    &
402               constant_flux_layer, constant_heatflux,                         &
403               create_disturbances, dopr_n, constant_diffusion, coupling_mode, &
404               coupling_start_time, current_timestep_number,                   &
405               disturbance_created, disturbance_energy_limit, dist_range,      &
406               do_sum, dt_3d, dt_averaging_input, dt_averaging_input_pr,       &
407               dt_coupling, dt_data_output_av, dt_disturb, dt_do2d_xy,         &
408               dt_do2d_xz, dt_do2d_yz, dt_do3d, dt_domask,dt_dopts, dt_dopr,   &
409               dt_dopr_listing, dt_dots, dt_dvrp, dt_run_control, end_time,    &
410               first_call_lpm, first_call_mas, galilei_transformation,         &
411               humidity, intermediate_timestep_count,                          &
412               intermediate_timestep_count_max,                                &
413               land_surface, large_scale_forcing,                              &
414               loop_optimization, lsf_surf, lsf_vert, masks, mid,              &
415               multi_agent_system_end, multi_agent_system_start,               &
416               nesting_offline, neutral, nr_timesteps_this_run, nudging,       &
417               ocean_mode, passive_scalar, pt_reference,                       &
418               pt_slope_offset, random_heatflux, rans_mode,                    &
419               rans_tke_e, run_coupled, simulated_time, simulated_time_chr,    &
420               skip_time_do2d_xy, skip_time_do2d_xz, skip_time_do2d_yz,        &
421               skip_time_do3d, skip_time_domask, skip_time_dopr,               &
422               skip_time_data_output_av, sloping_surface,                      &
423               stop_dt, terminate_coupled, terminate_run, timestep_scheme,     &
424               time_coupling, time_do2d_xy, time_do2d_xz, time_do2d_yz,        &
425               time_do3d, time_domask, time_dopr, time_dopr_av,                &
426               time_dopr_listing, time_dopts, time_dosp, time_dosp_av,         &
427               time_dots, time_do_av, time_do_sla, time_disturb, time_dvrp,    &
428               time_run_control, time_since_reference_point,                   &
429               turbulent_inflow, turbulent_outflow, urban_surface,             &
430               use_initial_profile_as_reference,                               &
431               use_single_reference_value, uv_exposure, u_gtrans, v_gtrans,    &
432               virtual_flight, wind_turbine, ws_scheme_mom, ws_scheme_sca
433
434    USE cpulog,                                                                &
435        ONLY:  cpu_log, log_point, log_point_s
436
437    USE date_and_time_mod,                                                     &
438        ONLY:  calc_date_and_time, hour_call_emis, hour_of_year
439
440    USE flight_mod,                                                            &
441        ONLY:  flight_measurement
442
443    USE gust_mod,                                                              &
444        ONLY:  gust_actions, gust_module_enabled
445
446    USE indices,                                                               &
447        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, nzb, nzt
448
449    USE interaction_droplets_ptq_mod,                                          &
450        ONLY:  interaction_droplets_ptq
451
452    USE interfaces
453
454    USE kinds
455
456    USE land_surface_model_mod,                                                &
457        ONLY:  lsm_boundary_condition, lsm_energy_balance, lsm_soil_model,     &
458               skip_time_do_lsm
459
460    USE lsf_nudging_mod,                                                       &
461        ONLY:  calc_tnudge, ls_forcing_surf, ls_forcing_vert, nudge_ref,       &
462               lsf_nesting_offline, lsf_nesting_offline_mass_conservation
463
464    USE multi_agent_system_mod,                                                &
465        ONLY:  agents_active, multi_agent_system
466
467    USE netcdf_data_input_mod,                                                 &
468        ONLY:  chem_emis, chem_emis_att, nest_offl, netcdf_data_input_lsf
469
470    USE ocean_mod,                                                             &
471        ONLY:  prho_reference
472
473    USE particle_attributes,                                                   &
474        ONLY:  particle_advection, particle_advection_start,                   &
475               use_sgs_for_particles, wang_kernel
476
477    USE pegrid
478
479    USE pmc_interface,                                                         &
480        ONLY:  nested_run, nesting_mode, pmci_boundary_conds, pmci_datatrans,  &
481               pmci_ensure_nest_mass_conservation, pmci_synchronize
482
483    USE progress_bar,                                                          &
484        ONLY:  finish_progress_bar, output_progress_bar
485
486    USE prognostic_equations_mod,                                              &
487        ONLY:  prognostic_equations_cache, prognostic_equations_vector
488
489    USE radiation_model_mod,                                                   &
490        ONLY: dt_radiation, force_radiation_call, radiation, radiation_control,&
491              radiation_interaction, radiation_interactions,                   &
492              skip_time_do_radiation, time_radiation
493
494    USE spectra_mod,                                                           &
495        ONLY: average_count_sp, averaging_interval_sp, calc_spectra, dt_dosp,  &
496              skip_time_dosp
497
498    USE statistics,                                                            &
499        ONLY:  flow_statistics_called, hom, pr_palm, sums_ls_l
500
501    USE surface_layer_fluxes_mod,                                              &
502        ONLY:  surface_layer_fluxes
503
504    USE surface_mod,                                                           &
505        ONLY:  surf_def_h, surf_lsm_h, surf_usm_h
506
507    USE turbulence_closure_mod,                                                &
508        ONLY:  tcm_diffusivities, production_e_init
509
510    USE urban_surface_mod,                                                     &
511        ONLY:  usm_boundary_condition, usm_material_heat_model,                &
512               usm_material_model,                                             &
513               usm_surface_energy_balance, usm_green_heat_model,               &
514               usm_temperature_near_surface
515
516    USE synthetic_turbulence_generator_mod,                                    &
517        ONLY:  stg_main, use_syn_turb_gen
518
519    USE user_actions_mod,                                                      &
520        ONLY:  user_actions
521
522    USE uv_exposure_model_mod,                                                 &
523        ONLY:  uvem_calc_exposure
524
525    USE wind_turbine_model_mod,                                                &
526        ONLY:  wtm_forces
527
528    USE lpm_mod,                                                               &
529        ONLY:  lpm
530
531    USE vertical_nesting_mod,                                                  &
532        ONLY:  vnested, vnest_anterpolate, vnest_anterpolate_e,                &
533               vnest_boundary_conds, vnest_boundary_conds_khkm,                & 
534               vnest_deallocate, vnest_init, vnest_init_fine,                  &
535               vnest_start_time
536
537    IMPLICIT NONE
538
539    CHARACTER (LEN=9) ::  time_to_string   !<
540
541    INTEGER(iwp)      ::  lsp       !<
542    INTEGER(iwp)      ::  lsp_usr   !<
543    INTEGER(iwp)      ::  n         !< loop counter for chemistry species
544
545    REAL(wp) ::  dt_3d_old  !< temporary storage of timestep to be used for
546                            !< steering of run control output interval
547    REAL(wp) ::  time_since_reference_point_save  !< original value of
548                                                  !< time_since_reference_point
549
550!
551!-- At beginning determine the first time step
552    CALL timestep
553!
554!-- Synchronize the timestep in case of nested run.
555    IF ( nested_run )  THEN
556!
557!--    Synchronization by unifying the time step.
558!--    Global minimum of all time-steps is used for all.
559       CALL pmci_synchronize
560    ENDIF
561
562!
563!-- Determine and print out the run control quantities before the first time
564!-- step of this run. For the initial run, some statistics (e.g. divergence)
565!-- need to be determined first --> CALL flow_statistics at the beginning of
566!-- run_control
567    CALL run_control
568!
569!-- Data exchange between coupled models in case that a call has been omitted
570!-- at the end of the previous run of a job chain.
571    IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled .AND. .NOT. vnested)  THEN
572!
573!--    In case of model termination initiated by the local model the coupler
574!--    must not be called because this would again cause an MPI hang.
575       DO WHILE ( time_coupling >= dt_coupling  .AND.  terminate_coupled == 0 )
576          CALL surface_coupler
577          time_coupling = time_coupling - dt_coupling
578       ENDDO
579       IF (time_coupling == 0.0_wp  .AND.                                      &
580           time_since_reference_point < dt_coupling )                          &
581       THEN
582          time_coupling = time_since_reference_point
583       ENDIF
584    ENDIF
585
586#if defined( __dvrp_graphics )
587!
588!-- Time measurement with dvrp software 
589    CALL DVRP_LOG_EVENT( 2, current_timestep_number )
590#endif
591
592    CALL location_message( 'starting timestep-sequence', .TRUE. )
593!
594!-- Start of the time loop
595    DO  WHILE ( simulated_time < end_time  .AND.  .NOT. stop_dt  .AND. &
596                .NOT. terminate_run )
597
598       CALL cpu_log( log_point_s(10), 'timesteps', 'start' )
599!
600!--    Vertical nesting: initialize fine grid
601       IF ( vnested ) THEN
602          IF ( .NOT. vnest_init  .AND.  simulated_time >= vnest_start_time )  THEN
603             CALL cpu_log( log_point(80), 'vnest_init', 'start' )
604             CALL vnest_init_fine
605             vnest_init = .TRUE.
606             CALL cpu_log( log_point(80), 'vnest_init', 'stop' )
607          ENDIF
608       ENDIF
609!
610!--    Determine ug, vg and w_subs in dependence on data from external file
611!--    LSF_DATA
612       IF ( large_scale_forcing .AND. lsf_vert )  THEN
613           CALL ls_forcing_vert ( simulated_time )
614           sums_ls_l = 0.0_wp
615       ENDIF
616
617!
618!--    Set pt_init and q_init to the current profiles taken from
619!--    NUDGING_DATA
620       IF ( nudging )  THEN
621           CALL nudge_ref ( simulated_time )
622!
623!--        Store temperature gradient at the top boundary for possible Neumann
624!--        boundary condition
625           bc_pt_t_val = ( pt_init(nzt+1) - pt_init(nzt) ) / dzu(nzt+1)
626           bc_q_t_val  = ( q_init(nzt+1) - q_init(nzt) ) / dzu(nzt+1)
627           IF ( air_chemistry )  THEN
628              DO  lsp = 1, nspec
629                 bc_cs_t_val = (  chem_species(lsp)%conc_pr_init(nzt+1)       &
630                                - chem_species(lsp)%conc_pr_init(nzt) )       &
631                               / dzu(nzt+1)
632              ENDDO
633           ENDIF
634       ENDIF
635!
636!--    If forcing by larger-scale models is applied, check if new data
637!--    at domain boundaries need to be read.
638       IF ( nesting_offline )  THEN
639          IF ( nest_offl%time(nest_offl%tind_p) <= time_since_reference_point )&
640             CALL netcdf_data_input_lsf
641       ENDIF
642
643!
644!--    Execute the gust module actions
645       IF ( gust_module_enabled )  THEN
646          CALL gust_actions( 'before_timestep' )
647       ENDIF
648
649!
650!--    Execute the user-defined actions
651       CALL user_actions( 'before_timestep' )
652
653!
654!--    Calculate forces by wind turbines
655       IF ( wind_turbine )  THEN
656
657          CALL cpu_log( log_point(55), 'wind_turbine', 'start' )
658
659          CALL wtm_forces
660
661          CALL cpu_log( log_point(55), 'wind_turbine', 'stop' )
662
663       ENDIF       
664       
665!
666!--    Start of intermediate step loop
667       intermediate_timestep_count = 0
668       DO  WHILE ( intermediate_timestep_count < &
669                   intermediate_timestep_count_max )
670
671          intermediate_timestep_count = intermediate_timestep_count + 1
672
673!
674!--       Set the steering factors for the prognostic equations which depend
675!--       on the timestep scheme
676          CALL timestep_scheme_steering
677
678!
679!--       Calculate those variables needed in the tendency terms which need
680!--       global communication
681          IF ( .NOT. use_single_reference_value  .AND. &
682               .NOT. use_initial_profile_as_reference )  THEN
683!
684!--          Horizontally averaged profiles to be used as reference state in
685!--          buoyancy terms (WARNING: only the respective last call of
686!--          calc_mean_profile defines the reference state!)
687             IF ( .NOT. neutral )  THEN
688                CALL calc_mean_profile( pt, 4 )
689                ref_state(:)  = hom(:,1,4,0) ! this is used in the buoyancy term
690             ENDIF
691             IF ( ocean_mode )  THEN
692                CALL calc_mean_profile( rho_ocean, 64 )
693                ref_state(:)  = hom(:,1,64,0)
694             ENDIF
695             IF ( humidity )  THEN
696                CALL calc_mean_profile( vpt, 44 )
697                ref_state(:)  = hom(:,1,44,0)
698             ENDIF
699!
700!--          Assure that ref_state does not become zero at any level
701!--          ( might be the case if a vertical level is completely occupied
702!--            with topography ).
703             ref_state = MERGE( MAXVAL(ref_state), ref_state,                  &
704                                ref_state == 0.0_wp )
705          ENDIF
706
707          IF ( .NOT. constant_diffusion )  CALL production_e_init
708          IF ( ( ws_scheme_mom .OR. ws_scheme_sca )  .AND.  &
709               intermediate_timestep_count == 1 )  CALL ws_statistics
710!
711!--       In case of nudging calculate current nudging time scale and horizontal
712!--       means of u, v, pt and q
713          IF ( nudging )  THEN
714             CALL calc_tnudge( simulated_time )
715             CALL calc_mean_profile( u, 1 )
716             CALL calc_mean_profile( v, 2 )
717             CALL calc_mean_profile( pt, 4 )
718             CALL calc_mean_profile( q, 41 )
719          ENDIF
720
721!
722!--       Solve the prognostic equations. A fast cache optimized version with
723!--       only one single loop is used in case of Piascek-Williams advection
724!--       scheme. NEC vector machines use a different version, because
725!--       in the other versions a good vectorization is prohibited due to
726!--       inlining problems.
727          IF ( loop_optimization == 'cache' )  THEN
728             CALL prognostic_equations_cache
729          ELSEIF ( loop_optimization == 'vector' )  THEN
730             CALL prognostic_equations_vector
731          ENDIF
732
733!
734!--       Particle transport/physics with the Lagrangian particle model
735!--       (only once during intermediate steps, because it uses an Euler-step)
736!--       ### particle model should be moved before prognostic_equations, in order
737!--       to regard droplet interactions directly
738          IF ( particle_advection  .AND.                         &
739               simulated_time >= particle_advection_start  .AND. &
740               intermediate_timestep_count == 1 )  THEN
741             CALL lpm
742             first_call_lpm = .FALSE.
743          ENDIF
744
745!
746!--       Interaction of droplets with temperature and mixing ratio.
747!--       Droplet condensation and evaporation is calculated within
748!--       advec_particles.
749          IF ( cloud_droplets  .AND.  &
750               intermediate_timestep_count == intermediate_timestep_count_max )&
751          THEN
752             CALL interaction_droplets_ptq
753          ENDIF
754
755!
756!--       Movement of agents in multi agent system
757          IF ( agents_active  .AND.                                            &
758               time_since_reference_point >= multi_agent_system_start  .AND.   &
759               time_since_reference_point <= multi_agent_system_end    .AND.   &
760               intermediate_timestep_count == 1 )  THEN
761             CALL multi_agent_system
762             first_call_mas = .FALSE.
763          ENDIF
764
765!
766!--       Exchange of ghost points (lateral boundary conditions)
767          CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
768
769          CALL exchange_horiz( u_p, nbgp )
770          CALL exchange_horiz( v_p, nbgp )
771          CALL exchange_horiz( w_p, nbgp )
772          CALL exchange_horiz( pt_p, nbgp )
773          IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
774          IF ( rans_tke_e  .OR.  wang_kernel  .OR.  collision_turbulence       &
775               .OR.  use_sgs_for_particles )  THEN
776             IF ( rans_tke_e )  THEN
777                CALL exchange_horiz( diss_p, nbgp )
778             ELSE
779                CALL exchange_horiz( diss, nbgp )
780             ENDIF
781          ENDIF
782          IF ( ocean_mode )  THEN
783             CALL exchange_horiz( sa_p, nbgp )
784             CALL exchange_horiz( rho_ocean, nbgp )
785             CALL exchange_horiz( prho, nbgp )
786          ENDIF
787          IF ( humidity )  THEN
788             CALL exchange_horiz( q_p, nbgp )
789             IF ( bulk_cloud_model .AND. microphysics_morrison )  THEN
790                CALL exchange_horiz( qc_p, nbgp )
791                CALL exchange_horiz( nc_p, nbgp )
792             ENDIF
793             IF ( bulk_cloud_model .AND. microphysics_seifert )  THEN
794                CALL exchange_horiz( qr_p, nbgp )
795                CALL exchange_horiz( nr_p, nbgp )
796             ENDIF
797          ENDIF
798          IF ( cloud_droplets )  THEN
799             CALL exchange_horiz( ql, nbgp )
800             CALL exchange_horiz( ql_c, nbgp )
801             CALL exchange_horiz( ql_v, nbgp )
802             CALL exchange_horiz( ql_vp, nbgp )
803          ENDIF
804          IF ( passive_scalar )  CALL exchange_horiz( s_p, nbgp )
805          IF ( air_chemistry )  THEN
806             DO  lsp = 1, nspec
807                CALL exchange_horiz( chem_species(lsp)%conc_p, nbgp )
808!
809!--             kanani: Push chem_boundary_conds after CALL boundary_conds
810                lsp_usr = 1
811                DO WHILE ( TRIM( cs_name( lsp_usr ) ) /= 'novalue' )
812                   IF ( TRIM(chem_species(lsp)%name) == TRIM(cs_name(lsp_usr)) )  THEN
813                      CALL chem_boundary_conds( chem_species(lsp)%conc_p,              &
814                                                chem_species(lsp)%conc_pr_init )
815                   ENDIF
816                   lsp_usr = lsp_usr + 1
817                ENDDO
818             ENDDO
819          ENDIF
820
821          CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
822
823!
824!--       Boundary conditions for the prognostic quantities (except of the
825!--       velocities at the outflow in case of a non-cyclic lateral wall)
826          CALL boundary_conds
827!
828!--       Swap the time levels in preparation for the next time step.
829          CALL swap_timelevel
830
831!
832!--       Vertical nesting: Interpolate fine grid data to the coarse grid
833          IF ( vnest_init ) THEN
834             CALL cpu_log( log_point(81), 'vnest_anterpolate', 'start' )
835             CALL vnest_anterpolate
836             CALL cpu_log( log_point(81), 'vnest_anterpolate', 'stop' )
837          ENDIF
838
839          IF ( nested_run )  THEN
840
841             CALL cpu_log( log_point(60), 'nesting', 'start' )
842!
843!--          Domain nesting. The data transfer subroutines pmci_parent_datatrans
844!--          and pmci_child_datatrans are called inside the wrapper
845!--          subroutine pmci_datatrans according to the control parameters
846!--          nesting_mode and nesting_datatransfer_mode.
847!--          TO_DO: why is nesting_mode given as a parameter here?
848             CALL pmci_datatrans( nesting_mode )
849
850             IF ( TRIM( nesting_mode ) == 'two-way' .OR.                       &
851                  nesting_mode == 'vertical' )  THEN
852!
853!--             Exchange_horiz is needed for all parent-domains after the
854!--             anterpolation
855                CALL exchange_horiz( u, nbgp )
856                CALL exchange_horiz( v, nbgp )
857                CALL exchange_horiz( w, nbgp )
858                IF ( .NOT. neutral )  CALL exchange_horiz( pt, nbgp )
859
860                IF ( humidity )  THEN
861
862                   CALL exchange_horiz( q, nbgp )
863
864                   IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
865                       CALL exchange_horiz( qc, nbgp )
866                       CALL exchange_horiz( nc, nbgp )
867                   ENDIF
868                   IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
869                       CALL exchange_horiz( qr, nbgp )
870                       CALL exchange_horiz( nr, nbgp )
871                   ENDIF
872
873                ENDIF
874
875                IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
876                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
877
878                IF ( .NOT. constant_diffusion  .AND.  rans_mode  .AND.         &
879                                                      rans_tke_e )             &
880                   CALL exchange_horiz( diss, nbgp )
881
882                IF ( air_chemistry )  THEN
883                   DO  n = 1, nspec     
884                      CALL exchange_horiz( chem_species(n)%conc, nbgp ) 
885                   ENDDO
886                ENDIF
887
888             ENDIF
889!
890!--          Set boundary conditions again after interpolation and anterpolation.
891             CALL pmci_boundary_conds
892!
893!--          Correct the w top-BC in nest domains to ensure mass conservation.
894!--          This action must never be done for the root domain. Vertical
895!--          nesting implies mass conservation.
896!--          Commented out April 18, 2018 as seemingly unnecessary.
897!--          Will later be completely removed.
898!--             IF ( child_domain )  THEN
899!--                CALL pmci_ensure_nest_mass_conservation
900!--             ENDIF
901
902
903             CALL cpu_log( log_point(60), 'nesting', 'stop' )
904
905          ENDIF
906
907!
908!--       Temperature offset must be imposed at cyclic boundaries in x-direction
909!--       when a sloping surface is used
910          IF ( sloping_surface )  THEN
911             IF ( nxl ==  0 )  pt(:,:,nxlg:nxl-1) = pt(:,:,nxlg:nxl-1) - &
912                                                    pt_slope_offset
913             IF ( nxr == nx )  pt(:,:,nxr+1:nxrg) = pt(:,:,nxr+1:nxrg) + &
914                                                    pt_slope_offset
915          ENDIF
916
917!
918!--       Impose a turbulent inflow using the recycling method
919          IF ( turbulent_inflow )  CALL  inflow_turbulence
920
921!
922!--       Impose a turbulent inflow using synthetic generated turbulence
923          IF ( use_syn_turb_gen )  CALL  stg_main
924
925!
926!--       Set values at outflow boundary using the special outflow condition
927          IF ( turbulent_outflow )  CALL  outflow_turbulence
928
929!
930!--       Impose a random perturbation on the horizontal velocity field
931          IF ( create_disturbances  .AND.                                      &
932               ( call_psolver_at_all_substeps  .AND.                           &
933               intermediate_timestep_count == intermediate_timestep_count_max )&
934          .OR. ( .NOT. call_psolver_at_all_substeps  .AND.                     &
935               intermediate_timestep_count == 1 ) )                            &
936          THEN
937             time_disturb = time_disturb + dt_3d
938             IF ( time_disturb >= dt_disturb )  THEN
939                IF ( disturbance_energy_limit /= 0.0_wp  .AND.                 &
940                     hom(nzb+5,1,pr_palm,0) < disturbance_energy_limit )  THEN
941                   CALL disturb_field( 'u', tend, u )
942                   CALL disturb_field( 'v', tend, v )
943                ELSEIF ( ( .NOT. bc_lr_cyc  .OR.  .NOT. bc_ns_cyc )            &
944                     .AND. .NOT. child_domain  .AND.  .NOT.  nesting_offline )  &
945                THEN
946!
947!--                Runs with a non-cyclic lateral wall need perturbations
948!--                near the inflow throughout the whole simulation
949                   dist_range = 1
950                   CALL disturb_field( 'u', tend, u )
951                   CALL disturb_field( 'v', tend, v )
952                   dist_range = 0
953                ENDIF
954                time_disturb = time_disturb - dt_disturb
955             ENDIF
956          ENDIF
957
958!
959!--       Map forcing data derived from larger scale model onto domain
960!--       boundaries.
961          IF ( nesting_offline  .AND.  intermediate_timestep_count ==          &
962                                       intermediate_timestep_count_max  )  THEN
963             CALL lsf_nesting_offline
964!
965!--          Moreover, ensure mass conservation
966             CALL lsf_nesting_offline_mass_conservation
967          ENDIF
968
969!
970!--       Reduce the velocity divergence via the equation for perturbation
971!--       pressure.
972          IF ( intermediate_timestep_count == 1  .OR. &
973                call_psolver_at_all_substeps )  THEN
974
975             IF (  vnest_init ) THEN
976!
977!--             Compute pressure in the CG, interpolate top boundary conditions
978!--             to the FG and then compute pressure in the FG
979                IF ( coupling_mode == 'vnested_crse' )  CALL pres
980
981                CALL cpu_log( log_point(82), 'vnest_bc', 'start' )
982                CALL vnest_boundary_conds
983                CALL cpu_log( log_point(82), 'vnest_bc', 'stop' )
984 
985                IF ( coupling_mode == 'vnested_fine' )  CALL pres
986
987!--             Anterpolate TKE, satisfy Germano Identity
988                CALL cpu_log( log_point(83), 'vnest_anter_e', 'start' )
989                CALL vnest_anterpolate_e
990                CALL cpu_log( log_point(83), 'vnest_anter_e', 'stop' )
991
992             ELSE
993
994                CALL pres
995
996             ENDIF
997
998          ENDIF
999
1000!
1001!--       If required, compute liquid water content
1002          IF ( bulk_cloud_model )  THEN
1003             CALL calc_liquid_water_content
1004          ENDIF
1005!
1006!--       If required, compute virtual potential temperature
1007          IF ( humidity )  THEN
1008             CALL compute_vpt 
1009          ENDIF 
1010
1011!
1012!--       Compute the diffusion quantities
1013          IF ( .NOT. constant_diffusion )  THEN
1014
1015!
1016!--          Determine surface fluxes shf and qsws and surface values
1017!--          pt_surface and q_surface in dependence on data from external
1018!--          file LSF_DATA respectively
1019             IF ( ( large_scale_forcing .AND. lsf_surf ) .AND. &
1020                 intermediate_timestep_count == intermediate_timestep_count_max )&
1021             THEN
1022                CALL ls_forcing_surf( simulated_time )
1023             ENDIF
1024
1025!
1026!--          First the vertical (and horizontal) fluxes in the surface
1027!--          (constant flux) layer are computed
1028             IF ( constant_flux_layer )  THEN
1029                CALL cpu_log( log_point(19), 'surface_layer_fluxes', 'start' )
1030                CALL surface_layer_fluxes
1031                CALL cpu_log( log_point(19), 'surface_layer_fluxes', 'stop' )
1032             ENDIF
1033!
1034!--          If required, solve the energy balance for the surface and run soil
1035!--          model. Call for horizontal as well as vertical surfaces
1036             IF ( land_surface .AND. time_since_reference_point >= skip_time_do_lsm)  THEN
1037
1038                CALL cpu_log( log_point(54), 'land_surface', 'start' )
1039!
1040!--             Call for horizontal upward-facing surfaces
1041                CALL lsm_energy_balance( .TRUE., -1 )
1042                CALL lsm_soil_model( .TRUE., -1, .TRUE. )
1043!
1044!--             Call for northward-facing surfaces
1045                CALL lsm_energy_balance( .FALSE., 0 )
1046                CALL lsm_soil_model( .FALSE., 0, .TRUE. )
1047!
1048!--             Call for southward-facing surfaces
1049                CALL lsm_energy_balance( .FALSE., 1 )
1050                CALL lsm_soil_model( .FALSE., 1, .TRUE. )
1051!
1052!--             Call for eastward-facing surfaces
1053                CALL lsm_energy_balance( .FALSE., 2 )
1054                CALL lsm_soil_model( .FALSE., 2, .TRUE. )
1055!
1056!--             Call for westward-facing surfaces
1057                CALL lsm_energy_balance( .FALSE., 3 )
1058                CALL lsm_soil_model( .FALSE., 3, .TRUE. )
1059!
1060!--             At the end, set boundary conditons for potential temperature
1061!--             and humidity after running the land-surface model. This
1062!--             might be important for the nesting, where arrays are transfered.
1063                CALL lsm_boundary_condition
1064
1065                CALL cpu_log( log_point(54), 'land_surface', 'stop' )
1066             ENDIF
1067!
1068!--          If required, solve the energy balance for urban surfaces and run
1069!--          the material heat model
1070             IF (urban_surface) THEN
1071                CALL cpu_log( log_point(74), 'urban_surface', 'start' )
1072               
1073                CALL usm_surface_energy_balance
1074                IF ( usm_material_model )  THEN
1075                   CALL usm_green_heat_model
1076                   CALL usm_material_heat_model
1077                ENDIF
1078
1079                CALL usm_temperature_near_surface
1080!
1081!--             At the end, set boundary conditons for potential temperature
1082!--             and humidity after running the urban-surface model. This
1083!--             might be important for the nesting, where arrays are transfered.
1084                CALL usm_boundary_condition
1085
1086                CALL cpu_log( log_point(74), 'urban_surface', 'stop' )
1087             ENDIF
1088!
1089!--          Compute the diffusion coefficients
1090             CALL cpu_log( log_point(17), 'diffusivities', 'start' )
1091             IF ( .NOT. humidity ) THEN
1092                IF ( ocean_mode )  THEN
1093                   CALL tcm_diffusivities( prho, prho_reference )
1094                ELSE
1095                   CALL tcm_diffusivities( pt, pt_reference )
1096                ENDIF
1097             ELSE
1098                CALL tcm_diffusivities( vpt, pt_reference )
1099             ENDIF
1100             CALL cpu_log( log_point(17), 'diffusivities', 'stop' )
1101!
1102!--          Vertical nesting: set fine grid eddy viscosity top boundary condition
1103             IF ( vnest_init )  CALL vnest_boundary_conds_khkm
1104
1105          ENDIF
1106
1107!
1108!--       If required, calculate radiative fluxes and heating rates
1109          IF ( radiation .AND. intermediate_timestep_count                     &
1110               == intermediate_timestep_count_max .AND. time_since_reference_point >    &
1111               skip_time_do_radiation )  THEN
1112
1113               time_radiation = time_radiation + dt_3d
1114
1115             IF ( time_radiation >= dt_radiation .OR. force_radiation_call )   &
1116             THEN
1117
1118                CALL cpu_log( log_point(50), 'radiation', 'start' )
1119
1120                IF ( .NOT. force_radiation_call )  THEN
1121                   time_radiation = time_radiation - dt_radiation
1122                ENDIF
1123
1124!
1125!--             Adjust the current time to the time step of the radiation model.
1126!--             Needed since radiation is pre-calculated and stored only on apparent
1127!--             solar positions
1128                time_since_reference_point_save = time_since_reference_point
1129                time_since_reference_point =                                   &
1130                                    REAL( FLOOR( time_since_reference_point /  &
1131                                                 dt_radiation), wp )           &
1132                                             * dt_radiation
1133
1134                CALL radiation_control
1135
1136                CALL cpu_log( log_point(50), 'radiation', 'stop' )
1137
1138                IF ( urban_surface  .OR.  land_surface  .AND.                  &
1139                     radiation_interactions )  THEN
1140                   CALL cpu_log( log_point(75), 'radiation_interaction', 'start' )
1141                   CALL radiation_interaction
1142                   CALL cpu_log( log_point(75), 'radiation_interaction', 'stop' )
1143                ENDIF
1144   
1145!
1146!--             Return the current time to its original value
1147                time_since_reference_point = time_since_reference_point_save
1148
1149             ENDIF
1150          ENDIF
1151
1152       ENDDO   ! Intermediate step loop
1153!
1154!--    If required, consider chemical emissions
1155       IF ( air_chemistry  .AND.  do_emis )  THEN
1156!
1157!--       Update the time --> kanani: revise location of this CALL
1158          CALL calc_date_and_time
1159!
1160!--       Call emission routine only once an hour
1161          IF (hour_of_year  .GT.  hour_call_emis )  THEN
1162             CALL chem_emissions_setup( chem_emis_att, chem_emis, nspec_out )
1163             hour_call_emis = hour_of_year
1164          ENDIF
1165       ENDIF
1166!
1167!--    If required, do UV exposure calculations
1168       IF ( uv_exposure )  THEN
1169          CALL uvem_calc_exposure
1170       ENDIF
1171!
1172!--    Increase simulation time and output times
1173       nr_timesteps_this_run      = nr_timesteps_this_run + 1
1174       current_timestep_number    = current_timestep_number + 1
1175       simulated_time             = simulated_time   + dt_3d
1176       time_since_reference_point = simulated_time - coupling_start_time
1177       simulated_time_chr         = time_to_string( time_since_reference_point )
1178
1179
1180
1181
1182       IF ( simulated_time >= skip_time_data_output_av )  THEN
1183          time_do_av         = time_do_av       + dt_3d
1184       ENDIF
1185       IF ( simulated_time >= skip_time_do2d_xy )  THEN
1186          time_do2d_xy       = time_do2d_xy     + dt_3d
1187       ENDIF
1188       IF ( simulated_time >= skip_time_do2d_xz )  THEN
1189          time_do2d_xz       = time_do2d_xz     + dt_3d
1190       ENDIF
1191       IF ( simulated_time >= skip_time_do2d_yz )  THEN
1192          time_do2d_yz       = time_do2d_yz     + dt_3d
1193       ENDIF
1194       IF ( simulated_time >= skip_time_do3d    )  THEN
1195          time_do3d          = time_do3d        + dt_3d
1196       ENDIF
1197       DO  mid = 1, masks
1198          IF ( simulated_time >= skip_time_domask(mid) )  THEN
1199             time_domask(mid)= time_domask(mid) + dt_3d
1200          ENDIF
1201       ENDDO
1202       time_dvrp          = time_dvrp        + dt_3d
1203       IF ( simulated_time >= skip_time_dosp )  THEN
1204          time_dosp       = time_dosp        + dt_3d
1205       ENDIF
1206       time_dots          = time_dots        + dt_3d
1207       IF ( .NOT. first_call_lpm )  THEN
1208          time_dopts      = time_dopts       + dt_3d
1209       ENDIF
1210       IF ( simulated_time >= skip_time_dopr )  THEN
1211          time_dopr       = time_dopr        + dt_3d
1212       ENDIF
1213       time_dopr_listing          = time_dopr_listing        + dt_3d
1214       time_run_control   = time_run_control + dt_3d
1215
1216!
1217!--    Data exchange between coupled models
1218       IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled                   &
1219                                          .AND. .NOT. vnested )  THEN
1220          time_coupling = time_coupling + dt_3d
1221
1222!
1223!--       In case of model termination initiated by the local model
1224!--       (terminate_coupled > 0), the coupler must be skipped because it would
1225!--       cause an MPI intercomminucation hang.
1226!--       If necessary, the coupler will be called at the beginning of the
1227!--       next restart run.
1228          DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
1229             CALL surface_coupler
1230             time_coupling = time_coupling - dt_coupling
1231          ENDDO
1232       ENDIF
1233
1234!
1235!--    Execute the gust module actions
1236       IF ( gust_module_enabled )  THEN
1237          CALL gust_actions( 'after_integration' )
1238       ENDIF
1239
1240!
1241!--    Execute user-defined actions
1242       CALL user_actions( 'after_integration' )
1243
1244!
1245!--    If Galilei transformation is used, determine the distance that the
1246!--    model has moved so far
1247       IF ( galilei_transformation )  THEN
1248          advected_distance_x = advected_distance_x + u_gtrans * dt_3d
1249          advected_distance_y = advected_distance_y + v_gtrans * dt_3d
1250       ENDIF
1251
1252!
1253!--    Check, if restart is necessary (because cpu-time is expiring or
1254!--    because it is forced by user) and set stop flag
1255!--    This call is skipped if the remote model has already initiated a restart.
1256       IF ( .NOT. terminate_run )  CALL check_for_restart
1257
1258!
1259!--    Carry out statistical analysis and output at the requested output times.
1260!--    The MOD function is used for calculating the output time counters (like
1261!--    time_dopr) in order to regard a possible decrease of the output time
1262!--    interval in case of restart runs
1263
1264!
1265!--    Set a flag indicating that so far no statistics have been created
1266!--    for this time step
1267       flow_statistics_called = .FALSE.
1268
1269!
1270!--    If required, call flow_statistics for averaging in time
1271       IF ( averaging_interval_pr /= 0.0_wp  .AND.  &
1272            ( dt_dopr - time_dopr ) <= averaging_interval_pr  .AND.  &
1273            simulated_time >= skip_time_dopr )  THEN
1274          time_dopr_av = time_dopr_av + dt_3d
1275          IF ( time_dopr_av >= dt_averaging_input_pr )  THEN
1276             do_sum = .TRUE.
1277             time_dopr_av = MOD( time_dopr_av, &
1278                                    MAX( dt_averaging_input_pr, dt_3d ) )
1279          ENDIF
1280       ENDIF
1281       IF ( do_sum )  CALL flow_statistics
1282
1283!
1284!--    Sum-up 3d-arrays for later output of time-averaged 2d/3d/masked data
1285       IF ( averaging_interval /= 0.0_wp  .AND.                                &
1286            ( dt_data_output_av - time_do_av ) <= averaging_interval  .AND. &
1287            simulated_time >= skip_time_data_output_av )                    &
1288       THEN
1289          time_do_sla = time_do_sla + dt_3d
1290          IF ( time_do_sla >= dt_averaging_input )  THEN
1291             CALL sum_up_3d_data
1292             average_count_3d = average_count_3d + 1
1293             time_do_sla = MOD( time_do_sla, MAX( dt_averaging_input, dt_3d ) )
1294          ENDIF
1295       ENDIF
1296
1297!
1298!--    Calculate spectra for time averaging
1299       IF ( averaging_interval_sp /= 0.0_wp  .AND.  &
1300            ( dt_dosp - time_dosp ) <= averaging_interval_sp  .AND.  &
1301            simulated_time >= skip_time_dosp )  THEN
1302          time_dosp_av = time_dosp_av + dt_3d
1303          IF ( time_dosp_av >= dt_averaging_input_pr )  THEN
1304             CALL calc_spectra
1305             time_dosp_av = MOD( time_dosp_av, &
1306                                 MAX( dt_averaging_input_pr, dt_3d ) )
1307          ENDIF
1308       ENDIF
1309
1310!
1311!--    Call flight module and output data
1312       IF ( virtual_flight )  THEN
1313          CALL flight_measurement
1314          CALL data_output_flight
1315       ENDIF
1316
1317!
1318!--    Profile output (ASCII) on file
1319       IF ( time_dopr_listing >= dt_dopr_listing )  THEN
1320          CALL print_1d
1321          time_dopr_listing = MOD( time_dopr_listing, MAX( dt_dopr_listing, &
1322                                                           dt_3d ) )
1323       ENDIF
1324
1325!
1326!--    Graphic output for PROFIL
1327       IF ( time_dopr >= dt_dopr )  THEN
1328          IF ( dopr_n /= 0 )  CALL data_output_profiles
1329          time_dopr = MOD( time_dopr, MAX( dt_dopr, dt_3d ) )
1330          time_dopr_av = 0.0_wp    ! due to averaging (see above)
1331       ENDIF
1332
1333!
1334!--    Graphic output for time series
1335       IF ( time_dots >= dt_dots )  THEN
1336          CALL data_output_tseries
1337          time_dots = MOD( time_dots, MAX( dt_dots, dt_3d ) )
1338       ENDIF
1339
1340!
1341!--    Output of spectra (formatted for use with PROFIL), in case of no
1342!--    time averaging, spectra has to be calculated before
1343       IF ( time_dosp >= dt_dosp )  THEN
1344          IF ( average_count_sp == 0 )  CALL calc_spectra
1345          CALL data_output_spectra
1346          time_dosp = MOD( time_dosp, MAX( dt_dosp, dt_3d ) )
1347       ENDIF
1348
1349!
1350!--    2d-data output (cross-sections)
1351       IF ( time_do2d_xy >= dt_do2d_xy )  THEN
1352          CALL data_output_2d( 'xy', 0 )
1353          time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
1354       ENDIF
1355       IF ( time_do2d_xz >= dt_do2d_xz )  THEN
1356          CALL data_output_2d( 'xz', 0 )
1357          time_do2d_xz = MOD( time_do2d_xz, MAX( dt_do2d_xz, dt_3d ) )
1358       ENDIF
1359       IF ( time_do2d_yz >= dt_do2d_yz )  THEN
1360          CALL data_output_2d( 'yz', 0 )
1361          time_do2d_yz = MOD( time_do2d_yz, MAX( dt_do2d_yz, dt_3d ) )
1362       ENDIF
1363
1364!
1365!--    3d-data output (volume data)
1366       IF ( time_do3d >= dt_do3d )  THEN
1367          CALL data_output_3d( 0 )
1368          time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
1369       ENDIF
1370
1371!
1372!--    Masked data output
1373       DO  mid = 1, masks
1374          IF ( time_domask(mid) >= dt_domask(mid) )  THEN
1375             CALL data_output_mask( 0 )
1376             time_domask(mid) = MOD( time_domask(mid),  &
1377                                     MAX( dt_domask(mid), dt_3d ) )
1378          ENDIF
1379       ENDDO
1380
1381!
1382!--    Output of time-averaged 2d/3d/masked data
1383       IF ( time_do_av >= dt_data_output_av )  THEN
1384          CALL average_3d_data
1385          CALL data_output_2d( 'xy', 1 )
1386          CALL data_output_2d( 'xz', 1 )
1387          CALL data_output_2d( 'yz', 1 )
1388          CALL data_output_3d( 1 )
1389          DO  mid = 1, masks
1390             CALL data_output_mask( 1 )
1391          ENDDO
1392          time_do_av = MOD( time_do_av, MAX( dt_data_output_av, dt_3d ) )
1393       ENDIF
1394
1395!
1396!--    Output of particle time series
1397       IF ( particle_advection )  THEN
1398          IF ( time_dopts >= dt_dopts  .OR. &
1399               ( simulated_time >= particle_advection_start  .AND. &
1400                 first_call_lpm ) )  THEN
1401             CALL data_output_ptseries
1402             time_dopts = MOD( time_dopts, MAX( dt_dopts, dt_3d ) )
1403          ENDIF
1404       ENDIF
1405
1406!
1407!--    Output of dvrp-graphics (isosurface, particles, slicer)
1408#if defined( __dvrp_graphics )
1409       CALL DVRP_LOG_EVENT( -2, current_timestep_number-1 )
1410#endif
1411       IF ( time_dvrp >= dt_dvrp )  THEN
1412          CALL data_output_dvrp
1413          time_dvrp = MOD( time_dvrp, MAX( dt_dvrp, dt_3d ) )
1414       ENDIF
1415#if defined( __dvrp_graphics )
1416       CALL DVRP_LOG_EVENT( 2, current_timestep_number )
1417#endif
1418
1419!
1420!--    If required, set the heat flux for the next time step at a random value
1421       IF ( constant_heatflux  .AND.  random_heatflux )  THEN
1422          IF ( surf_def_h(0)%ns >= 1 )  CALL disturb_heatflux( surf_def_h(0) )
1423          IF ( surf_lsm_h%ns    >= 1 )  CALL disturb_heatflux( surf_lsm_h    )
1424          IF ( surf_usm_h%ns    >= 1 )  CALL disturb_heatflux( surf_usm_h    )
1425       ENDIF
1426
1427!
1428!--    Execute the gust module actions
1429       IF ( gust_module_enabled )  THEN
1430          CALL gust_actions( 'after_timestep' )
1431       ENDIF
1432
1433!
1434!--    Execute user-defined actions
1435       CALL user_actions( 'after_timestep' )
1436
1437!
1438!--    Determine size of next time step. Save timestep dt_3d because it is
1439!--    newly calculated in routine timestep, but required further below for
1440!--    steering the run control output interval
1441       dt_3d_old = dt_3d
1442       CALL timestep
1443
1444!
1445!--    Synchronize the timestep in case of nested run.
1446       IF ( nested_run )  THEN
1447!
1448!--       Synchronize by unifying the time step.
1449!--       Global minimum of all time-steps is used for all.
1450          CALL pmci_synchronize
1451       ENDIF
1452
1453!
1454!--    Computation and output of run control parameters.
1455!--    This is also done whenever perturbations have been imposed
1456       IF ( time_run_control >= dt_run_control  .OR.                     &
1457            timestep_scheme(1:5) /= 'runge'  .OR.  disturbance_created ) &
1458       THEN
1459          CALL run_control
1460          IF ( time_run_control >= dt_run_control )  THEN
1461             time_run_control = MOD( time_run_control, &
1462                                     MAX( dt_run_control, dt_3d_old ) )
1463          ENDIF
1464       ENDIF
1465
1466!
1467!--    Output elapsed simulated time in form of a progress bar on stdout
1468       IF ( myid == 0 )  CALL output_progress_bar
1469
1470       CALL cpu_log( log_point_s(10), 'timesteps', 'stop' )
1471
1472
1473    ENDDO   ! time loop
1474
1475!-- Vertical nesting: Deallocate variables initialized for vertical nesting   
1476    IF ( vnest_init )  CALL vnest_deallocate
1477
1478    IF ( myid == 0 )  CALL finish_progress_bar
1479
1480#if defined( __dvrp_graphics )
1481    CALL DVRP_LOG_EVENT( -2, current_timestep_number )
1482#endif
1483
1484    CALL location_message( 'finished time-stepping', .TRUE. )
1485
1486 END SUBROUTINE time_integration
Note: See TracBrowser for help on using the repository browser.