	subroutine redset(infile,nent)
c	read data sets from tape infile into ecs * $SEDUM controls action
c	iadd(i)=0 is normal * creates a new set
c	iadd(i)=1 adds i th set to previous one
c	ntlo(i):nthi(i)  read in t bins ntlo(i)-nthi(i) inclusive for
c	ith set read in
c	readset can be called more than once to read several files
c
c ****    foxin controls loadset
c	    it1,2     * add up t bins it1 thru it2
c	    iwset     * select set number iwset * sets are numbered
c	              * sequentially as input by readset with added sets
c	              * (iadd=1) not counted
c ....    iebeg     * begin with iebeg th energy bin
c ....    nume      * and continue with nume bins
c ....    kgeom     * 1 a and nfs * 2 trigger b
c
	include '/u1/gcf/e350/crystal/cb/pperp'
	include '/u1/gcf/e350/crystal/cb/foxxie'
	include '/u1/gcf/e350/crystal/cb/norm'
	include '/u1/gcf/e350/crystal/cb/foxin'
	common/ecs/ecs(100000),necs
	common/icenot/tval(50),nddt
	dimension iadd(20),ntlo(20),nthi(20),corset(20),ttval(50)
	character*35 filnam
c
c	corset = 1./bigfud used in smallie
c
	data numset/0/,iecs/0/,necs/100000/
c
101	format(' input file'i3' added to number'i3)
102	format(' input file'i3' starts new set number'i3)
103	format(' leaving readset    no of sets ='i3)
104	format(' no of t bins ='i2' range read in ='i2' - 'i2
&	' values ='4f7.3,4(/' '18f7.3))
114	format(' no of pperp bins = 'i4' values = '2(/' '12f8.3))
105	format(' no of indices = 'i4)
106	format(' no of energy bins = 'i4' lowest energy = 'f8.3
& 	' interval = 'f8.3)
107	format(20(i1,1x),l2/20i3/20i3)
108	format(' iadd '20i4/' ntlo '20i4/' nthi '20i4' dopp='l2' corset =')
c
	do 10 i=1,20
10	iadd(i)=0
	jadd=0
c
	read(1,107) iadd,dopp,ntlo,nthi
	read(1,*) corset
	write(6,108) iadd,ntlo,nthi,dopp
        write(6,*) corset
c
1	read(1,304) filnam
304	format(a35)
	write(6,305) filnam
305	format('reading data from file 'a35)
	open(infile,file=filnam,access='sequential',form='unformatted')
	rewind infile
c
	read(infile,end=7) noq,noi,noe,dum1,dum1,dum1,
& 	dum1,(ttval(j),j=1,noq),e1,de
	nddt=noq
c	reorder tval when some t bins are skipped
	if (ntlo(jadd+1).eq.1.and.nthi(jadd+1).eq.nos) goto 16
	nddt=nthi(jadd+1)-ntlo(jadd+1)+2
	do 18 j=1,nddt
	tt=ttval(j+ntlo(jadd+1)-1)
	if (jadd.eq.0) tval(j)=tt
18	if (tt.ne.tval(j)) call abort
16	nut=noq-1
	noi=1
99	print 104,nut,ntlo(jadd+1),nthi(jadd+1),(tval(j),j=1,nddt)
	print 106,noe,e1,de
	if (ntlo(jadd+1).gt.0) goto 11
	ibbx=noe*noi*nut
	iex=3*ibbx
	iwant=iex+iecs
	if (iex+iecs.gt.necs) goto 55
	read(infile,end=1) num,(ecs(i+iecs),i=1,iex)
c
3	jadd=jadd+1
	if (iadd(jadd).ne.0.and.numset.ne.0) goto 444
c
c	new set created
4	numset=numset+1
	numbe(numset)=noe
	e1b(numset)=e1
	deb(numset)=de
	numbt(numset)=nut
	print 102,jadd,numset
	if (iadd(jadd+1).eq.0) goto 20
	iecs=iwant
	goto 1
c
c	add current input to previous set
444	print 101,jadd,numset
	if (iadd(jadd+1).eq.1) goto 21
c	add and correct for acceptance - last set
	do 5 i=1,ibbx
	if (ecs(i+iecs-iex).eq.0.) goto 5
	inda=(i-1)/noe
	euse=(e1+de*(float(i-inda*noe)-0.5))*corset(jadd)
	nnn=numset
	if (mt(1)) nnn=(numset+1)/2
	fudt=correc(euse,iacc(nnn),-tval(inda+1),-tval(inda+2))
	if (fudt.lt.1.e-5) goto 14
	ecs(i+iecs-iex)=(ecs(i+iecs)+ecs(i+iecs-iex))/fudt
	ecs(i+iecs-2*ibbx)=(ecs(i+iecs+ibbx)+ecs(i+iecs-2*ibbx))/(fudt**2)
	ecs(i+iecs-ibbx)=(ecs(i+iecs-ibbx)+ecs(i+iecs+2*ibbx))/fudt
	goto 5
