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

Last change on this file since 3569 was 3569, checked in by kanani, 3 years ago

Fix for biomet output (ticket:757), merge of uv_exposure into biometeorology_mod

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