Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 3993)
+++ palm/trunk/SOURCE/Makefile	(revision 3994)
@@ -25,4 +25,7 @@
 # -----------------
 # $Id$
+# new module for calculation and output of diagnostic quantities added
+# 
+# 3988 2019-05-22 11:32:37Z kanani
 # Add dependencies for virtual_measurement_mod
 # 
@@ -589,4 +592,5 @@
 	data_output_tseries.f90 \
 	date_and_time_mod.f90 \
+	diagnostic_output_quantities_mod.f90 \
 	diffusion_s.f90 \
 	diffusion_u.f90 \
@@ -789,4 +793,5 @@
 average_3d_data.o: \
 	cpulog_mod.o \
+	diagnostic_output_quantities_mod.o \
 	exchange_horiz_2d.o \
 	mod_kinds.o \
@@ -925,4 +930,5 @@
 	chemistry_model_mod.o \
 	cpulog_mod.o \
+	diagnostic_output_quantities_mod.o \
 	mod_kinds.o \
 	mod_particle_attributes.o \
@@ -964,4 +970,5 @@
 	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
+	diagnostic_output_quantities_mod.o \
 	land_surface_model_mod.o \
 	mod_kinds.o \
@@ -976,4 +983,5 @@
 	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
+	diagnostic_output_quantities_mod.o \
 	land_surface_model_mod.o \
 	mod_kinds.o \
@@ -986,4 +994,7 @@
 	urban_surface_mod.o
 date_and_time_mod.o: \
+	mod_kinds.o \
+	modules.o
+diagnostic_output_quantities_mod.o: \
 	mod_kinds.o \
 	modules.o
@@ -1401,4 +1412,5 @@
 	cpulog_mod.o \
 	date_and_time_mod.o \
+	diagnostic_output_quantities_mod.o \
 	land_surface_model_mod.o \
 	mod_kinds.o \
@@ -1563,4 +1575,5 @@
 	cpulog_mod.o \
 	date_and_time_mod.o \
+	diagnostic_output_quantities_mod.o \
 	mod_kinds.o \
 	model_1d_mod.o \
@@ -1616,4 +1629,5 @@
 	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
+	diagnostic_output_quantities_mod.o \
 	mod_kinds.o \
 	module_interface.o \
@@ -1681,4 +1695,5 @@
 	cpulog_mod.o \
 	data_output_flight.o \
+	diagnostic_output_quantities_mod.o \
 	disturb_heatflux.o \
 	indoor_model_mod.o \
@@ -1869,4 +1884,5 @@
 write_restart_data_mod.o: \
 	date_and_time_mod.o \
+	diagnostic_output_quantities_mod.o \
 	mod_kinds.o \
 	mod_particle_attributes.o \
Index: palm/trunk/SOURCE/average_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/average_3d_data.f90	(revision 3993)
+++ palm/trunk/SOURCE/average_3d_data.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3933 2019-04-25 12:33:20Z kanani
 ! Bugfix in CASE theta_2m*, removal of redundant code
 ! 
@@ -188,4 +191,7 @@
         ONLY:  cpu_log, log_point
 
+    USE diagnostic_output_quantities_mod,                                      &
+        ONLY:  ti_av
+
     USE indices,                                                               &
         ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt
@@ -515,4 +521,16 @@
              ENDIF
 
