Index: palm/trunk/SOURCE/check_for_restart.f90
===================================================================
--- palm/trunk/SOURCE/check_for_restart.f90	(revision 4901)
+++ palm/trunk/SOURCE/check_for_restart.f90	(revision 1)
@@ -1,34 +1,46 @@
-!> @file check_for_restart.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-2021 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------------------------!
-!
-! Current revisions:
+ SUBROUTINE check_for_restart
+
+!------------------------------------------------------------------------------!
+! Actual revisions:
 ! -----------------
 ! 
-! 
+!
 ! Former revisions:
 ! -----------------
-! $Id$
-! file re-formatted to follow the PALM coding standard
+! $Log: check_for_restart.f90,v $
+! Revision 1.11  2007/02/11 12:55:13  raasch
+! Informative output to the job protocol
 !
-! 4360 2020-01-07 11:25:50Z suehring
-! Corrected "Former revisions" section
+! Revision 1.10  2003/03/16 09:27:49  raasch
+! Two underscores (_) are placed in front of all define-strings
 !
-! 3655 2019-01-07 16:51:22Z knoop
-! Error messages revised
+! Revision 1.9  2002/12/19 13:48:59  raasch
+! Stop flag is also set in case of user forced restarts, routine name
+! changed from check_cpu_time to check_for_restart, the run description
+! header will be written on file CONTINUE_RUN
+!
+! Revision 1.8  2001/08/21 08:22:23  raasch
+! MPI_ALLREDUCE moved out of IF-clause
+!
+! Revision 1.7  2001/03/30 06:56:28  raasch
+! Translation of remaining German identifiers (variables, subroutines, etc.)
+!
+! Revision 1.6  2001/01/22 05:36:33  raasch
+! Module test_variables removed
+!
+! Revision 1.5  2001/01/02 17:19:27  raasch
+! Initial value of terminate_run_l is set to .FALSE. (undefined before).
+! Flag file will only be created by PE0. Unit 90 is used instead of 91.
+!
+! Revision 1.4  2000/01/21 16:27:59  letzel
+! All comments translated into English
+!
+! Revision 1.3  1998/07/06 12:07:47  raasch
+! + USE test_variables
+!
+! Revision 1.2  1998/03/24 15:24:54  raasch
+! Lauf wird nur dann beendet und Fortsetzungslauf gestartet, falls auch eine
+! Abspeicherung der entsprechenden Binaerdateien vorgesehen ist.
+! Beendigung der Rechnung auf mehreren Prozessoren richtig implementiert.
 !
 ! Revision 1.1  1998/03/18 20:06:51  raasch
@@ -38,30 +50,16 @@
 ! Description:
 ! ------------
-!> Set stop flag, if restart is neccessary because of expiring cpu-time or if it is forced by user.
-!--------------------------------------------------------------------------------------------------!
- SUBROUTINE check_for_restart
-
-
-    USE control_parameters,                                                                        &
-        ONLY:  coupling_mode, dt_restart, end_time, message_string, run_description_header,        &
-               simulated_time, terminate_coupled, terminate_coupled_remote, terminate_run,         &
-               termination_time_needed, time_restart, time_since_reference_point, write_binary
-
-    USE kinds
+! Set stop flag, if restart is neccessary because of expiring cpu-time or
+! if it is forced by user
+!------------------------------------------------------------------------------!
 
     USE pegrid
-
-    USE pmc_interface,                                                                             &
-        ONLY:  comm_world_nesting, cpl_id, nested_run
+    USE control_parameters
 
     IMPLICIT NONE
 
-    INTEGER ::  global_communicator       !< global communicator to be used here
 
-    LOGICAL ::  terminate_run_l           !<
-    LOGICAL ::  do_stop_now = .FALSE.     !<
-    LOGICAL ::  do_restart_now = .FALSE.  !<
-
-    REAL(wp) ::  remaining_time !<
+    LOGICAL :: terminate_run_l
+    REAL ::  remaining_time
 
 
@@ -73,24 +71,16 @@
 !-- If necessary set a flag to stop the model run
     terminate_run_l = .FALSE.
-    IF ( remaining_time <= termination_time_needed  .AND.  write_binary )  THEN
+    IF ( remaining_time <= termination_time_needed  .AND. &
+         write_binary(1:4) == 'true' )  THEN
 
        terminate_run_l = .TRUE.
     ENDIF
 
-!
-!-- Set the global communicator to be used (depends on the mode in which PALM is running)
-    IF ( nested_run )  THEN
-       global_communicator = comm_world_nesting
-    ELSE
-       global_communicator = comm2d
-    ENDIF
-
 #if defined( __parallel )
 !
-!-- Make a logical OR for all processes. Stop the model run if at least one process has reached the
-!-- time limit.
-    IF ( collective_wait )  CALL MPI_BARRIER( global_communicator, ierr )
-    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, MPI_LOR,                   &
-                        global_communicator, ierr )
+!-- Make a logical OR for all processes. Stop the model run if at least
+!-- one processor has reached the time limit.
+    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, &
+                        MPI_LOR, comm2d, ierr )
 #else
     terminate_run = terminate_run_l
@@ -100,141 +90,42 @@
 !-- Output that job will be terminated
     IF ( terminate_run  .AND.  myid == 0 )  THEN
-       WRITE( message_string, * ) 'run will be terminated because it is ',                         &
-                                  'running out of job cpu limit & ',                               &
-                                  'remaining time:         ', remaining_time, ' s &',              &
-                                  'termination time needed:', termination_time_needed, ' s'
-       CALL message( 'check_for_restart', 'PA0163', 0, 1, 0, 6, 0 )
+       PRINT*, '*** WARNING: run will be terminated because it is running out of job cpu', &
+                    'limit'
+       PRINT*, '             remaining time:         ', remaining_time, ' s'
+       PRINT*, '             termination time needed:', termination_time_needed, ' s'
     ENDIF
 
 !
