	DIMENSION J(200),L(200),K(200),F(200)
	WRITE(108,5)
5	FORMAT(/' PROGRAM TO AVERAGE EQUIVILANT REFLECTIONS'/)
	DO 90 I=1,200
	READ(105,10,END=100)J(I),K(I),L(I),F(I)
	IF(J(I))50,70,90
50	J(I) = IABS( J(I))
	IF(L(I))70,80,80
70	L(I) = IABS(L(I))
	GO TO 90
80	L(I) = - L(I)
90	CONTINUE
100	N=I-1
	 CALL SORT(L,J,F,N)
	CALL SORT(J,L,F,N)
	M=1
	WRITE(108,167)
167	FORMAT(1H1,'SORTED DATA'//'  H  K  L    I')
	DO166 I=1,N
	WRITE(108,10)J(I),K(I),L(I),F(I)
166	CONTINUE
	II=2
	I=1
110	     SUM = F(I)
	IF(J(I).NE.J(II).OR.L(I).NE.L(II)) GO TO 140
	WRITE(108,15)J(I),K(I),L(I),F(I)
10	FORMAT(3I3,F10.3)
15	FORMAT(/ ' AVERAGE FOR ',3I3,' REFLECTION'/'    I'/1XF10.3)
	DO 120 I3=II,N
	IF(J(I).NE.J(I3).OR.L(I).NE.L(I3)) GO TO 130
	M=M+1
	SUM = SUM + F(I3)
	WRITE(108,18)F(I3)
18	FORMAT(1XF10.3)
120	CONTINUE
130	SUM = SUM / M
	WRITE(108,20)SUM
20	FORMAT('  AVERAGE = ',F10.3)
140	WRITE(10,10)J(I),K(I),L(I),SUM
	I=I+M
	II=I+1
	M=1
	IF(II.GT.N) GOT O 150
	GO TO 110
150	REWIND 10
	WRITE(108,25)
25	FORMAT(///' FINAL DATA SET'//'  H  K  L     I')
	DO160 I=1,N
	READ(10,10,END=170)J(I),K(I),L(I),F(I)
	WRITE(108,10)J(I),K(I),L(I),F(I)
160	CONTINUE
170	N = I - 1
	WRITE(108,30)N
30	FORMAT(//' TOTAL NUMBER OF UNIQUE REFLECTIONS = ',I5)
	CALL EXIT
	END
	SUBROUTINE SORT(J,L,F,N)
	DIMENSION J(200),L(200),F(200)
	NN = N - 1
	DO10 I=1,NN
	M=I+1
	DO 10 II=M,N
	IF(J(I).LT.J(II)) GO TO 10
	IHOLD = J(I)
	J(I)  = J(II)
	J(II) = IHOLD
	IHOLD = L(I)
	L(I)  = L(II)
	L(II) = IHOLD
	AHOLD = F(I)
	F(I) = F(II)
	F(II) = AHOLD
10	CONTINUE
	RETURN