+
+          CASE ( 'ti' )
+             IF ( ALLOCATED( ti_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb, nzt+1
+                         ti_av(k,j,i) = ti_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
+
           CASE ( 'w' )
              IF ( ALLOCATED( w_av ) ) THEN
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 3993)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3933 2019-04-25 12:33:20Z kanani
 ! Alphabetical resorting in CASE, condense settings for theta_2m* into one IF clause
 ! 
@@ -3080,4 +3083,7 @@
              CONTINUE
 
+          CASE ( 'ti' )
+             unit = '1/s'
+
           CASE ( 'ghf*', 'lwp*', 'ol*', 'qsws*', 'r_a*',                       &
                  'shf*', 'ssws*', 't*', 'theta_2m*', 'tsurf*', 'us*',          &
Index: palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_2d.f90	(revision 3993)
+++ palm/trunk/SOURCE/data_output_2d.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3987 2019-05-22 09:52:13Z kanani
 ! Introduce alternative switch for debug output during timestepping
 ! 
@@ -321,4 +324,7 @@
     USE cpulog,                                                                &
         ONLY:  cpu_log, log_point
+
+    USE diagnostic_output_quantities_mod,                                      &
+        ONLY:  ti, ti_av
 
     USE indices,                                                               &
@@ -1261,6 +1267,16 @@
                 level_z(nzb+1) = zu(nzb+1)
                 
-                
-                
+             CASE ( 'ti_xy', 'ti_xz', 'ti_yz' )
+                IF ( av == 0 )  THEN
+                   to_be_resorted => ti
+                ELSE
+                   IF ( .NOT. ALLOCATED( ti_av ) ) THEN
+                      ALLOCATE( ti_av(nzb:nzt+1,nys:nyn,nxl:nxr) )
+                      ti_av = REAL( fill_value, KIND = wp )
+                   ENDIF
+                   to_be_resorted => ti_av
+                ENDIF
+                IF ( mode == 'xy' )  level_z = zu
+
              CASE ( 'w_xy', 'w_xz', 'w_yz' )
                 flag_nr = 3
Index: palm/trunk/SOURCE/data_output_3d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_3d.f90	(revision 3993)
+++ palm/trunk/SOURCE/data_output_3d.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3987 2019-05-22 09:52:13Z kanani
 ! Introduce alternative switch for debug output during timestepping
 ! 
@@ -272,4 +275,7 @@
     USE cpulog,                                                                &
         ONLY:  log_point, cpu_log
+
+    USE diagnostic_output_quantities_mod,                                      &
+        ONLY:  ti, ti_av
 
 #if defined( __parallel )
@@ -697,4 +703,15 @@
                 ENDIF
                 to_be_resorted => vpt_av
+             ENDIF
+
+          CASE ( 'ti' )
+             IF ( av == 0 )  THEN
+                to_be_resorted => ti
+             ELSE
+                IF ( .NOT. ALLOCATED( ti_av ) ) THEN
+                   ALLOCATE( ti_av(nzb:nzt+1,nys:nyn,nxl:nxr) )
+                   ti_av = REAL( fill_value, KIND = wp )
+                ENDIF
+                to_be_resorted => ti_av
              ENDIF
 
Index: palm/trunk/SOURCE/data_output_mask.f90
===================================================================
--- palm/trunk/SOURCE/data_output_mask.f90	(revision 3993)
+++ palm/trunk/SOURCE/data_output_mask.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3665 2019-01-10 08:28:24Z raasch
 ! unused variables removed
 ! 
@@ -179,4 +182,7 @@
     USE cpulog,                                                                &
         ONLY:  cpu_log, log_point
+
+    USE diagnostic_output_quantities_mod,                                      &
+        ONLY:  ti, ti_av
 
     USE indices,                                                               &
@@ -663,4 +669,11 @@
              ENDIF
 
+          CASE ( 'ti' )
+             IF ( av == 0 )  THEN
+                to_be_resorted => ti
+             ELSE
+                to_be_resorted => ti_av
+             ENDIF
+
           CASE ( 'w' )
              grid = 'w'
Index: palm/trunk/SOURCE/diagnostic_output_quantities_mod.f90
===================================================================
--- palm/trunk/SOURCE/diagnostic_output_quantities_mod.f90	(revision 3994)
+++ palm/trunk/SOURCE/diagnostic_output_quantities_mod.f90	(revision 3994)
@@ -0,0 +1,313 @@
+!> @file diagnostic_output_quantities_mod.f90
+!------------------------------------------------------------------------------!
+! This file is part of the PALM model system.
+!
+! PALM is free software: you can redistribute it and/or modify it under the
+! terms of the GNU General Public License as published by the Free Software
+! Foundation, either version 3 of the License, or (at your option) any later
+! version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2019 Leibniz Universitaet Hannover
+!------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+! Initial revision
+!
+!
+! @author Farah Kanani-Suehring
+! 
+! Description:
+! ------------
+!> ...
+!------------------------------------------------------------------------------!
+ MODULE diagnostic_output_quantities_mod
+ 
+
+!     USE arrays_3d,                                                             &
+!         ONLY:  dzw, e, heatflux_output_conversion, nc, nr, p, pt,              &
+!                precipitation_amount, prr, q, qc, ql, ql_c, ql_v, qr, s, tend,  &
+!                u, v, vpt, w, zu, zw, waterflux_output_conversion, hyrho, d_exner
+! 
+!     USE averaging
+! 
+!     USE basic_constants_and_equations_mod,                                     &
+!         ONLY:  c_p, lv_d_cp, l_v
+! 
+!     USE bulk_cloud_model_mod,                                                  &
+!         ONLY:  bulk_cloud_model
+! 
+    USE control_parameters,                                                    &
+        ONLY:  current_timestep_number, varnamelength
+! 
+!     USE cpulog,                                                                &
+!         ONLY:  cpu_log, log_point
+! 
+!     USE indices,                                                               &
+!         ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg,       &
+!                nzb, nzt, wall_flags_0
+! 
+    USE kinds
+! 
+!     USE land_surface_model_mod,                                                &
+!         ONLY:  zs
+! 
+!     USE module_interface,                                                      &
+!         ONLY:  module_interface_data_output_2d
+! 
+! #if defined( __netcdf )
+!     USE NETCDF
+! #endif
+! 
+!     USE netcdf_interface,                                                      &
+!         ONLY:  fill_value, id_set_xy, id_set_xz, id_set_yz, id_var_do2d,       &
+!                id_var_time_xy, id_var_time_xz, id_var_time_yz, nc_stat,        &
+!                netcdf_data_format, netcdf_handle_error
+! 
+!     USE particle_attributes,                                                   &
+!         ONLY:  grid_particles, number_of_particles, particle_advection_start,  &
+!                particles, prt_count
+!     
+!     USE pegrid
+! 
+!     USE surface_mod,                                                           &
+!         ONLY:  ind_pav_green, ind_veg_wall, ind_wat_win, surf_def_h,           &
+!                surf_lsm_h, surf_usm_h
+! 
+!     USE turbulence_closure_mod,                                                &
+!         ONLY:  tcm_data_output_2d
+
+
+    IMPLICIT NONE
+
+    CHARACTER(LEN=varnamelength), DIMENSION(500) ::  do_all = ' '
+
+    INTEGER(iwp) ::  timestep_number_at_prev_calc = 0  !< ...at previous diagnostic output calculation
+
+    LOGICAL ::  initialized_diagnostic_output_quantities = .FALSE.
+    LOGICAL ::  prepared_diagnostic_output_quantities = .FALSE.
+
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, TARGET ::  ti     !< rotation(u,v,w) aka turbulence intensity
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, TARGET ::  ti_av  !< avg. rotation(u,v,w) aka turbulence intensity
+
+
+    SAVE
+
+    PRIVATE
+
+!
+!-- Public variables
+    PUBLIC do_all,                                                                                 &
+           initialized_diagnostic_output_quantities,                                               &
+           prepared_diagnostic_output_quantities,                                                  &
+           ti, ti_av,                                                                              &
+           timestep_number_at_prev_calc
+!
+!-- Public routines
+    PUBLIC diagnostic_output_quantities_calculate,                                                 &
+           diagnostic_output_quantities_init,                                                      &
+           diagnostic_output_quantities_prepare
+
+
+    INTERFACE diagnostic_output_quantities_init
+       MODULE PROCEDURE diagnostic_output_quantities_init
+    END INTERFACE diagnostic_output_quantities_init
+
+    INTERFACE diagnostic_output_quantities_calculate
+       MODULE PROCEDURE diagnostic_output_quantities_calculate
+    END INTERFACE diagnostic_output_quantities_calculate
+
+    INTERFACE diagnostic_output_quantities_prepare
+       MODULE PROCEDURE diagnostic_output_quantities_prepare
+    END INTERFACE diagnostic_output_quantities_prepare
+
+
+ CONTAINS
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> ...
+!------------------------------------------------------------------------------!
+ SUBROUTINE diagnostic_output_quantities_init
+
+
+    USE indices,                                                                                   &
+        ONLY:  nxl, nxr, nyn, nys, nzb, nzt
+
+    IMPLICIT NONE
+
+
+    initialized_diagnostic_output_quantities = .FALSE.
+
+    IF ( .NOT. ALLOCATED( ti ) )  THEN
+       ALLOCATE( ti(nzb:nzt+1,nys:nyn,nxl:nxr) )
+       ti = 0.0_wp
+    ENDIF
+
+    initialized_diagnostic_output_quantities = .TRUE.
+
+ END SUBROUTINE diagnostic_output_quantities_init
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> ...
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE diagnostic_output_quantities_calculate
+
+
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzu, u, v, w
+
+    USE grid_variables,                                                                            &
+        ONLY:  ddx, ddy
+
+    USE indices,                                                                                   &
+        ONLY:  nxl, nxr, nyn, nys, nzb, nzt, wall_flags_0
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i, j, k    !< grid loop index in x-, y-, z-direction
+    INTEGER(iwp) ::  ivar_all   !< loop index over all 2d/3d/mask output quantities
+
+
+!     CALL cpu_log( log_point(41), 'calculate_quantities', 'start' )
+!
+!-- Preparatory steps and initialization of output arrays
+    IF ( .NOT.  prepared_diagnostic_output_quantities )     CALL diagnostic_output_quantities_prepare
+    IF ( .NOT.  initialized_diagnostic_output_quantities )  CALL diagnostic_output_quantities_init
+!
+!-- Save timestep number to check in time_integration if diagnostic_output_quantities_calculate 
+!-- has been called already, since the CALL occurs at two locations, but the calculations need to be
+!-- done only once per timestep.
+    timestep_number_at_prev_calc = current_timestep_number
+
+
+    ivar_all = 1
+
+    DO  WHILE ( do_all(ivar_all)(1:1) /= ' ' )
+
+       SELECT CASE ( TRIM( do_all(ivar_all) ) )
+!
+!--       Calculate 'turbulence intensity' from rot[(u,v,w)] at scalar grid point
+          CASE ( 'ti' )
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb+1, nzt
+
+                      ti(k,j,i) = 0.25_wp * SQRT(                                                  &
+                        (   (   w(k,j+1,i) + w(k-1,j+1,i)                                          &
+                              - w(k,j-1,i) - w(k-1,j-1,i) ) * ddy                                  &
+                          - (   v(k+1,j,i) + v(k+1,j+1,i)                                          &
+                              - v(k-1,j,i) - v(k-1,j+1,i) ) * ddzu(k) )**2                         &
+                      + (   (   u(k+1,j,i) + u(k+1,j,i+1)                                          &
+                              - u(k-1,j,i) - u(k-1,j,i+1) ) * ddzu(k)                              &
+                          - (   w(k,j,i+1) + w(k-1,j,i+1)                                          &
+                              - w(k,j,i-1) - w(k-1,j,i-1) ) * ddx     )**2                         &
+                      + (   (   v(k,j,i+1) + v(k,j+1,i+1)                                          &
+                              - v(k,j,i-1) - v(k,j+1,i-1) ) * ddx                                  &
+                          - (   u(k,j+1,i) + u(k,j+1,i+1)                                          &
+                              - u(k,j-1,i) - u(k,j-1,i+1) ) * ddy     )**2  )                      &
+                                          * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0) )
+                   ENDDO
+                ENDDO
+             ENDDO
+
+          END SELECT
+
+          ivar_all = ivar_all + 1
+    ENDDO
+
+!     CALL cpu_log( log_point(41), 'calculate_quantities', 'stop' )
+
+ END SUBROUTINE diagnostic_output_quantities_calculate
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> ...
+!------------------------------------------------------------------------------!
+ SUBROUTINE diagnostic_output_quantities_prepare
+
+
+    USE control_parameters,                                                                        &
+        ONLY:  do2d, do3d, domask, masks, mid
+
+    IMPLICIT NONE
+
+    CHARACTER (LEN=varnamelength), DIMENSION(0:1,500) ::  do2d_var = ' '  !<
+                                                          !< label array for 2d output quantities
+
+    INTEGER(iwp) ::  av         !< index defining type of output, av=0 instantaneous, av=1 averaged
+    INTEGER(iwp) ::  ivar       !< loop index
+    INTEGER(iwp) ::  ivar_all   !< loop index
+    INTEGER(iwp) ::  l          !< index for cutting string
+
+
+    prepared_diagnostic_output_quantities = .FALSE.
+
+    ivar     = 1
+    ivar_all = 1
+
+    DO  av = 0, 1
+!
+!--    Remove _xy, _xz, or _yz from string
+       l = MAX( 3, LEN_TRIM( do2d(av,ivar) ) )
+       do2d_var(av,ivar) = do2d(av,ivar)(0:l-2)
+!
+!--    Gather 2d output quantity names, check for double occurrence of output quantity
+       DO  WHILE ( do2d_var(av,ivar)(1:1) /= ' ' )
+          IF ( .NOT.  ANY( do_all == do2d_var(av,ivar) ) )  THEN
+             do_all(ivar_all) = do2d_var(av,ivar)
+          ENDIF
+          ivar = ivar + 1
+          ivar_all = ivar_all + 1
+          l = MAX( 3, LEN_TRIM( do2d(av,ivar) ) )
+          do2d_var(av,ivar) = do2d(av,ivar)(0:l-2)
+       ENDDO
+
+       ivar = 1
+!
+!--    Gather 3d output quantity names, check for double occurrence of output quantity
+       DO  WHILE ( do3d(av,ivar)(1:1) /= ' ' )
+          do_all(ivar_all) = do3d(av,ivar)
+
+          ivar = ivar + 1
+          ivar_all = ivar_all + 1
+       ENDDO
+
+       ivar = 1
+!
+!--    Gather masked output quantity names, check for double occurrence of output quantity
+       DO  mid = 1, masks
+          DO  WHILE ( domask(mid,av,ivar)(1:1) /= ' ' )
+             do_all(ivar_all) = domask(mid,av,ivar)
+
+             ivar = ivar + 1
+             ivar_all = ivar_all + 1
+          ENDDO
+          ivar = 1
+       ENDDO
+
+    ENDDO
+
+    prepared_diagnostic_output_quantities = .TRUE.
+
+ END SUBROUTINE diagnostic_output_quantities_prepare
+
+ END MODULE diagnostic_output_quantities_mod
Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3993)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3994)
@@ -20,5 +20,4 @@
 ! Current revisions:
 ! -----------------
