	Subroutine Add_Sembud

	Parameter (screen=1,sembud=2,Rec_S=52)

	Logical*1	Exists
	Character*52	rec_line
	Character*52	temp_line
	Character*24	Id_Key
	Character*12	Type
	Character*12	Sub_type
	Character*12	disk
	Integer*2	group
	Integer*2	login_Q
	Integer*2	logout_Q
	Real*8		budget
	Integer*2	rate
	Integer*2	length
	Integer*2	IO_err
	Character*1	answer

	Equivalence (rec_line(1:12),type)
	Equivalence (rec_line(13:24),Sub_type)
	Equivalence (rec_line(25:36),disk)
	Equivalence (rec_line(37:38),group)
	Equivalence (rec_line(39:40),login_Q)
	Equivalence (rec_line(41:42),logout_Q)
	Equivalence (rec_line(43:44),rate)
	Equivalence (rec_line(45:52),Budget)

	Inquire (File='MAKACT_FILES:sembud.idx',exist=Exists)
	If (Exists) then 
		Open (unit=sembud,file='MAKACT_FILES:sembud.idx',
     +		status='old',Organization='indexed',access='keyed',
     +		RecordType='fixed',form='unformatted',shared,
     +		key=(1:24,37:38),recordsize=Rec_S)
	else
		Open (unit=sembud,file='MAKACT_FILES:sembud.idx',
     +		status='new',Organization='indexed',access='keyed',
     +		RecordType='fixed',form='unformatted',shared,
     +		key=(1:24,37:38),recordsize=Rec_S)
	end if

1	format (Q,A)

5	type='            '
	write (screen,10)
10	format (1x,'Type of Account     > ',$)
	read (screen,1,err=9999) length,type
	if (length .eq. 0) goto 5
	call str$Upcase(type,type)

15	Sub_type='            '
	write (screen,20)
20	format (1x,'Sub-Type of Account > ',$)
	read (screen,1,err=5) length,Sub_type
	if (length .eq. 0) goto 15
	call str$Upcase(Sub_type,Sub_type)

	if ((type .eq. 'THSS ').OR.(type .eq. 'PROF ')) then
		if (index(Sub_type,'_') .eq. 0) then
			Sub_type(length+1:length+1 )='_'
			length=length+1
		end if
	end if

	Id_Key=type//Sub_type

	read (sembud,key=Id_Key,keyid=0,IOstat=IO_err) temp_line
	if (IO_err .eq. 0) then
		write (screen,90) Id_Key
90		format (1x,'Re-Write Entry ',1A24,' [N] > ',$)
		read (screen,1) length,answer
		call str$Upcase(answer,answer)
		if (answer .eq. 'Y') goto 25
		write (screen,*) ' '
		goto 15
	end if

	if ((IO_err .ne. 0).AND.(IO_err .ne. 36)) then
		write (screen,100)
100		format (1x,'%%%%% ERROR in the SemBud File')
		call Exit(IO_err)
	end if

25	disk='            '
	write (screen,*) ' '
	write (screen,30)
30	format (1x,'Disk to be Used     > ',$)
	read (screen,1,err=15) length,disk
	if (length .eq. 0) goto 25

35	write (screen,40)
40	format (1x,'UIC Group Number    > ',$)
	read (screen,42,err=35,end=25) group
42	format (1O6)
	if (group .le. 0) goto 35

45	write (screen,50)
50	format (1x,'Permquota           > ',$)
	read (screen,*,err=45,end=35) login_Q
	if (login_Q .le. 0) goto 45

55	write (screen,60)
60	format (1x,'Overdraft           > ',$)
	read (screen,*,err=55,end=45) logout_Q
	if (logout_Q .le. 0) goto 55

65	write (screen,70)
70	format (1x,'PACS Rate Number    > ',$)
	read (screen,*,err=65,end=55) rate
	if (rate .lt. 0) goto 65

75	write (screen,80)
80	format (1x,'Budget              > ',$)
	read (screen,*,err=75,end=65) budget
	if (budget .le. 0) goto 75

	call str$Upcase(disk,disk)

	if (IO_err .eq. 0) rewrite (sembud) rec_line
	if (IO_err .eq. 36) write (sembud) rec_line

	write(screen,*) ' '
	goto 15

9999	close(sembud)
	end