c	acceptance too small
14	ecs(i+iecs-2*ibbx)=-1.e20
5	continue
23	continue
	if (numset.lt.nent) goto 1
	goto 9
c	no acceptance calculation
21	do 22 i=1,ibbx
	ecs(i+iecs-iex)=ecs(i+iecs)+ecs(i+iecs-iex)
	ecs(i+iecs-2*ibbx)=ecs(i+iecs+ibbx)+ecs(i+iecs-2*ibbx)
22	ecs(i+iecs-ibbx)=ecs(i+iecs-ibbx)+ecs(i+iecs+2*ibbx)
	goto 23
c
c	read in a selected t range of data only
11	nos=nut
	nut=nthi(jadd+1)-ntlo(jadd+1)+1
	nort=nos-nut
	ibbx=noe*noi*nut
	ibqx=noe*noi*nort
	iex=3*ibbx
	iwant=iecs+iex
	if (iwant.gt.necs) goto 55
	if (nthi(jadd+1).eq.nos) goto 12
	if (ntlo(jadd+1).ne.1) goto 19
c	read initial t bins only
	read(infile,end=1) num,(ecs(i+iecs),i=1,ibbx),(ecs(i+iecs+ibbx),
& 	i=1,ibqx),(ecs(i+iecs+ibbx),i=1,ibbx),(ecs(i+iecs+2*ibbx),
& 	i=1,ibqx),(ecs(i+iecs+2*ibbx),i=1,ibbx)
	goto 3
c	read final t bins only
12      read(infile,end=1) num,(ecs(i+iecs),i=1,ibqx),
& 	(ecs(i+iecs),i=1,ibbx),(ecs(i+iecs+ibbx),i=1,ibqx),
& 	(ecs(i+iecs+ibbx),i=1,ibbx),
& 	(ecs(i+iecs+2*ibbx),i=1,ibqx),(ecs(i+iecs+2*ibbx),i=1,ibbx)
	goto 3
c
c	read set of t bins from middle of range
19	ibax=noe*noi*(ntlo(jadd+1)-1)
	ibcx=noe*noi*(nos-nthi(jadd+1))
	ibex=noe*noi*nos
	ibfx=ibbx+ibcx
c	storage in ecs:
c	ibax words - discard
c	ibbx words - store in (ecs(i+iecs),i=1,ibbx)
c	ibcx words - discard
c	ibax words - discard
c	ibbx words - store in (ecs(i+iecs+ibbx),i=1,ibbx)
c	ibcx words - discard
c	ibax words - discard
c	ibbx words - store in (ecs(i+iecs+2*ibbx),i=1,ibbx)
c	ibcx words - discard
	read(infile,end=1) num,(ecs(i+iecs),i=1,ibax),(ecs(i+iecs),
&	i=1,ibex),(ecs(i+iecs+ibbx),i=1,ibex),(ecs(i+iecs+2*ibbx),
&	i=1,ibfx)
	goto 3
c
c	end of file found
7	nut=noq-1
	noi=1
	read(infile,end=8) noq,noi,noe,dum1,dum1,dum1,
& 	dum1,(tval(j),j=1,noq),e1,de
2	nut=noq-1
	noi=1
	goto 99
c
c	double end of file encountered
c	was next jadd value = 1
8	if (iadd(jadd+1).eq.0) call abort
c	did not correct for acceptance so do so now
	iecs=iwant-iex
c
c	correct for acceptance
20	do 15 i=1,ibbx
	if (ecs(i+iecs).eq.0.) goto 15
	inda=(i-1)/noe
	euse=(e1+de*(float(i-inda*noe)-0.5))*corset(jadd)
	nnn=numset
	if (mt(1)) nnn=(numset+1)/2
	fudt=correc(euse,iacc(nnn),-tval(inda+1),-tval(inda+2))
	if (fudt.lt.1.e-5) goto 17
	ecs(i+iecs)=ecs(i+iecs)/fudt
	ecs(i+iecs+ibbx)=ecs(i+iecs+ibbx)/(fudt**2)
	ecs(i+iecs+2*ibbx)=ecs(i+iecs+2*ibbx)/fudt
	goto 15
17	ecs(i+iecs+ibbx)=-1.e20
15	continue
	iecs=iwant
	if (numset.lt.nent) goto 1
9	print 103,numset
	close(1)
	return
c
c	not enough storage space
55	print 125,necs
125	format(' Stopping in readset because ecs storage limited to'i6)
	call abort
c
	end
