      SUBROUTINE ERROUT( PRTFIL, SEVRTY, WHERE, ERRMSG )

C     Outputs an error message

C     PRTFIL unit number for print-out
C     SEVRTY:
C        'W' Warning
C        'F' Fatal
C     WHERE  in which program or subroutine
C     ERRMSG error message

      IMPLICIT NONE
      INTEGER PRTFIL, LAST
      CHARACTER SEVRTY *1, WHERE *(*), ERRMSG *(*)

      WRITE( PRTFIL, * )
      WRITE( PRTFIL, * )
      WRITE( PRTFIL, * )

C     *** Severity ***

      IF( SEVRTY(1:1) .EQ. 'W' ) THEN
         WRITE( PRTFIL, * ) '*** WARNING ***'
      ELSE IF( SEVRTY(1:1) .EQ. 'F' ) THEN
         WRITE( PRTFIL, * ) '*** FATAL ERROR ***'
      ELSE
         WRITE( PRTFIL, * ) '*** FATAL ERROR ***'
         WRITE( PRTFIL, * )
     &      'The error handler (ERROUT) has been called ',
     &      'with an unknown severity level: ', SEVRTY(1:1)
      ENDIF

      WRITE( PRTFIL, * )

C     *** Where did it happen? ***

      LAST = LEN( WHERE )
      WRITE( PRTFIL, * ) 'Error detected in program or subroutine: ',
     &                   WHERE( 1:LAST )

C     *** What is the error? ***

      LAST = LEN( ERRMSG )
      WRITE( PRTFIL, * ) ERRMSG(1:LAST)

      WRITE( PRTFIL, * )
      WRITE( PRTFIL, * )
      WRITE( PRTFIL, * )

C     ******

      IF ( SEVRTY(1:1) .EQ. 'W' ) THEN
         RETURN
      ELSE
         STOP 'Fatal Error: See print file for details about '
      ENDIF

      END
