      SUBROUTINE SPAWN_TRGMON ()
C----------------------------------------------------------------------
C-
C-   Purpose and Methods : This Routine spawns a subprocess to run TRGMON
C-
C-   Inputs  : none
C-   Outputs : none
C-   Controls: none
C-
C-   Created   9-NOV-1990   MICHIGAN STATE UNIVERSITY, TRIGGER CONTROL SOFTWARE
C-
C----------------------------------------------------------------------
      IMPLICIT   NONE
C
C *** Include paramaters predeclared in SYS$LIBRARY:FORSYSDEF.TLB
C
      INCLUDE       '($JPIDEF)' 
C
C *** Local Variables
C
      INTEGER        STATUS
      CHARACTER*256  ERRMSG             ! receives VMS error message
      INTEGER        LENGTH
      CHARACTER*15   PRC_NAM 
C
C *** Constants
C
      PARAMETER      ALL = 1+2+4+8      ! request full message from SYS$GETMSG
C
C *** Declaration of External Functions
C
      INTEGER        LIBREP
      INTEGER        LIB$SPAWN 
      INTEGER        LIB$GETJPI 
      INTEGER        SYS$GETMSG
C
C ********************************************************************
C *** Executable starts here
C
      CALL BROADC(.FALSE.)     !Turn off broadcast trapping
C
      STATUS = LIB$GETJPI ( JPI$_PRCNAM,! item
     &                      ,           ! pid
     &                      ,           ! process name
     &                      ,           ! out value
     &                      PRC_NAM,    ! out string
     &                      LENGTH )    ! out len
C
      PRC_NAM = PRC_NAM(1:LENGTH) // '$TRGMON'
C
      CALL OUTMSG( ' Spawning Process ' // PRC_NAM )
C
      STATUS = LIB$SPAWN ( 'TRGMON',    ! command
     &                      ,           ! 'SYS$INPUT'
     &                      ,           ! 'SYS$OUTPUT'
     &                      ,           ! flags
     &                      PRC_NAM,    ! process name
     &                      ,           ! pid
     &                      ,           ! completion status
     &                      ,           ! completion efn
     &                      ,           ! completion ast
     &                      ,           ! completion ast arg
     &                      ,           ! prompt
     &                      , )         ! cli
C
C       display VMS message in case of failure
C
      IF ( STATUS .NE. 1 ) THEN 
        STATUS = SYS$GETMSG( %VAL(STATUS), LENGTH, ERRMSG, %VAL(ALL),)
        CALL OUTMSG( ' ' // ERRMSG(1:LENGTH) )
        CALL OUTMSG( ' you can try $ TRGMON from DCL level' )
        CALL WAITIT ( 2.0 )               
      END IF
C
C       Give operator 1s to read possible screen messages
C
      CALL WAITIT ( 2.0 )               
C
C       Turn on broadcast trapping again
C
      CALL BROADC(.TRUE.)               
C
C       Repaint screen
C
      STATUS = LIBREP ()                
C
C----------------------------------------------------------------------
  999 RETURN
      END