-! 
 ! 
 ! Former revisions:
Index: palm/trunk/SOURCE/netcdf_interface_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3993)
+++ palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3994)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! output of turbulence intensity added
 ! 
 ! Former revisions:
@@ -1118,5 +1118,5 @@
                 CASE ( 'e', 'nc', 'nr', 'p', 'pc', 'pr', 'prr',                &
                        'q', 'qc', 'ql', 'ql_c', 'ql_v', 'ql_vp', 'qr', 'qv',   &
-                       's', 'theta', 'thetal', 'thetav' )
+                       's', 'theta', 'thetal', 'thetav', 'ti' )
 
                    grid_x = 'x'
@@ -1864,5 +1864,5 @@
                 CASE ( 'e', 'nc', 'nr', 'p', 'pc', 'pr', 'prr',   &
                        'q', 'qc', 'ql', 'ql_c', 'ql_v', 'ql_vp', 'qr', 'qv',   &
-                       's', 'theta', 'thetal', 'thetav' )
+                       's', 'theta', 'thetal', 'thetav', 'ti' )
 
                    grid_x = 'x'
@@ -2852,5 +2852,5 @@
                              'ql_vp_xy', 'qr_xy', 'qv_xy',                     &
                              's_xy',                                           &
-                             'theta_xy', 'thetal_xy', 'thetav_xy' )
+                             'theta_xy', 'thetal_xy', 'thetav_xy', 'ti_xy' )
 
                          grid_x = 'x'
