Index: /palm/trunk/SOURCE/pres.f90
===================================================================
--- /palm/trunk/SOURCE/pres.f90	(revision 1907)
+++ /palm/trunk/SOURCE/pres.f90	(revision 1908)
@@ -19,5 +19,6 @@
 ! Current revisions:
 ! ------------------
-! 
+! New divergence for output into RUN_CONTROL file is calculated only at last 
+! Runge-Kutta step
 ! 
 ! Former revisions:
@@ -107,9 +108,9 @@
         ONLY:  bc_lr_cyc, bc_ns_cyc, conserve_volume_flow, dt_3d,              &
                gathered_size, ibc_p_b, ibc_p_t, intermediate_timestep_count,   &
-               mg_switch_to_pe0_level, nest_domain, nest_bound_l,              &
-               nest_bound_n, nest_bound_r, nest_bound_s, on_device, outflow_l, &
-               outflow_n, outflow_r, outflow_s, psolver, simulated_time,       &
-               subdomain_size, topography, volume_flow, volume_flow_area,      &
-               volume_flow_initial
+               intermediate_timestep_count_max, mg_switch_to_pe0_level,        &
+               nest_domain, nest_bound_l, nest_bound_n, nest_bound_r,          &
+               nest_bound_s, on_device, outflow_l, outflow_n, outflow_r,       &
+               outflow_s, psolver, simulated_time, subdomain_size, topography, &
+               volume_flow, volume_flow_area, volume_flow_initial
 
     USE cpulog,                                                                &
@@ -359,7 +360,8 @@
     ENDDO
 
-    localsum = localsum + threadsum * dt_3d * &
-                          weight_pres(intermediate_timestep_count)
-
+    IF ( intermediate_timestep_count == intermediate_timestep_count_max )  THEN
+       localsum = localsum + threadsum * dt_3d * &
+                             weight_pres(intermediate_timestep_count)
+    ENDIF
     !$OMP END PARALLEL
 #else
@@ -383,19 +385,22 @@
 
 !
-!-- Compute possible PE-sum of divergences for flow_statistics
-    !$OMP PARALLEL PRIVATE (i,j,k) FIRSTPRIVATE(threadsum) REDUCTION(+:localsum)
-    !$OMP DO SCHEDULE( STATIC )
-    !$acc parallel loop collapse(3) present( d ) reduction(+:threadsum)
-    DO  i = nxl, nxr
-       DO  j = nys, nyn
-          DO  k = nzb+1, nzt
-             threadsum = threadsum + ABS( d(k,j,i) )
-          ENDDO
-       ENDDO
-    ENDDO
-    !$acc end parallel loop
-    localsum = localsum + threadsum * dt_3d * &
-                          weight_pres(intermediate_timestep_count)
-    !$OMP END PARALLEL
+!-- Compute possible PE-sum of divergences for flow_statistics. Carry out
+!-- computation only at last Runge-Kutta substep.
+    IF ( intermediate_timestep_count == intermediate_timestep_count_max )  THEN
+       !$OMP PARALLEL PRIVATE (i,j,k) FIRSTPRIVATE(threadsum) REDUCTION(+:localsum)
+       !$OMP DO SCHEDULE( STATIC )
+       !$acc parallel loop collapse(3) present( d ) reduction(+:threadsum)
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+             DO  k = nzb+1, nzt
+                threadsum = threadsum + ABS( d(k,j,i) )
+             ENDDO
+          ENDDO
+       ENDDO
+       !$acc end parallel loop
+       localsum = localsum + threadsum * dt_3d * &
+                             weight_pres(intermediate_timestep_count)
+       !$OMP END PARALLEL
+    ENDIF
 #endif
 
@@ -403,5 +408,6 @@
 !-- For completeness, set the divergence sum of all statistic regions to those
 !-- of the total domain
-    sums_divold_l(0:statistic_regions) = localsum
+    IF ( intermediate_timestep_count == intermediate_timestep_count_max )      &
+       sums_divold_l(0:statistic_regions) = localsum
 
     CALL cpu_log( log_point_s(1), 'divergence', 'stop' )
@@ -726,67 +732,71 @@
 !
 !-- Compute the divergence of the corrected velocity field,
