m_errors.f90 Source File

This File Depends On

sourcefile~~m_errors.f90~~EfferentGraph sourcefile~m_errors.f90 m_errors.f90 sourcefile~m_variablekind.f90 m_variableKind.f90 sourcefile~m_variablekind.f90->sourcefile~m_errors.f90
Help

Files Dependent On This One

sourcefile~~m_errors.f90~~AfferentGraph sourcefile~m_errors.f90 m_errors.f90 sourcefile~m_allocate.f90 m_allocate.f90 sourcefile~m_errors.f90->sourcefile~m_allocate.f90 sourcefile~m_read.f90 m_read.f90 sourcefile~m_errors.f90->sourcefile~m_read.f90 sourcefile~m_maths.f90 m_maths.f90 sourcefile~m_errors.f90->sourcefile~m_maths.f90 sourcefile~scale_coretran.f90 scale_coretran.f90 sourcefile~m_errors.f90->sourcefile~scale_coretran.f90 sourcefile~m_deallocate.f90 m_deallocate.f90 sourcefile~m_errors.f90->sourcefile~m_deallocate.f90 sourcefile~m_copy.f90 m_copy.f90 sourcefile~m_errors.f90->sourcefile~m_copy.f90 sourcefile~m_array1d.f90 m_array1D.f90 sourcefile~m_errors.f90->sourcefile~m_array1d.f90 sourcefile~ddynamicarray_class.f90 dDynamicArray_Class.f90 sourcefile~m_errors.f90->sourcefile~ddynamicarray_class.f90 sourcefile~m_tests.f90 m_tests.f90 sourcefile~m_errors.f90->sourcefile~m_tests.f90 sourcefile~idargdynamicarray_class.f90 idArgDynamicArray_Class.f90 sourcefile~m_errors.f90->sourcefile~idargdynamicarray_class.f90 sourcefile~m_write.f90 m_write.f90 sourcefile~m_errors.f90->sourcefile~m_write.f90 sourcefile~rargdynamicarray_class.f90 rArgDynamicArray_Class.f90 sourcefile~m_errors.f90->sourcefile~rargdynamicarray_class.f90 sourcefile~prng_class.f90 Prng_Class.f90 sourcefile~m_errors.f90->sourcefile~prng_class.f90 sourcefile~m_random.f90 m_random.f90 sourcefile~m_errors.f90->sourcefile~m_random.f90 sourcefile~idynamicarray_class.f90 iDynamicArray_Class.f90 sourcefile~m_errors.f90->sourcefile~idynamicarray_class.f90 sourcefile~m_fileio.f90 m_fileIO.f90 sourcefile~m_errors.f90->sourcefile~m_fileio.f90 sourcefile~dargdynamicarray_class.f90 dArgDynamicArray_Class.f90 sourcefile~m_errors.f90->sourcefile~dargdynamicarray_class.f90 sourcefile~m_reallocate.f90 m_reallocate.f90 sourcefile~m_errors.f90->sourcefile~m_reallocate.f90 sourcefile~iddynamicarray_class.f90 idDynamicArray_Class.f90 sourcefile~m_errors.f90->sourcefile~iddynamicarray_class.f90 sourcefile~rdynamicarray_class.f90 rDynamicArray_Class.f90 sourcefile~m_errors.f90->sourcefile~rdynamicarray_class.f90 sourcefile~m_strings.f90 m_strings.f90 sourcefile~m_errors.f90->sourcefile~m_strings.f90 sourcefile~iargdynamicarray_class.f90 iArgDynamicArray_Class.f90 sourcefile~m_errors.f90->sourcefile~iargdynamicarray_class.f90 sourcefile~m_kdtree.f90 m_KdTree.f90 sourcefile~m_errors.f90->sourcefile~m_kdtree.f90 sourcefile~m_unittester.f90 m_unitTester.f90 sourcefile~m_errors.f90->sourcefile~m_unittester.f90 sourcefile~m_allocate.f90->sourcefile~m_maths.f90 sourcefile~m_allocate.f90->sourcefile~scale_coretran.f90 sourcefile~m_allocate.f90->sourcefile~m_copy.f90 sourcefile~m_allocate.f90->sourcefile~m_array1d.f90 sourcefile~m_allocate.f90->sourcefile~ddynamicarray_class.f90 sourcefile~m_allocate.f90->sourcefile~m_tests.f90 sourcefile~m_allocate.f90->sourcefile~prng_class.f90 sourcefile~m_allocate.f90->sourcefile~m_random.f90 sourcefile~m_allocate.f90->sourcefile~idynamicarray_class.f90 sourcefile~m_allocate.f90->sourcefile~m_reallocate.f90 sourcefile~m_allocate.f90->sourcefile~iddynamicarray_class.f90 sourcefile~m_allocate.f90->sourcefile~rdynamicarray_class.f90 sourcefile~m_allocate.f90->sourcefile~m_kdtree.f90 sourcefile~m_read.f90->sourcefile~scale_coretran.f90 sourcefile~m_read.f90->sourcefile~m_fileio.f90 sourcefile~m_maths.f90->sourcefile~scale_coretran.f90 sourcefile~m_maths.f90->sourcefile~m_tests.f90 sourcefile~m_maths.f90->sourcefile~m_kdtree.f90 sourcefile~m_deallocate.f90->sourcefile~m_maths.f90 sourcefile~m_deallocate.f90->sourcefile~ddynamicarray_class.f90 sourcefile~m_deallocate.f90->sourcefile~m_tests.f90 sourcefile~m_deallocate.f90->sourcefile~m_random.f90 sourcefile~m_deallocate.f90->sourcefile~idynamicarray_class.f90 sourcefile~m_deallocate.f90->sourcefile~iddynamicarray_class.f90 sourcefile~m_deallocate.f90->sourcefile~rdynamicarray_class.f90 sourcefile~m_deallocate.f90->sourcefile~m_kdtree.f90 sourcefile~m_copy.f90->sourcefile~scale_coretran.f90 sourcefile~m_copy.f90->sourcefile~m_tests.f90 sourcefile~m_array1d.f90->sourcefile~m_maths.f90 sourcefile~m_array1d.f90->sourcefile~scale_coretran.f90 sourcefile~m_array1d.f90->sourcefile~m_tests.f90 sourcefile~m_array1d.f90->sourcefile~m_kdtree.f90 sourcefile~ddynamicarray_class.f90->sourcefile~m_tests.f90 sourcefile~ddynamicarray_class.f90->sourcefile~dargdynamicarray_class.f90 sourcefile~test_coretran.f90 test_coretran.f90 sourcefile~m_tests.f90->sourcefile~test_coretran.f90 sourcefile~idargdynamicarray_class.f90->sourcefile~m_tests.f90 sourcefile~m_write.f90->sourcefile~scale_coretran.f90 sourcefile~m_write.f90->sourcefile~m_tests.f90 sourcefile~m_write.f90->sourcefile~m_fileio.f90 sourcefile~rargdynamicarray_class.f90->sourcefile~m_tests.f90 sourcefile~prng_class.f90->sourcefile~m_tests.f90 sourcefile~prng_class.f90->sourcefile~m_random.f90 sourcefile~m_random.f90->sourcefile~scale_coretran.f90 sourcefile~m_random.f90->sourcefile~m_array1d.f90 sourcefile~m_random.f90->sourcefile~m_tests.f90 sourcefile~m_random.f90->sourcefile~test_coretran.f90 sourcefile~idynamicarray_class.f90->sourcefile~m_tests.f90 sourcefile~idynamicarray_class.f90->sourcefile~idargdynamicarray_class.f90 sourcefile~idynamicarray_class.f90->sourcefile~rargdynamicarray_class.f90 sourcefile~idynamicarray_class.f90->sourcefile~dargdynamicarray_class.f90 sourcefile~idynamicarray_class.f90->sourcefile~iargdynamicarray_class.f90 sourcefile~idynamicarray_class.f90->sourcefile~m_kdtree.f90 sourcefile~m_fileio.f90->sourcefile~scale_coretran.f90 sourcefile~m_fileio.f90->sourcefile~m_tests.f90 sourcefile~dargdynamicarray_class.f90->sourcefile~m_tests.f90 sourcefile~dargdynamicarray_class.f90->sourcefile~m_kdtree.f90 sourcefile~m_reallocate.f90->sourcefile~scale_coretran.f90 sourcefile~m_reallocate.f90->sourcefile~ddynamicarray_class.f90 sourcefile~m_reallocate.f90->sourcefile~m_tests.f90 sourcefile~m_reallocate.f90->sourcefile~idynamicarray_class.f90 sourcefile~m_reallocate.f90->sourcefile~iddynamicarray_class.f90 sourcefile~m_reallocate.f90->sourcefile~rdynamicarray_class.f90 sourcefile~iddynamicarray_class.f90->sourcefile~m_tests.f90 sourcefile~iddynamicarray_class.f90->sourcefile~idargdynamicarray_class.f90 sourcefile~rdynamicarray_class.f90->sourcefile~m_tests.f90 sourcefile~rdynamicarray_class.f90->sourcefile~rargdynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~m_read.f90 sourcefile~m_strings.f90->sourcefile~scale_coretran.f90 sourcefile~m_strings.f90->sourcefile~m_array1d.f90 sourcefile~m_strings.f90->sourcefile~ddynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~m_tests.f90 sourcefile~m_strings.f90->sourcefile~idargdynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~m_write.f90 sourcefile~m_strings.f90->sourcefile~rargdynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~prng_class.f90 sourcefile~m_strings.f90->sourcefile~m_random.f90 sourcefile~m_strings.f90->sourcefile~idynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~m_fileio.f90 sourcefile~m_strings.f90->sourcefile~dargdynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~iddynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~rdynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~iargdynamicarray_class.f90 sourcefile~m_strings.f90->sourcefile~m_kdtree.f90 sourcefile~stopwatch_class.f90 Stopwatch_Class.f90 sourcefile~m_strings.f90->sourcefile~stopwatch_class.f90 sourcefile~m_debugging.f90 m_debugging.f90 sourcefile~m_strings.f90->sourcefile~m_debugging.f90 sourcefile~iargdynamicarray_class.f90->sourcefile~m_tests.f90 sourcefile~m_kdtree.f90->sourcefile~scale_coretran.f90 sourcefile~m_kdtree.f90->sourcefile~m_tests.f90 sourcefile~m_unittester.f90->sourcefile~m_allocate.f90 sourcefile~m_unittester.f90->sourcefile~m_maths.f90 sourcefile~m_unittester.f90->sourcefile~m_tests.f90 sourcefile~m_unittester.f90->sourcefile~m_random.f90 sourcefile~m_unittester.f90->sourcefile~m_fileio.f90 sourcefile~m_unittester.f90->sourcefile~test_coretran.f90 sourcefile~stopwatch_class.f90->sourcefile~scale_coretran.f90 sourcefile~stopwatch_class.f90->sourcefile~m_tests.f90 sourcefile~progressbar_class.f90 ProgressBar_Class.f90 sourcefile~stopwatch_class.f90->sourcefile~progressbar_class.f90 sourcefile~progressbar_class.f90->sourcefile~scale_coretran.f90 sourcefile~progressbar_class.f90->sourcefile~m_tests.f90
Help

