C	SOFTFILE.FOR
C
C	SOFT_FILE contains the utility routines to do indexed and 
C	sequential I/O  and conversion to SOFTQUOTA.DAT.
C
	subroutine  open_soft (soft_open)

	implicit integer (a-z)

	include		'($FORIOSDEF)'
	include		'SOFTDEF'
	include		'IODEF'

	parameter	BUFFERS		= 4		!Multi-buffer count
	parameter	PK_ID		= 0

	logical		soft_open
	character	dev * 60

	character	drive * (40), DataFile * (40)
	common /drive_name/ drive, DataFile
	common /drive_length/ drive_len

	if (drive(drive_len:drive_len) .ne. ':') then
	    drive_len = drive_len + 1
	    drive (drive_len:drive_len) = ':'
	endif
	dev = drive(1:drive_len)//DataFile
D	type *,dev

	call open_isam (SOFT_CHAN, dev, BUFFERS, ios)

	soft_open = .false.
	if (ios .eq. 0) then
	    soft_open = .true.
	else if (ios .eq. FOR$IOS_FILNOTFOU) then
	    type *, 'I cannot find ',dev
	else if (ios .eq. FOR$IOS_NO_SUCDEV) then
	    type *, 'No such device ',drive(1:drive_len)
	else if (ios .eq. FOR$IOS_OPEFAI) then
	    type *, 'I cannot open ',dev
	else
	    type 10, ios, dev
10	    format (' Fortran error ',I4,' opening ',A)
	endif

	return
C
C************************************************************************
C
	entry read_soft (sq_key, sq_uic, sq_soft, sq_hard, sq_mess, iof)

20	format (2i4, 1x, i8, 2x, i8, 2x, i4)

	write (uic_str, '(2i4)') sq_key
	call read_isam (SOFT_CHAN, uic_str, PK_ID, buffer, ios)
	iof = ios
	read (buffer, 20) sq_uic, sq_soft, sq_hard, sq_mess

	return
C
C************************************************************************
C
	entry  read_soft_first (sq_uic, sq_soft, sq_hard, sq_mess, iof)

	call read_isam_first (SOFT_CHAN, PK_ID, buffer, ios)
	iof = ios
	read (buffer, 20) sq_uic, sq_soft, sq_hard, sq_mess
	return
C
C************************************************************************
C
	entry  read_soft_next (sq_uic, sq_soft, sq_hard, sq_mess, iof)

	call read_isam_next (SOFT_CHAN, buffer, ios)
	iof = ios
	read (buffer, 20) sq_uic, sq_soft, sq_hard, sq_mess
	return
C
C************************************************************************
C
	entry  rewrite_soft (sq_uic, sq_soft, sq_hard, sq_mess, iof)

	write (buffer, 20) sq_uic, sq_soft, sq_hard, sq_mess
	call rewrite_isam (SOFT_CHAN, buffer, ios)
	iof = ios

	return
C
C************************************************************************
C
	entry  write_soft (sq_uic, sq_soft, sq_hard, sq_mess, iof)

	write (buffer, 20) sq_uic, sq_soft, sq_hard, sq_mess
	call write_isam (SOFT_CHAN, buffer, ios)
	iof = ios
	return
C
C************************************************************************
C
	entry  delete_soft

	delete (SOFT_CHAN, iostat=ios)
	if (ios .ne. 0)  call geterr (i, j, k, l)

	return
C
C************************************************************************
C
	entry  close_soft

	close (SOFT_CHAN, iostat=ios)
	if (ios .ne. 0)  call geterr (i, j, k, l)

	return
	end
