	integer function exit_editor
	implicit integer (a-z)
	integer*2 keybuf(9)
	character*4 control
	character*128 file_name
	character*10 record_type
	external std_seq_put,std_seq_useropen
	logical fixed,status
	character*1 semi_colon,blank
	data blank /' '/
	data semi_colon /';'/

	logical called
	common /calls/ called

	logical quit,exit,confirm,edited
	common /eflags/ quit,exit,confirm,edited

	include 'flags.inc'
!
! using two faked character keys
!	first one is longword in ascending order
!	second is word in descending order
!
	data keybuf /2,1,0,3,4,1,1,7,2/

	if (.not. edited) then
		type 22
 22		format(/' No changes made '/)
		exit_editor=1
		return
	 endif

	close(unit=9)

	istat=sor$pass_files('fdmpwork1','fdmpwork2')
	if (.not. istat) call lib$stop(%val(istat))
	istat=sor$init_sort(keybuf)
	if (.not. istat) call lib$stop(%val(istat))
	istat=sor$sort_merge()
	if (.not. istat) call lib$stop(%val(istat))
	istat=sor$end_sort()
	if (.not. istat) call lib$stop(%val(istat))
!
! strip out duplicate records by creating a new file
!
	call strip_dupl
!
! open new file as old file
!
	inquire(unit=3,name=file_name)
	inquire(unit=3,recordtype=record_type)
	if (record_type.eq.'FIXED') then
		fixed=.true.
	 else
		fixed=.false.
	 endif
	inquire(unit=3,recl=record_size)
	isemi=index(file_name,semi_colon)-1
	if (isemi.le.0) stop 'unable to get output file name'
	file_name=file_name(1:isemi)

	if (variable) then
		record_type='VARIABLE'
		control='LIST'
	 else
		control='NONE'
	 endif

	open(unit=4,type='new',name=file_name,useropen=std_seq_useropen,
     1		recordtype=record_type,recl=record_size,
     2		form='unformatted',carriagecontrol=control)

	call update(fixed,irecords)

	inquire(unit=4,name=file_name)
	iblank=index(file_name,blank)-1
	type 10,file_name(1:iblank),irecords
 10	format(/' Created:  ',a,i6,' record(s)'/)
	call clean_up
	edited=.false.
	called=.false.
	close(unit=4)
	exit_editor = 1
	return
	end