Source Code


Source Code

module m_errors
  !!Module contains error handling procedures
  use iso_fortran_env, only: output_unit
  use variableKind
  implicit none

  integer(i32), parameter :: IO_OPEN = 1
    !! Constant for file open used by fErr
  integer(i32), parameter :: IO_READ = 2
    !! Constant for file read used by fErr
  integer(i32), parameter :: IO_WRITE = 3
    !! Constant for file write used by fErr
  integer(i32), parameter :: IO_CLOSE = 4
    !! Constant for file close used by fErr

contains
  !====================================================================!
  subroutine mErr(istat, aMsg, alloc, iunit)
    !! Checks for successful (de)allocation.  Stops the code.
    !!
    !! Use this after an allocate/deallocate statement
    !! allocate(x(nz,ny,nx), stat=istat); call mErr(istat,'x',1)
    !! deallocate(x, stat=istat); call mErr(istat,'x',2)
    !====================================================================!
    integer(i32), intent(in) :: istat
      !! results of stat=istat in (de)allocate
    character(len=*), intent(in) :: aMsg
      !! Message associated with the (de)allocate
    integer(i32), intent(in) :: alloc
      !! 1 = allocate, 2 = deallocate
    integer(i32), optional, intent(in) :: iunit
      !! Optional file id to write the message to

    character(len=:), allocatable :: tmp

    ! If istat is not zero, there is an error.
    tmp=''
    if (istat /= 0) then
      select case(alloc)
      case(1)
        tmp='Allocating Memory: '//trim(aMsg)
      case(2)
        tmp='Deallocating Memory: '//trim(aMsg)
      end select
      call eMsg(tmp, iunit)
    endif
  end subroutine
  !====================================================================!
  !====================================================================!
  subroutine msg(aMsg, iunit)
    !! Write a message
    !====================================================================!
    character(len=*), intent(in) :: aMsg
      !! Message to write
    integer(i32), optional, intent(in) :: iunit
      !! file id to write the message to

    if (present(iunit)) then
      write(iunit,'(a)') trim(aMsg)
      write(output_unit,'(a)') trim(aMsg)
    else
      write(output_unit,'(a)') trim(aMsg)
    endif
  end subroutine
  !====================================================================!
  !====================================================================!
  subroutine wMsg(aMsg, iunit)
    !! Write a Warning message
    !====================================================================!
    character(len=*), intent(in) :: aMsg
      !! Message to write
    integer(i32), optional, intent(in) :: iunit
      !! file id to write the message to

    call msg('Warning:'//trim(aMsg), iunit)
  end subroutine
  !====================================================================!
  !====================================================================!
  subroutine eMsg(aMsg, iunit)
    !! Write an Error message. Stops the code
    !====================================================================!
    character(len=*), intent(in) :: aMsg
      !! Message to write
    integer(i32), optional, intent(in) :: iunit
      !! file id to write the message to

    call Msg('Error:'//trim(aMsg), iunit)
    if (present(iunit)) close(iunit)
    stop
  end subroutine
  !====================================================================!
  !====================================================================!
  subroutine fErr(istat, fname, flg, iunit)
    !! Checks for a file error
    !====================================================================!
    integer(i32), intent(in) :: istat
      !! Result of iostat=istat for open,read,write,close
    character(len=*), intent(in) :: fname
      !! Name of the file
    integer(i32), intent(in) :: flg
      !! IO_OPEN=Open, IO_READ=Read, IO_WRITE=Write, IO_CLOSE=Close
    integer(i32), optional, intent(in) :: iunit
      !! file id to write the error to

    character(len=:),allocatable :: Amsg

    Amsg=''
    if (istat /= 0) then
      select case(flg)
      case(IO_OPEN)
        Amsg='Opening file: '//trim(fname)
      case(IO_READ)
        Amsg='Reading from: '//trim(fname)
      case(IO_WRITE)
        Amsg='Writing to file: '//trim(fname)
      case(IO_CLOSE)
        Amsg='Closing file: '//trim(fname)
      case default
        Amsg='Error:Invalid error flag [1-4]'
      end select

      call eMsg(aMsg, iunit)
    endif
  end subroutine
  !====================================================================!
end module m_errors