@@ -3756,5 +3756,5 @@
                           'ql_xz', 'ql_c_xz', 'ql_v_xz', 'ql_vp_xz', 'qr_xz',  &
                           'qv_xz', 's_xz',                                     &
-                          'theta_xz', 'thetal_xz', 'thetav_xz'                 )
+                          'theta_xz', 'thetal_xz', 'thetav_xz', 'ti_xz' )
 
                       grid_x = 'x'
@@ -4615,5 +4615,5 @@
                           'ql_c_yz', 'ql_v_yz', 'ql_vp_yz', 'qr_yz', 'qv_yz',  &
                           's_yz',                                              &
-                          'theta_yz', 'thetal_yz', 'thetav_yz' )
+                          'theta_yz', 'thetal_yz', 'thetav_yz', 'ti_yz' )
 
                       grid_x = 'x'
@@ -5994,5 +5994,5 @@
                        'q', 'qc', 'ql', 'ql_c', 'ql_v', 'ql_vp', 'qr', 'qv',   &
                        'rho_sea_water', 's', 'sa', &
-                       'theta', 'thetal', 'thetav', 'u', 'v' )
+                       'theta', 'thetal', 'thetav', 'ti', 'u', 'v' )
 
                    grid_z = 'zu'
Index: palm/trunk/SOURCE/palm.f90
===================================================================
--- palm/trunk/SOURCE/palm.f90	(revision 3993)
+++ palm/trunk/SOURCE/palm.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! new module for calculation and output of diagnostic quantities added
+! 
+! 3885 2019-04-11 11:29:34Z kanani
 ! Changes related to global restructuring of location messages and introduction 
 ! of additional debug messages
