	subroutine hash(name,found,entry)

	implicit none

	include 'parameters.inc'
	include 'tables.inc'

	character*(*) name
	logical found,found_empty
	integer*4 entry,name_length,ihash,i,j,irehash,empty_entry,ientry,ki
	byte bhash(4),kb

	equivalence (bhash,ihash),(ki,kb)

c	compress name to 32bit integer
	name_length=len(name)
	i=1
	ihash=0	
	do j=1,name_length
		ki=0
		kb=bhash(i)
		ki=ki+ichar(name(j:j))
		bhash(i)=kb
		i=i+1
		if(i.gt.4)i=1
	enddo
c	hash the name
	found_empty=.false.
	ihash=mod(ihash,name_table_size)	!mod table size(prime number)
	if(ihash.lt.0)ihash=ihash+name_table_size
	irehash=max0(1,ihash)			!get rehash size
	do i=1,name_table_size			!possable step thorugh table
		ientry=ihash+1			! get entry to examione
		if(.not.name_table(ientry).inuse)then	!if not inuse
			if(.not.name_table(ientry).deleted)then
				entry=ientry
				found=.false.		!no matching name
				return			!return new potential entry
			elseif(.not.found_empty)then
				found_empty=.true.
				empty_entry=entry
			endif
		elseif(name_table(ientry).name.eq.name)then
			found=.true.		!found namein table
			entry=ientry
			return
		endif		
		ihash=mod(ihash+irehash,name_table_size)! try rehash
	enddo
	if(found_empty)then
		entry=empty_entry
		found=.false.
		return
	endif
	call log_error(' ****HASH-Name table is full****')
	call exit(4)
	end
