Index: palm/trunk/SOURCE/timestep.f90
===================================================================
--- palm/trunk/SOURCE/timestep.f90	(revision 2119)
+++ palm/trunk/SOURCE/timestep.f90	(revision 2130)
@@ -20,5 +20,7 @@
 ! Current revisions:
 ! ------------------
-! 
+! bugfix: in case of nested runs the stop condition in case of too small
+! timesteps is communicated to all parent/child processes,
+! some formatting done
 ! 
 ! Former revisions:
@@ -123,4 +125,7 @@
     USE pegrid
 
+    USE pmc_interface,                                                         &
+        ONLY:  nested_run
+
     USE statistics,                                                            &
         ONLY:  flow_statistics_called, hom, u_max, u_max_ijk, v_max, v_max_ijk,&
@@ -132,4 +137,6 @@
     INTEGER(iwp) ::  j !< 
     INTEGER(iwp) ::  k !< 
+
+    LOGICAL ::  stop_dt_local !< local switch for controlling the time stepping
 
     REAL(wp) ::  div               !< 
@@ -193,9 +200,11 @@
              ENDDO
           ENDDO
-          uv_gtrans_l(1) = u_gtrans_l / REAL( (nxr-nxl+1)*(nyn-nys+1)*(nzt-nzb), KIND=wp )
-          uv_gtrans_l(2) = v_gtrans_l / REAL( (nxr-nxl+1)*(nyn-nys+1)*(nzt-nzb), KIND=wp )
+          uv_gtrans_l(1) = u_gtrans_l /                                        &
+                           REAL( (nxr-nxl+1)*(nyn-nys+1)*(nzt-nzb), KIND=wp )
+          uv_gtrans_l(2) = v_gtrans_l /                                        &
+                           REAL( (nxr-nxl+1)*(nyn-nys+1)*(nzt-nzb), KIND=wp )
 #if defined( __parallel )
           IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-          CALL MPI_ALLREDUCE( uv_gtrans_l, uv_gtrans, 2, MPI_REAL, MPI_SUM, &
+          CALL MPI_ALLREDUCE( uv_gtrans_l, uv_gtrans, 2, MPI_REAL, MPI_SUM,    &
                               comm2d, ierr )
           u_gtrans = uv_gtrans(1) / REAL( numprocs, KIND=wp )
@@ -229,7 +238,10 @@
           DO  j = nys, nyn
              DO  k = nzb+1, nzt
-                dt_u_l = MIN( dt_u_l, ( dx     / ( ABS( u(k,j,i) - u_gtrans ) + 1.0E-10_wp ) ) )
-                dt_v_l = MIN( dt_v_l, ( dy     / ( ABS( v(k,j,i) - v_gtrans ) + 1.0E-10_wp ) ) )
-                dt_w_l = MIN( dt_w_l, ( dzu(k) / ( ABS( w(k,j,i) )            + 1.0E-10_wp ) ) )
+                dt_u_l = MIN( dt_u_l, ( dx     /                               &
+                                 ( ABS( u(k,j,i) - u_gtrans ) + 1.0E-10_wp ) ) )
+                dt_v_l = MIN( dt_v_l, ( dy     /                               &
+                                 ( ABS( v(k,j,i) - v_gtrans ) + 1.0E-10_wp ) ) )
+                dt_w_l = MIN( dt_w_l, ( dzu(k) /                               &
+                                 ( ABS( w(k,j,i) )            + 1.0E-10_wp ) ) )
              ENDDO
           ENDDO
@@ -254,7 +266,4 @@
 !--    Compute time step according to the diffusion criterion.
 !--    First calculate minimum grid spacing which only depends on index k
-!--    Note: also at k=nzb+1 a full grid length is being assumed, although
-!--          in the Prandtl-layer friction term only dz/2 is used.
-!--          Experience from the old model seems to justify this.
        dt_diff_l = 999999.0_wp
 
@@ -268,6 +277,6 @@
           DO  j = nys, nyn
              DO  k = nzb+1, nzt
-                dt_diff_l = MIN( dt_diff_l, dxyz2_min(k) / &
-                                       ( MAX( kh(k,j,i), km(k,j,i) ) + 1E-20_wp ) )
+                dt_diff_l = MIN( dt_diff_l, dxyz2_min(k) /                     &
+                                    ( MAX( kh(k,j,i), km(k,j,i) ) + 1E-20_wp ) )
              ENDDO
           ENDDO
@@ -276,5 +285,5 @@
 #if defined( __parallel )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( dt_diff_l, dt_diff, 1, MPI_REAL, MPI_MIN, comm2d, &
+       CALL MPI_ALLREDUCE( dt_diff_l, dt_diff, 1, MPI_REAL, MPI_MIN, comm2d,   &
                            ierr )
 #else
@@ -286,6 +295,5 @@
 !--    step minus a reduction (cfl_factor) to be on the safe side.
 !--    The time step must not exceed the maximum allowed value.
-       dt_3d = cfl_factor * MIN( dt_diff, dt_u, dt_v, dt_w,   &
-                                 dt_precipitation )
+       dt_3d = cfl_factor * MIN( dt_diff, dt_u, dt_v, dt_w, dt_precipitation )
        dt_3d = MIN( dt_3d, dt_max )
 
@@ -303,16 +311,16 @@
           stop_dt = .TRUE.
 
-          WRITE( message_string, * ) 'Time step has reached minimum limit.',  &
-               '&dt              = ', dt_3d, ' s  Simulation is terminated.', &
-               '&old_dt          = ', old_dt, ' s',                           &
-               '&dt_u            = ', dt_u, ' s',                             &
-               '&dt_v            = ', dt_v, ' s',                             &
-               '&dt_w            = ', dt_w, ' s',                             &
-               '&dt_diff         = ', dt_diff, ' s',                          &
-               '&u_max           = ', u_max, ' m/s   k=', u_max_ijk(1),       &
-               '  j=', u_max_ijk(2), '  i=', u_max_ijk(3),                    &
-               '&v_max           = ', v_max, ' m/s   k=', v_max_ijk(1),       &
-               '  j=', v_max_ijk(2), '  i=', v_max_ijk(3),                    &
-               '&w_max           = ', w_max, ' m/s   k=', w_max_ijk(1),       &
+          WRITE( message_string, * ) 'Time step has reached minimum limit.',   &
+               '&dt              = ', dt_3d, ' s  Simulation is terminated.',  &
+               '&old_dt          = ', old_dt, ' s',                            &
+               '&dt_u            = ', dt_u, ' s',                              &
+               '&dt_v            = ', dt_v, ' s',                              &
+               '&dt_w            = ', dt_w, ' s',                              &
+               '&dt_diff         = ', dt_diff, ' s',                           &
+               '&u_max           = ', u_max, ' m/s   k=', u_max_ijk(1),        &
+               '  j=', u_max_ijk(2), '  i=', u_max_ijk(3),                     &
+               '&v_max           = ', v_max, ' m/s   k=', v_max_ijk(1),        &
+               '  j=', v_max_ijk(2), '  i=', v_max_ijk(3),                     &
+               '&w_max           = ', w_max, ' m/s   k=', w_max_ijk(1),        &
                '  j=', w_max_ijk(2), '  i=', w_max_ijk(3)
           CALL message( 'timestep', 'PA0312', 0, 1, 0, 6, 0 )
@@ -324,13 +332,24 @@
           IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0 )  THEN
              terminate_coupled = 2
-             IF ( myid == 0 ) THEN
+             IF ( myid == 0 )  THEN
                 CALL MPI_SENDRECV( &
-                     terminate_coupled,        1, MPI_INTEGER, target_id,  0, &
-                     terminate_coupled_remote, 1, MPI_INTEGER, target_id,  0, &
+                     terminate_coupled,        1, MPI_INTEGER, target_id,  0,  &
+                     terminate_coupled_remote, 1, MPI_INTEGER, target_id,  0,  &
                      comm_inter, status, ierr )
              ENDIF
-             CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, ierr)
+             CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0,      &
+                             comm2d, ierr)
           ENDIF
 #endif
+       ENDIF
+
+!
+!--    In case of nested runs all parent/child processes have to terminate if
+!--    one process has set the stop flag, i.e. they need to set the stop flag
+!--    too.
+       IF ( nested_run )  THEN
+          stop_dt_local = stop_dt
+          CALL MPI_ALLREDUCE( stop_dt_local, stop_dt, 1, MPI_LOGICAL, MPI_LOR, &
+                              MPI_COMM_WORLD, ierr )
        ENDIF
 
