! This routine prints a warning message and goes on
! Inspired  from Die in Siesta 3.1 
    SUBROUTINE Warning(routine, msg, file, line, unit)

      Use VarTypes
      Use io_module

      implicit none


  INTERFACE
     function valid(string) result (isValid)
       CHARACTER(*), intent(in) :: string
       logical                  :: isValid
     END function VALID

  END INTERFACE
!--------------------------------------------------------------- Input Variables
      character(len=*), intent(in)           :: routine, msg
      character(len=*), intent(in), optional :: file
      integer(KINT), intent(in), optional      :: line, unit

!--------------------------------------------------------------- Local Variables
      integer(KINT)                            :: warning_unit

      LOGICAL ::  Debug

!------------------------------------------------------------------------- BEGIN
      debug=valid('warning')

      if (debug) Call Header('Entering Warning')
      if (PRESENT(unit)) then
        warning_unit = unit
      else
        warning_unit = IOOUT
      endif

      write(warning_unit,'(a)') '*************************************************************'
      write(warning_unit,'(a)') '* WARNING *'
      write(warning_unit,'(a)') ' '
      write(warning_unit,'(3a)') TRIM(routine), ': ', TRIM(msg)
      write(warning_unit,'(a)') ' '
      if (PRESENT(file)) write(warning_unit,'(5x,2a)') 'File: ', file
      if (PRESENT(line)) write(warning_unit,'(5x,a,i5)') 'Line: ', line
      write(warning_unit,'(a)') '*************************************************************'

      if (debug) Call Header('Exiting Warning')

    END SUBROUTINE warning

