C ** ALFRIET - CONVERT ALFRED TO RIETVELD FORMAT
C *
	CHARACTER KCHAR(20)*4, DATMB(20)*1, DATMW(5)*4, KFILE*20
	DIMENSION DATA(10),IINT(20000),IOUT(8)
	EQUIVALENCE (DATMW,DATMB)
	DATA KCHAR/20*'    '/, DATMB/20*' '/
C *
C *  GET FILE NAMES
C *
	WRITE(6,1000)
1000	FORMAT(/'$ENTER INPUT FILE NAME:')
	READ(5,1010) KFILE
1010	FORMAT(A20)
	OPEN(UNIT=10,FILE=KFILE,STATUS='OLD',FORM='UNFORMATTED',
	1READONLY)
	WRITE(6,1030)
1030	FORMAT(/'$ENTER OUTPUT FILE NAME:')
	READ(5,1010) KFILE
	OPEN(UNIT=20,FILE=KFILE,STATUS='NEW',FORM='FORMATTED',
	1CARRIAGECONTROL='LIST')
*
*  READ THE FILE HEADER INFORMATION
*
*  TITLE
	READ(10) KCHAR
7024	FORMAT(20A4)
	WRITE(6,7026) KCHAR
7026	FORMAT(X,20A4)
*
*  DATE
	READ(10) (DATMB(I),I=1,17)
	WRITE(6,7040) (DATMB(I),I=1,17)
7040	FORMAT(/' DATE:'17A1)
*
*  READ THE DATA COLLECTION PARAMETERS
	READ(10) BANG,EANG,FINC,FTIM
	WRITE(6,7050) BANG,EANG,FINC,FTIM
7050	FORMAT(/' BANG,EANG,FINC,FTIM = '4F10.4)
*
*  READ THE RECORDS AND CONVERT THEN TO COUNTS
*
	FNPTS = (EANG-BANG)/FINC
	PRINT *,'FNPTS=',FNPTS
	NPTS = INT(FNPTS)+1
	NREC = NPTS / 10
	IF(NREC*10.LT.NPTS) NREC = NREC + 1
	PRINT *,'NPTS,NREC=',NPTS,NREC
	NRED = 0
2000	DO 2010 I=1,NREC
	READ(10,END=9876) DATA
	DO 2012 J=1,10
	NRED = NRED + 1
	IINT(NRED) = NINT( DATA(J) * FTIM )+5
	IF(NRED.EQ.NPTS) GO TO 9876
2012	CONTINUE
2010	CONTINUE
*
*  WRITE THE DATA OUT IN RIETVELD FORMAT
*
9876	WRITE(6,2101)
2101	FORMAT(/'$GIVE STARTING,ENDING ANGLES FOR OUTPUT FILE:')
	READ(5,2111) SA,EA
2111	FORMAT(2F)
	NSTART = NINT( (SA-BANG)/FINC ) + 1
	IF(NSTART.LT.1) NSTART=1
	NSTOP = NINT( (EA-BANG)/FINC ) + 1
	IF(NSTOP.GT.NPTS) NSTOP = NPTS
	EANG = BANG + (NSTOP-1)*FINC
	BANG = BANG + (NSTART-1)*FINC
	WRITE(20,7052) BANG,FINC,EANG
7052	FORMAT(F8.4,F8.4,F8.4)
	PRINT *,'NSTART,NSTOP = ',NSTART,NSTOP
*
2015	NWRIT = NSTART
2019	DO 2018 I=1,8
2018	IOUT(I) = 0
	DO 2020 I=1,8
	IOUT(I) = IINT(NWRIT)
	IF(NWRIT.EQ.NSTOP) GO TO 2100
	NWRIT = NWRIT + 1
2020	CONTINUE
	WRITE(20,2022) IOUT
2022	FORMAT(8(I7,X))
	GO TO 2019
2100	WRITE(20,2022) IOUT
C *
	CLOSE(UNIT=10)
	CLOSE(UNIT=20)
	STOP'FILE CONVERTED'
	END
