      PROGRAM D2PREF
C
C  Program to convert a Diffrac-500 D&I file to POWD10 listing format
C  for use as input to program SUPREF.  
C  Allows user to enter Cell params and HKLs.
C
      PARAMETER TITLES='           2THETA  PEA'//
	1 'K     D      H  K  L I(INT) I(PK) I(DS)'
      PARAMETER CELLCO='0CELL CONSTANTS '
      CHARACTER FILE*80
	INCLUDE 'FILECONV.CBS'
	IO4=4
	IO5=5
	IO6=6
	WRITE(IO6,1)
1	FORMAT(/,' **** PROGRAM TO FAKE CALCULATED PATTERNS',
     &    ' FROM SPRAYDRIED PATTERNS ****',/)
	CALL OBREAD(IO5,IO6,WAVEL)
C	WRITE(IO6,4) (SLID(I),I=1,16),NAME,DATM,NPKS
C4	FORMAT(' SAMPLE ID=',16A4,/,' COLLECTED BY ',3A4,
C     &	   ' ON ',F7.0,'   NUMBER OF PEAKS=',I5)
C	TYPE*,'WAVE=',(WAVE(I,6),I=1,5)
C
C  Open output file
C
	WRITE(IO6,30)
30	FORMAT(/,' Enter name of output file: ',$)
	READ(IO5,35) FILE
35	FORMAT(A)
	OPEN(UNIT=IO4,NAME=FILE,STATUS='NEW',CARRIAGECONTROL='LIST')
C
C  Optional Cell Constants.
C
      WRITE(IO6,130)
130   FORMAT(/' Cell parameters - enter A,B,C,ALPHA,BETA,GAMMA'/,' :',$)
      READ(IO5,60) A,B,C,AL,BE,GA
60    FORMAT(8G10.0)
      IF(A.NE.0.0) WRITE(IO4,84) CELLCO,'A=',A,'B=',B,'C=',C,
     & 'ALPHA=',AL,'BETA= ',BE,'GAMMA=',GA
84    FORMAT(A,/,3(/,2X,A2,F8.4),3(/,2X,A6,F6.2))

C  Write the peak data.

      WRITE(IO4,90) TITLES
90    FORMAT(/,A,/)

      CALL CAWRIT(4,5,6)
      END

	SUBROUTINE CAWRIT(IO4,IO5,IO6)
	INCLUDE 'FILECONV.CBS'
	D2R = 3.1415926/180.
	DO 7,I=1,NPKS
	IF(C2TH(I).EQ.0.0) GOTO 7
	IF(PHKL(1,I).EQ.0 .AND. PHKL(2,I).EQ.0 .AND. PHKL(3,I).EQ.0) THEN
         WRITE(IO6,236) I,C2TH(I)
236      FORMAT(' PEAK #',I4,' AT',F8.4,' H,K,L? ',$)
         READ(IO5,237) PHKL(1,I),PHKL(2,I),PHKL(3,I)
237      FORMAT(3I)
	ENDIF
	D = WAVE(1,6)/2.0/SIN(D2R*C2TH(I)/2.0)
	INTEG=0
	IF(AREA(I,1).LT.1E6 .AND. AREA(I,1).GT.0.0) INTEG=AREA(I,1)
	WRITE(IO4,235) C2TH(I), D, PHKL(1,I),
     &    PHKL(2,I),PHKL(3,I), INTEG, NINT(PHGH(I))
7	CONTINUE
235	FORMAT(F17.2,7X,F7.3,T34,3I3,I6,I6)
	RETURN
	END
