MODULE ErrorProcess
      INTEGER  :: WinHandle   ! This is the Windows handle used to pass messages back to the GUI (unused here)
      INTEGER  :: ErrorLevel
      CHARACTER (LEN=255) :: ErrorMessage
CONTAINS
!-----------------------------------------------------------------------------
      SUBROUTINE PassMsg
      PRINT *, TRIM(ErrorMessage)                       ! for use as DOS program
      END SUBROUTINE PassMsg

!-----------------------------------------------------------------------------
      SUBROUTINE WriteErrorMessage(Message, Prefix, LogFileUnit, ToUser)
      IMPLICIT NONE
      CHARACTER(LEN=*), INTENT(IN) :: Message, Prefix
      INTEGER,          INTENT(IN) :: LogFileUnit
      LOGICAL,          INTENT(IN) :: ToUser

      INTEGER :: IOS      
      CHARACTER(LEN=250) :: Msg
      
      Msg = TRIM(Message)

      IF (LogFileUnit .GT. 0) THEN
         WRITE(LogFileUnit, *, IOSTAT=IOS) TRIM(Msg)
      END IF
      
      IF (ToUser) THEN
         ErrorMessage = TRIM(Msg)
      ELSE
         ErrorMessage = TRIM(Prefix) // TRIM(Msg)
      END IF
      CALL PassMsg

      END SUBROUTINE WriteErrorMessage
      
END MODULE ErrorProcess
