	SUBROUTINE D5D11(FILE1,FILE2)
C++
C++	Routine: D5D11
C	Programmer: DJ HELM
C	Date: 13 FEB 85
C++	Purpose: Conversion routine
C++	Syntax:
C++		CALL D5D11(FILE1,FILE2)
C++	Calls:
C++
C	Modifications
C	Who	date	what
C
C
C
	COMMON /TRMBLK/IUNIT1,IUNIT2,TERM
C
	BYTE FILE1(32),FILE2(32),ID(16),DAT(9),TIM(8),BLK(3),USER(12)
C
	INTEGER*2 IUNIT1,IUNIT2,NSTEPS,TUBKV,TUBMA,DET,SCAN
	1,NORM,NRANG,TERM
C
	REAL*4 WAVE,SNGLE,ENGLE,STPSIZ,TIME,TUBVOL,LAMBDA,ANODE
	1,DELWAV,WAVE1,WAVE2,ZERO
C
	DATA BLK/3*' '/
	DATA TIM/8*' '/
	DATA USER/12*' '/
C
	WAVE1=0.0
	WAVE2=0.0
	DELWAV=0.0
	ANODE='    '
	TUBKV=0
	TUBMA=0
	DET=3	! default to sillentation counter with mon
	SCAN=0
	ZERO=0
C
	READ(IUNIT1'1,ERR=900)(ID(I),I=1,4)
	WRITE(IUNIT2'1,ERR=950)(ID(I),I=1,4)
	READ(IUNIT1'2,ERR=900)(ID(I),I=5,8)
	WRITE(IUNIT2'2,ERR=950)(ID(I),I=5,8)
	READ(IUNIT1'3,ERR=900)(ID(I),I=9,12)
	WRITE(IUNIT2'3,ERR=950)(ID(I),I=9,12)
	READ(IUNIT1'4,ERR=900)(ID(I),I=13,16)
	WRITE(IUNIT2'4,ERR=950)(ID(I),I=13,16)
	READ(IUNIT1'5,ERR=900)(DAT(I),I=1,4)
	WRITE(IUNIT2'5,ERR=950)(DAT(I),I=1,4)
	READ(IUNIT1'6,ERR=900)(DAT(I),I=5,8)
	WRITE(IUNIT2'6,ERR=950)(DAT(I),I=5,8)
	READ(IUNIT1'7,ERR=900)DAT(9)
	WRITE(IUNIT2'7,ERR=950)DAT(9),(BLK(I),I=1,3)
C
C	the diffrac 11 date and time are not  known and will be entered
C	as blanks
C
	WRITE(IUNIT2'8,ERR=950)(TIM(I),I=1,4)
	WRITE(IUNIT2'9,ERR=950)(TIM(I),I=5,8)
	WRITE(IUNIT2'10,ERR=950)(USER(I),I=1,4)
	WRITE(IUNIT2'11,ERR=950)(USER(I),I=5,8)
	WRITE(IUNIT2'12,ERR=950)(USER(I),I=9,12)
C
	READ(IUNIT1'8,ERR=900)WAVE
	READ(IUNIT1'9,ERR=900)SNGLE
	READ(IUNIT1'10,ERR=900)ENGLE
	READ(IUNIT1'11,ERR=900)STPSIZ
	READ(IUNIT1'12,ERR=900)TIME
C
C	calculate the number of NSTEPS
C
	NSTEPS=IFIX((ENGLE-SNGLE)/STPSIZ)+1
C
C	check to see if the wavelength is in the d5 data file
C
	IF(WAVE.NE.'WAVE')GO TO 100
	IREC=NSTEPS+13
	READ(IUNIT1'IREC,ERR=900)WAVE1
	READ(IUNIT1'IREC+1,ERR=900)WAVE2
	DELWAV=WAVE2-WAVE1
	GO TO 1001
C
100	WAVE1=1.540510
	WAVE2=1.544330
	DELWAV=WAVE2-WAVE1
	ANODE='CU  '
C
1001	WRITE(IUNIT2'13,ERR=950)ANODE
	WRITE(IUNIT2'14,ERR=950)WAVE1
	WRITE(IUNIT2'15,ERR=950)DELWAV
	WRITE(IUNIT2'16,ERR=950)TUBKV,TUBMA
	WRITE(IUNIT2'17,ERR=950)DETSLT
	WRITE(IUNIT2'18,ERR=950)RECDIV
	WRITE(IUNIT2'19,ERR=950)DET,SCAN
C
C	set all of the calibration coefs to 0
C
	DO 101 I=20,29
	JJ=I
	WRITE(IUNIT2'JJ,ERR=950)ZERO
101	CONTINUE
C
	NORM=0
	NRANG=1
	WRITE(IUNIT2'30,ERR=950)NRANG,NORM
C
C	write out the measurement information
C
	WRITE(IUNIT2'31,ERR=950)SNGLE
	WRITE(IUNIT2'32,ERR=950)ENGLE
	WRITE(IUNIT2'33,ERR=950)STPSIZ
	WRITE(IUNIT2'34,ERR=950)TIME
	WRITE(IUNIT2'35,ERR=950)ZERO
C
C	transfer the intensities
C
	IOF5=13
	IOF11=36
	DO 120 I=1,NSTEPS
	READ(IUNIT1'IOF5,ERR=900)VAL
	WRITE(IUNIT2'IOF11,ERR=950)VAL
	IOF5=IOF5+1
	IOF11=IOF11+1
120	CONTINUE
C
C	everything completed
C	
121	CLOSE(UNIT=IUNIT1)
	CLOSE(UNIT=IUNIT2)
	IF(IER.NE.0)GO TO 201
	WRITE(TERM,200)(FILE1(I),I=1,26),(FILE2(I),I=1,26)
200	FORMAT(' File ',26A1,' has been transfered to ',26A1)
201	RETURN
C
C	errors
C
900	CALL ERRSNS(IER)
	WRITE(TERM,901)IER,FILE1
901	FORMAT(' An error',I4,' has occured while reading from 
	1file :',32A1)
	GO TO 121
C
950	CALL ERRSNS(IER)
	WRITE(TERM,951)IER,FILE1
951	FORMAT(' An error',I4,' has occured while writing to file :',32A1)
	GO TO 121
	END
