checkstop Subroutine

public subroutine checkstop(exit, exit_reason, list)

Check whether the stop file .stop is present, and if so trigger exit.

Arguments

Type IntentOptional Attributes Name
logical, intent(inout) :: exit
type(exit_code), intent(inout) :: exit_reason
logical, intent(in), optional :: list

Contents

Source Code


Source Code

  subroutine checkstop(exit, exit_reason, list)
    use mp, only: proc0, broadcast
    use file_utils, only: run_name, list_name
    use constants, only: run_name_size
    use exit_codes, only: EXIT_STOP_FILE, exit_code
    use optionals, only: get_option_with_default
    implicit none
    logical, intent (in), optional :: list
    logical, intent (in out) :: exit
    type(exit_code), intent (in out) :: exit_reason
    character(run_name_size) :: filename
    logical :: exit_local, is_list

    ! If .stop file has appeared, set exit flag
    if (proc0) then
       is_list = get_option_with_default(list, .false.)
       if (is_list) then
          filename = list_name(:len_trim(list_name)-5)//".stop"
       else
          filename = trim(run_name)//".stop"
       end if

       inquire(file = filename, exist = exit_local)
       if (exit_local) then
          exit_reason = EXIT_STOP_FILE
          call exit_reason%write_exit_file()
       end if
       exit = exit .or. exit_local
    end if

    call broadcast (exit)
  end subroutine checkstop