!*******************************************************************************
!$RCSfile$
!$Revision$
!$Date$
!*******************************************************************************
!*******************************************************************************
!            Exit SCIP Tool
!*******************************************************************************
INTEGER FUNCTION ExitTool()

USE SCIMgr_fd
USE files_fi
USE SCIMgr_fi
USE search_fd
USE SCIMgrState

IMPLICIT NONE

INTEGER irv, ios
INTEGER currentState

INTEGER, EXTERNAL :: ExitPlotTool, SWIMexit

ExitTool = SCIPfailure

IF( SCIMgrCheckState(HS_IDLESTATE) )THEN !Available only while idle
  currentState = SCIMgrSetState( HS_BUSY )
ELSE
  CALL SCIMgrSetBusyMsg()
  RETURN
END IF

!==== Exit UTM

IF( AvailUTM )THEN
END IF

!==== Exit SWIM

irv = SWIMexit()

!==== Clear SAG linked list

irv = ExitPlotTool()

!==== Deallocate memory

CALL scipuff_deallocate()

!==== Set return value

ExitTool = SCIPsuccess

irv = SCIMgrSetState( currentState )

RETURN
END