@@ -300,4 +303,8 @@
     USE date_and_time_mod,                                                     &
         ONLY:  calc_date_and_time, init_date_and_time
+
+    USE diagnostic_output_quantities_mod,                                      &
+        ONLY:  diagnostic_output_quantities_calculate,                         &
+               timestep_number_at_prev_calc
 
     USE indices,                                                               &
@@ -558,4 +565,6 @@
 !-- If required, output of initial arrays
     IF ( do2d_at_begin )  THEN
+       CALL diagnostic_output_quantities_calculate    !TODO, will be called twice
+
        CALL data_output_2d( 'xy', 0 )
        CALL data_output_2d( 'xz', 0 )
@@ -564,4 +573,6 @@
 
     IF ( do3d_at_begin )  THEN
+       CALL diagnostic_output_quantities_calculate    !TODO, will be called twice
+
        CALL data_output_3d( 0 )
     ENDIF
Index: palm/trunk/SOURCE/read_restart_data_mod.f90
===================================================================
--- palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3993)
+++ palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3988 2019-05-22 11:32:37Z kanani
 ! + time_virtual_measurement (to enable steering of output interval)
 ! 
@@ -124,4 +127,7 @@
     USE date_and_time_mod,                                                     &
         ONLY:  day_of_year_init, time_utc_init
