	dimension ihist(21000)
	character*80 filename
	character*25 s1
	open(unit=1,file='temp3',status='old')
C	open(unit=3,file='temp4',status='new')
	s1=''
1	read(1,2,end=99) filename
C Get the image name
	do 10 i=1,75
	if(filename(i:i+3).eq.'hist') then
	s1=filename(1:i-1)
	go to 11
	end if
10	continue
	stop 'could not get filename'
11	continue
	do 100 i=1,21000
	ihist(i)=0
100	continue
2	format(a80)
	open(unit=2,file=filename,status='old')
	mall=0
3	read(2,*,end=4) value,inum
	index=value+50.5
	if(index.lt.1) index=1
	if(index.gt.21000) index=21000
	ihist(index)=inum
	if(inum.gt.mall) then
	mall=inum
	ibest=index
	end if
	go to 3
4	write(6,5) ibest,mall
5	format('Peak value at ',i8,' with',i10)
	low=ibest-5
	ihigh=ibest+5
	if(low.lt.1) low=1
	if(ihigh.gt.21000) ihigh=21000
	sumx=0
	sumxy=0
	do 101 i=low,ihigh
	sumxy=sumxy+i*ihist(i)
	sumx=sumx+ihist(i)
101	continue
	centroid=sumxy/sumx
	write(4,102) s1,-(centroid-50.5)
	write(6,102) s1,-(centroid-50.5)
102	format(a25,f8.2)
	go to 1
99	stop
	end
