	SUBROUTINE FINISH
C
C	Performs cleanup and exits to the system for VAXNET.
C
	INCLUDE 'COM.INC/NOLIST'
C
C	Set up the messages.
C
	CHARACTER*(*) DEALLOCATE, DONE_MESSAGE, HANGUP_MESSAGE

	PARAMETER (DEALLOCATE = SS//
	1 '*** Don''t forget to DEALLOCATE ')
	PARAMETER (DONE_MESSAGE = SS//
	1 '*** Normal VAXNET Termination ***'//SS)
	PARAMETER (HANGUP_MESSAGE = SS//
	1 '*** Don''t forget to hangup the modem !!! ***'//BELL//SS)

C
C	If we're using a modem, and hangup is true, hangup the modem.
C
C	CALL SETUP_REMOTE(.TRUE.)		! Establish remote status.
	EXITING = .TRUE.			! Show we're exiting ...
	IF (MODEM) THEN
		IF (HANGUP) THEN
			CALL HANGUP_MODEM()	! Hangup the modem.
		ELSE
			CALL WRITE_USER(HANGUP_MESSAGE)
		ENDIF
	ENDIF
	IF (NEED_TO_DEAL)
	1	CALL WRITE_USER(DEALLOCATE//REMOTE_DEVICE//' ***'//BELL//SS)
	CALL WRITE_USER(DONE_MESSAGE)		! Type the done message.
	CALL FLUSH_LOGFILE			! Empty the logfile buffer.
C
C	If a logfile is open, we close it and execute the REFormat
C	program when we exit to automatically reformat the file.
C
	IF (LOGFILE) THEN
		CLOSE (UNIT=LOG_UNIT)		! Close the logfile.
		CALL LIB$DO_COMMAND('MCR REF '//LOG_FILE(1:LOGFILE_SIZE))
	ENDIF
	CALL SYS$EXIT(%VAL(SS$_NORMAL))		! And exit.
	END

	SUBROUTINE HANGUP_MODEM
C
C	This routine is called to hangup the modem.
C
	INCLUDE 'COM.INC/NOLIST'

	IF (.NOT. NEED_TO_DEAS) RETURN		! Don't have a remote port.
C	CALL SETUP_REMOTE(.TRUE.)		! Establish remote status.
	IF (MODEM) THEN
		MODEM_ONLINE = .FALSE.		! Show modem is offline.
		REMOTE = .FALSE.		! Show modem is hungup.
		REMOTE_STATUS = SYS$QIOW(%VAL(REFN_IN),%VAL(RCHAN_IN),
	1			%VAL(IO$_SETMODE + IO$M_HANGUP),
	1			RIOSB,,,,,,,,)
		CALL CHECK_STATUS('HANGUP_MODEM',REMOTE_STATUS)
	ELSE
		RETURN				! Not a modem.
	ENDIF
C
C	If modem is not a RIXON, and we're not exiting, wait for DTR
C	to return so autodial will work properly (for REDIAL command).
C
	IF (AUTODIAL) THEN
	    IF (AUTODIAL_TYPE .NE. RIXON) THEN
		IF (.NOT. EXITING) THEN
		    CALL WAITABIT('05.0')	! Wait for DTR to return.
		ENDIF
	    ENDIF
	ENDIF
C
C	If using an autodial modem, reset the modem for the next time.
C
	IF (AUTODIAL) THEN
		IF (AUTODIAL_TYPE .EQ. DF03) THEN
			CALL WRITE_BYTE(SOH,1)	! CTRL/A to abort ACU.
		ELSEIF (AUTODIAL_TYPE .EQ. RIXON) THEN
			CALL SIGNOFF_RIXON()	! Signoff the RIXON.
		ENDIF
	ENDIF
	RETURN
	END