+
+    USE diagnostic_output_quantities_mod,                                      &
+        ONLY:  ti_av
 
     USE grid_variables,                                                        &
@@ -1093,4 +1099,5 @@
     REAL(wp), DIMENSION(:,:),   ALLOCATABLE   ::  tmp_2d      !< temporary array for storing 2D data
     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3d      !< temporary array for storing 3D data
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3d_noghost  !< temporary array for storing 3D data without ghost points
     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwul   !<
     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwun   !<
@@ -1295,5 +1302,7 @@
                         nxl_on_file-nbgp:nxr_on_file+nbgp),                    &
                  tmp_3d(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,           &
-                        nxl_on_file-nbgp:nxr_on_file+nbgp) )
+                        nxl_on_file-nbgp:nxr_on_file+nbgp),                    &
+                 tmp_3d_noghost(nzb:nzt+1,nys_on_file:nyn_on_file,             &
+                        nxl_on_file:nxr_on_file) )
 
 !
@@ -1576,5 +1585,13 @@
                    ssws_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  =         &
                       tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-                 
+
+                CASE ( 'ti_av' )
+                   IF ( .NOT. ALLOCATED( ti_av ) )  THEN
+                      ALLOCATE( ti_av(nzb:nzt+1,nys:nyn,nxl:nxr) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d_noghost
+                   ti_av(:,nysc:nync,nxlc:nxrc) =                              &
+                      tmp_3d_noghost(:,nysf:nynf,nxlf:nxrf)
+
                 CASE ( 'ts_av' )
                    IF ( .NOT. ALLOCATED( ts_av ) )  THEN
Index: palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3993)
+++ palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3943 2019-05-02 09:50:41Z maronga
 ! Added output of qsws_av for green roofs.
 ! 
@@ -283,4 +286,7 @@
     USE cpulog,                                                                &
         ONLY:  cpu_log, log_point
+
+    USE diagnostic_output_quantities_mod,                                      &
+        ONLY:  ti, ti_av
 
     USE indices,                                                               &
@@ -472,4 +478,10 @@
                 ENDIF
                 tsurf_av = 0.0_wp
+
+             CASE ( 'ti' )
+                IF ( .NOT. ALLOCATED( ti_av ) )  THEN
+                   ALLOCATE( ti_av(nzb:nzt+1,nys:nyn,nxl:nxr) )
+                ENDIF
+                ti_av = 0.0_wp
 
              CASE ( 'u' )
@@ -1019,4 +1031,15 @@
              ENDIF
 