-!-- In case of coupled runs inform the remote model of the termination and its reason, provided the
-!-- remote model has not already been informed of another termination reason (terminate_coupled > 0)
-!-- before, or vice versa (terminate_coupled_remote > 0).
-    IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled'  .AND.                           &
-         terminate_coupled == 0  .AND.  terminate_coupled_remote == 0 )  THEN
-
-       terminate_coupled = 3
-
-#if defined( __parallel )
-       IF ( myid == 0 ) THEN
-          CALL MPI_SENDRECV( 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 )
-#endif
-    ENDIF
-
-
+!-- Set the stop flag also, if restart is forced by user
+    IF ( time_restart /= 9999999.9  .AND.  time_restart < simulated_time ) &
+    THEN
 !
-!-- Check if a flag file exists that forces a termination of the model.
-    IF ( myid == 0 )  THEN
-       INQUIRE(FILE="DO_STOP_NOW", EXIST=do_stop_now)
-       INQUIRE(FILE="DO_RESTART_NOW", EXIST=do_restart_now)
-
-       IF ( do_stop_now .OR. do_restart_now )  THEN
-
-          terminate_run_l = .TRUE.
-
-          WRITE( message_string, * ) 'run will be terminated because user ',                       &
-                                     'forced a job finalization using a flag',                     &
-                                     'file:',                                                      &
-                                     '&DO_STOP_NOW: ', do_stop_now,                                &
-                                     '&DO_RESTART_NOW: ', do_restart_now
-          CALL message( 'check_for_restart', 'PA0398', 0, 0, 0, 6, 0 )
-
-       ENDIF
-    ENDIF
-
-
-#if defined( __parallel )
-!
-!-- Make a logical OR for all processes. Stop the model run if a flag file has been detected above.
-    IF ( collective_wait )  CALL MPI_BARRIER( global_communicator, ierr )
-    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, MPI_LOR,                   &
-                        global_communicator, ierr )
-#else
-    terminate_run = terminate_run_l
-#endif
-
-!
-!-- In case of coupled runs inform the remote model of the termination and its reason, provided the
-!-- remote model has not already been informed of another termination reason (terminate_coupled > 0)
-!-- before, or vice versa (terminate_coupled_remote > 0).
-    IF ( terminate_run .AND. coupling_mode /= 'uncoupled' .AND.                                    &
-         terminate_coupled == 0 .AND.  terminate_coupled_remote == 0 )  THEN
-
-       terminate_coupled = 6
-
-#if defined( __parallel )
-       IF ( myid == 0 ) THEN
-          CALL MPI_SENDRECV( 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 )
-#endif
-
-    ENDIF
-
-!
-!-- Set the stop flag also, if restart is forced by user settings
-    IF ( time_restart /= 9999999.9_wp  .AND.  time_restart < time_since_reference_point )  THEN
-
-!
-!--    Restart is not neccessary, if the end time of the run (given by the user) has been reached.
+!--    Restart is not neccessary, if the end time of the run (given by
+!--    the user) has been reached
        IF ( simulated_time < end_time )  THEN
           terminate_run = .TRUE.
 !
-!--       Increment restart time, if forced by user, otherwise set restart time to default (no user
-!--       restart).
-          IF ( dt_restart /= 9999999.9_wp )  THEN
+!--       Increment restart time, if forced by user, otherwise set restart
+!--       time to default (no user restart)
+          IF ( dt_restart /= 9999999.9 )  THEN
              time_restart = time_restart + dt_restart
           ELSE
-             time_restart = 9999999.9_wp
+             time_restart = 9999999.9
           ENDIF
 
-          WRITE( message_string, * ) 'run will be terminated due to user ',                        &
-                                     'settings of ',                                               &
-                                     'restart_time / dt_restart, ',                                &
-                                     'new restart time is: ', time_restart, ' s'
-          CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 )
-
-!
-!--       In case of coupled runs inform the remote model of the termination and its reason,
-!--       provided the remote model has not already been informed of another termination reason
-!--       (terminate_coupled > 0) before, or vice versa (terminate_coupled_remote > 0).
-          IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0                           &
-               .AND.  terminate_coupled_remote == 0 )  THEN
-
-             IF ( dt_restart /= 9999999.9_wp )  THEN
-                terminate_coupled = 4
-             ELSE
-                terminate_coupled = 5
-             ENDIF
-#if defined( __parallel )
-             IF ( myid == 0 ) THEN
-                CALL MPI_SENDRECV( 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 )
-#endif
+          IF ( myid == 0 )  THEN
+             PRINT*, '*** INFORMATIVE: run will be terminated due to user settings of'
+             PRINT*, '                 restart_time / dt_restart'
+             PRINT*, '                 new restart time is: ', time_restart, ' s'
           ENDIF
-       ELSE
-          time_restart = 9999999.9_wp
+    ELSE
+          time_restart = 9999999.9
        ENDIF
     ENDIF
 
 !
-!-- If the run is stopped, set a flag file which is necessary to initiate the start of a
-!-- continuation run, except if the user forced to stop the run without restart.
-    IF ( terminate_run  .AND.  myid == 0  .AND.  cpl_id == 1  .AND.  .NOT. do_stop_now)  THEN
+!-- If the run is stopped, set a flag file which is necessary to initiate
+!-- the start of a continuation run
+    IF ( terminate_run  .AND.  myid == 0 )  THEN
 
        OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' )