-!-- a possible PE-sum is computed in flow_statistics 
-    CALL cpu_log( log_point_s(1), 'divergence', 'start' )
-    sums_divnew_l = 0.0_wp
-
-!
-!-- d must be reset to zero because it can contain nonzero values below the
-!-- topography
-    IF ( topography /= 'flat' )  d = 0.0_wp
-
-    localsum  = 0.0_wp
-    threadsum = 0.0_wp
-
-    !$OMP PARALLEL PRIVATE (i,j,k) FIRSTPRIVATE(threadsum) REDUCTION(+:localsum)
-    !$OMP DO SCHEDULE( STATIC )
+!-- A possible PE-sum is computed in flow_statistics. Carry out computation
+!-- only at last Runge-Kutta step.
+    IF ( intermediate_timestep_count == intermediate_timestep_count_max )  THEN 
+       CALL cpu_log( log_point_s(1), 'divergence', 'start' )
+       sums_divnew_l = 0.0_wp
+
+!
+!--    d must be reset to zero because it can contain nonzero values below the
+!--    topography
+       IF ( topography /= 'flat' )  d = 0.0_wp
+
+       localsum  = 0.0_wp
+       threadsum = 0.0_wp
+
+       !$OMP PARALLEL PRIVATE (i,j,k) FIRSTPRIVATE(threadsum) REDUCTION(+:localsum)
+       !$OMP DO SCHEDULE( STATIC )
 #if defined( __ibm )
-    DO  i = nxl, nxr
-       DO  j = nys, nyn
-          DO  k = nzb_s_inner(j,i)+1, nzt
-             d(k,j,i) = ( u(k,j,i+1) - u(k,j,i) ) * ddx + &
-                        ( v(k,j+1,i) - v(k,j,i) ) * ddy + &
-                        ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k)
-          ENDDO
-          DO  k = nzb+1, nzt
-             threadsum = threadsum + ABS( d(k,j,i) )
-          ENDDO
-       ENDDO
-    ENDDO
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+             DO  k = nzb_s_inner(j,i)+1, nzt
+                d(k,j,i) = ( u(k,j,i+1) - u(k,j,i) ) * ddx +                   &
+                           ( v(k,j+1,i) - v(k,j,i) ) * ddy +                   &
+                           ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k)
+             ENDDO
+             DO  k = nzb+1, nzt
+                threadsum = threadsum + ABS( d(k,j,i) )
+             ENDDO
+          ENDDO
+       ENDDO
 #else
-    !$acc kernels present( d, ddzw, rflags_s_inner, u, v, w )
-    !$acc loop collapse( 3 )
-    DO  i = nxl, nxr
-       DO  j = nys, nyn
-          DO  k = 1, nzt
-                d(k,j,i) = ( ( u(k,j,i+1) - u(k,j,i) ) * ddx +   &
-                             ( v(k,j+1,i) - v(k,j,i) ) * ddy +   &
-                             ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) &
-                           ) * rflags_s_inner(k,j,i)
-          ENDDO
-       ENDDO
-    ENDDO
-    !$acc end kernels
-!
-!-- Compute possible PE-sum of divergences for flow_statistics
-    !$acc parallel loop collapse(3) present( d ) reduction(+:threadsum)
-    DO  i = nxl, nxr
-       DO  j = nys, nyn
-          DO  k = nzb+1, nzt
-             threadsum = threadsum + ABS( d(k,j,i) )
-          ENDDO
-       ENDDO
-    ENDDO
-    !$acc end parallel loop
+       !$acc kernels present( d, ddzw, rflags_s_inner, u, v, w )
+       !$acc loop collapse( 3 )
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+             DO  k = 1, nzt
+                   d(k,j,i) = ( ( u(k,j,i+1) - u(k,j,i) ) * ddx +              &
+                                ( v(k,j+1,i) - v(k,j,i) ) * ddy +              &
+                                ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k)            &
+                              ) * rflags_s_inner(k,j,i)
+             ENDDO
+          ENDDO
+       ENDDO
+       !$acc end kernels
+!
+!--    Compute possible PE-sum of divergences for flow_statistics
+       !$acc parallel loop collapse(3) present( d ) reduction(+:threadsum)
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+             DO  k = nzb+1, nzt
+                threadsum = threadsum + ABS( d(k,j,i) )
+             ENDDO
+          ENDDO
+       ENDDO
+       !$acc end parallel loop
 #endif
 
-    localsum = localsum + threadsum
-    !$OMP END PARALLEL
-
-!
-!-- For completeness, set the divergence sum of all statistic regions to those
-!-- of the total domain
-    sums_divnew_l(0:statistic_regions) = localsum
-
-    CALL cpu_log( log_point_s(1), 'divergence', 'stop' )
+       localsum = localsum + threadsum
+       !$OMP END PARALLEL
+
+!
+!--    For completeness, set the divergence sum of all statistic regions to those
+!--    of the total domain
+       sums_divnew_l(0:statistic_regions) = localsum
+
+       CALL cpu_log( log_point_s(1), 'divergence', 'stop' )
+
+    ENDIF
 
     CALL cpu_log( log_point(8), 'pres', 'stop' )
