C ***  SEMALF - SEIMENS TO ALFRED DATA FILE CONVERSION
C *
	CHARACTER KCHAR(20)*4, DATMB(20)*1, DATMW(5)*4, KFILE*20
	DIMENSION DATA(10), PATERN(20000),ANGS(20000)
	EQUIVALENCE (DATMW,DATMB)
	DATA KCHAR/20*'    '/, DATMB/20*' '/
C *
C *  GET FILE NAMES
C *
	IFIRST = 0
	ITOTAL = 0
1	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')
C *
C *  READ THE FILE HEADER INFORMATION
C *
C *  TITLE
7000	READ(10) KCHAR
7010	CONTINUE
C	WRITE(20) KCHAR
	WRITE(6,7020) (KCHAR(I),I=1,4)
7020	FORMAT(/' FILE TITLE:'4A4)
C *
C *  DATE
	READ(10) (DATMB(I),I=1,17)
C	WRITE(20) (DATMB(I),I=1,17)
	WRITE(6,7040) (DATMB(I),I=1,17)
7040	FORMAT(/' DATE:'9A1)
C *
C *  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)
	IF( IFIRST .NE. 0 )GO TO 8000
	PBANG = BANG
	PFINC = FINC
	PTIME = FTIM
	IFIRST = 1
C *
C *  READ THE PATTERN INTO MEMORY
C *
C *  DETERMINE MEMORY POINTERS
8000	NPTS = INT( (EANG-BANG) / FINC + 0.5 ) + 1
	NREC = NPTS / 10
	IF( NPTS .GT. NREC*10 )NREC = NREC + 1
	WRITE(6,8010) NPTS,NREC
8010	FORMAT(/' NUMBER OF POINTS IN SEGMENT = 'I5,//,
	1' NUMBER OF RECORDS TO BE READ = 'I5)
	ISTART = INT( (BANG-PBANG) / FINC + 0.5 ) + 1
	WRITE(6,8020) ISTART
8020	FORMAT(/' DATA IS ENTERED FROM POINT = 'I5)
C *
C *  INITIALIZE THE COUNTER
	ICOUNT = 0
C *
C *  READ THE PATTERN
	DO 8030 IP=1,NREC
	READ(10) DATA
C *
	DO 8040 I=1,10
	ICOUNT = ICOUNT + 1
	IF( ICOUNT .GT. NPTS )GO TO 8100
	IPOINT = ISTART+ICOUNT-1
	PATERN(IPOINT) = DATA(I)
	ANGS(IPOINT) = BANG+FLOAT(ICOUNT-1)*FINC
8040	CONTINUE
C *
8030	CONTINUE
C *
C *  IS THERE ANOTHER PATTERN TO PROCESS...
8100	WRITE(6,8110)
8110	FORMAT(/'$IS THERE ANOTHER PATTERN TO ADD? (Y/N) <N> :')
	READ(5,8120) IANS
8120	FORMAT(A1)
	IF( IANS .EQ. 1HY )GO TO 1
C *
C *  READ THE RECORDS AND CONVERT THEN TO ALFRED FORMAT
C *
	WRITE(6,1030)
1030	FORMAT(/'$ENTER OUTPUT FILE NAME:')
	READ(5,1010) KFILE
	OPEN(UNIT=20,FILE=KFILE,STATUS='NEW',FORM='UNFORMATTED')
C *
	PEANG = ANGS(IPOINT)
	WRITE(6,9876) IPOINT,PEANG
9876	FORMAT(/' TOTAL POINTS = 'I5'  ENDING PATTERN ANGLE = 'F10.4)
C *
C *  GET A TITLE
	WRITE(6,2100)
2100	FORMAT(/' ENTER A TITLE FOR THE PATTERN:',/,'$:')
	READ(5,2110) KCHAR
2110	FORMAT(20A4)
	WRITE(20) KCHAR
C *
C *  GET THE DATE/TIME
	WRITE(6,2120)
2120	FORMAT(/'$ENTER DATE/TIME OF PATTERN CREATION:')
	READ(5,2130) (DATMB(I),I=1,17)
2130	FORMAT(17A1)
	WRITE(20) (DATMB(I),I=1,17)
C *
C *  WRITE THE PATTERN PARAMTERS
	WRITE(20) PBANG,PEANG,PFINC,PTIME
C *
C *  WRITE THE PATTERN
C *
	ICOUNT = 0
2000	DO 2010 I=1,10
	DATA(I) = 0.0
2010	CONTINUE
C *
	DO 2020 I=1,10
	ICOUNT = ICOUNT + 1
	IF( ICOUNT .GT. IPOINT )GO TO 3000
	DATA(I) = PATERN(ICOUNT)
2020	CONTINUE
	WRITE(20) DATA
	GO TO 2000
C *
3000	IF( ICOUNT .NE. 0 )WRITE(20)DATA
	CLOSE(UNIT=10)
	CLOSE(UNIT=20)
	STOP'FILE CONVERTED'
	END