+          CASE ( 'ti' )
+             IF ( ALLOCATED( ti_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb, nzt+1
+                         ti_av(k,j,i) = ti_av(k,j,i) + ti(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
+
           CASE ( 'u' )
              IF ( ALLOCATED( u_av ) ) THEN
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 3993)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3988 2019-05-22 11:32:37Z kanani
 ! Implement steerable output interval for virtual measurements
 ! 
@@ -561,4 +564,8 @@
     USE date_and_time_mod,                                                                         &
         ONLY:  calc_date_and_time, hour_call_emis, hour_of_year
+
+    USE diagnostic_output_quantities_mod,                                                          &
+        ONLY:  diagnostic_output_quantities_calculate,                                             &
+               timestep_number_at_prev_calc
 
     USE flight_mod,                                                                                &
@@ -1655,4 +1662,7 @@
           time_do_sla = time_do_sla + dt_3d
           IF ( time_do_sla >= dt_averaging_input )  THEN
+             IF ( current_timestep_number > timestep_number_at_prev_calc )                         &
+                CALL diagnostic_output_quantities_calculate
+
              CALL sum_up_3d_data
              average_count_3d = average_count_3d + 1
@@ -1733,12 +1743,21 @@
 !--    2d-data output (cross-sections)
        IF ( time_do2d_xy >= dt_do2d_xy  .AND.  time_since_reference_point >= skip_time_do2d_xy )  THEN
+          IF ( current_timestep_number > timestep_number_at_prev_calc )                            &
+             CALL diagnostic_output_quantities_calculate
+
           CALL data_output_2d( 'xy', 0 )
           time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
        ENDIF
        IF ( time_do2d_xz >= dt_do2d_xz  .AND.  time_since_reference_point >= skip_time_do2d_xz )  THEN
+          IF ( current_timestep_number > timestep_number_at_prev_calc )                            &
+
+             CALL diagnostic_output_quantities_calculate
           CALL data_output_2d( 'xz', 0 )
           time_do2d_xz = MOD( time_do2d_xz, MAX( dt_do2d_xz, dt_3d ) )
        ENDIF
        IF ( time_do2d_yz >= dt_do2d_yz  .AND.  time_since_reference_point >= skip_time_do2d_yz )  THEN
+          IF ( current_timestep_number > timestep_number_at_prev_calc )                            &
+             CALL diagnostic_output_quantities_calculate
+
           CALL data_output_2d( 'yz', 0 )
           time_do2d_yz = MOD( time_do2d_yz, MAX( dt_do2d_yz, dt_3d ) )
@@ -1748,4 +1767,7 @@
 !--    3d-data output (volume data)
        IF ( time_do3d >= dt_do3d  .AND.  time_since_reference_point >= skip_time_do3d )  THEN
+          IF ( current_timestep_number > timestep_number_at_prev_calc )                            &
+             CALL diagnostic_output_quantities_calculate
+
           CALL data_output_3d( 0 )
           time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
@@ -1757,4 +1779,7 @@
           IF ( time_domask(mid) >= dt_domask(mid)                                                  &
                .AND.  time_since_reference_point >= skip_time_domask(mid) )  THEN
+             IF ( current_timestep_number > timestep_number_at_prev_calc )                         &
+                CALL diagnostic_output_quantities_calculate
+
              CALL data_output_mask( 0 )
              time_domask(mid) = MOD( time_domask(mid), MAX( dt_domask(mid), dt_3d ) )
Index: palm/trunk/SOURCE/write_restart_data_mod.f90
===================================================================
--- palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3993)
+++ palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3994)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of turbulence intensity added
+! 
+! 3988 2019-05-22 11:32:37Z kanani
 ! + time_virtual_measurement (to enable steering of output interval)
 ! 
@@ -92,4 +95,7 @@
         ONLY:  day_of_year_init, time_utc_init
 
+    USE diagnostic_output_quantities_mod,                                      &
+        ONLY:  ti_av
+
     USE grid_variables,                                                        &
         ONLY:  dx, dy
@@ -1076,4 +1082,9 @@
        ENDIF
 
+       IF ( ALLOCATED( ti_av ) )  THEN
+          CALL wrd_write_string( 'ti_av' ) 
+          WRITE ( 14 )  ti_av
+       ENDIF
+
        IF ( ALLOCATED( ts_av ) )  THEN
           CALL wrd_write_string( 'ts_av' ) 
