	SUBROUTINE D11DIF(F)
C
C  LU-3  RAW DATA FILE
C  LU-9  D11.DIF
c
c SUBROUTINE ADDED FOR D11 D&I FILE OUTPUT
C
C COPIES INFORMATION FROM D11.RAW FOR D11.DIF
C
	BYTE F(30),FI(30)
	INTEGER IAN(2)
C    MAKE IT PEAK HEIGHT AND ADR LIKE
	IAN(1)='A'
	IAN(2)='N'
C
	DO 200 I=1,30
	FI(I)=F(I)
200	IF(FI(I).EQ.'.') J=I
	FI(J+1)='R'
	FI(J+2)='A'
	FI(J+3)='W'
      OPEN(UNIT=3,FILE=FI,STATUS='OLD',ACCESS='DIRECT',READONLY
     1,RECORDSIZE=1)
C
	DO 100 I=1,12
	J=I
	READ(3'J) A
100	WRITE(9'J) A
	READ(3'31)A
	WRITE(9'13)A
	READ(3'32)A
	WRITE(9'14)A
	READ(3'33)A
	WRITE(9'15)A
	READ(3'34)A
	WRITE(9'16)A
	READ(3'13)A
	WRITE(9'18)A
	READ(3'14)A
	WRITE(9'19)A
	READ(3'18)A
	WRITE(9'23)A
	WRITE(9'20) (IAN(I),I=1,2)
	CALL CLOSE(3)
	RETURN
	END
C
      SUBROUTINE SPDIF(FI,mon,date,year,inst,tit,t0,dx,dy,XL)
c
      COMMON /DPRC/ IDPRC,IBKGR,ISCH,INRM,ISTD,NDER,MF,MB,IK2,ISM,IPF,
     1NT,SENS,INSTD,EXSTD,E2T
C
      BYTE IBKGR,IK2,ISCH,INRM,IDPRC,ISTD,NDER,MF,MB,ISM,INSTD(30)
     1,EXSTD(30)
      DIMENSION tit(12)
      BYTE FI(6)
      integer mon,date,year,inst(2)
C
      WRITE(9,32) FI,MON,DATE,YEAR,(INST(I),I=1,2)
     1,(TIT(I),I=1,12)
   32 FORMAT(1X,6A1,1X,I2,'/',I2,'/',I2,1X,2A2,4X,12A4)
      WRITE(9,33) T0,DX,DY
   33 FORMAT(1X,'INITIAL 2THETA=',F8.3,' DELTA 2THETA=',F6.3,
     X' DELTA TIME=',F6.2,'SEC')
      WRITE(9,61) ISM,IBKGR,MF,MB,IK2,XL,ISCH,SENS,IPF,NT
   61 FORMAT(1X,'SM=',I2,2X,'BKGR=',3I2,2X,'KA2=',I1,2X,'WLGTH=',F8.6,
     1' SCH=',I2,' SENS=',F4.2,'  CENTROID=',I2,' NT=',I2)
      WRITE(9,41)
      WRITE(9,142)
  142 FORMAT(3X,'M',4X,'2THETA',4X,'DSPACE',4X,'HEIGHT')
      WRITE(9,41)
   41 FORMAT(1X)
      RETURN
      END
C
      SUBROUTINE SPDSP(FI,istd,mon,date,year,inst,tit,dmax,dmin,aerr
     1,err,TYP)
C
      BYTE ISTD,FI(6),TYP
      DIMENSION TIT(12)
      integer mon,date,year,inst(2)
C
      WRITE(10,32)FI,MON,DATE,YEAR,(INST(I),I=1,2),(TIT(I),I=1,12)
   32 FORMAT(1X,6A1,1X,I2,'/',I2,'/',I2,1X,2A2,4X,12A4)
      WRITE(10,*) DMAX,DMIN
      IF(TYP.NE.0) GO TO 100
      IF(ISTD.EQ.1.OR.ISTD.EQ.3) WRITE(9,1010)
 1010 FORMAT('+',$,'EXTERNAL STANDARD USED')
      IF(ISTD.EQ.2.OR.ISTD.EQ.3) WRITE(9,1020) AERR,ERR
 1020 FORMAT('+',$,' INTERNAL STANDARD USED  AVERAGE ERROR WAS',F9.3
     1,'  AVERAGE DIFF WAS',F9.3)
  100 IF(LIST.EQ.1) WRITE(7,142)
   42 FORMAT(3X,'M',4X,'DSPACE',4X,'HEIGHT')
  142 FORMAT(3X,'M',4X,'2THETA',4X,'DSPACE',4X,'HEIGHT')
   41 FORMAT(1X)
      RETURN
      END

      SUBROUTINE WR910(TYP,ISTD,LIST,XL,P2T,X,DY)
C
C WRITE OUT RESULTS FOR 9&10  IE MAKE IT FIT
C
      BYTE TYP,ISTD
      DIMENSION P2T(1),W(100),D(100),P(100)
C
      IF(LIST.EQ.1) WRITE(7,142)
  142 FORMAT(3X,'M',4X,'2THETA',4X,'DSPACE',4X,'HEIGHT')
      J=41
      M=1
      IR=0
   21 READ(8,19,END=96,ERR=21) DE,SDE,Q,PK,CAREA,PR,W2,W4
   19 FORMAT(4X,8F9.0)
      IF(DE.LE.0.0) GO TO 21
      IF(DE.GT.180.0) GO TO 21
      IF(ISTD.GT.0) DE=P2T(M)
      IF(DE.LE.0.0) GO TO 900
      P(M)=PK
      PK=PK*100./X
      D(M)=DE
      W(M)=W4
      SDE=XL/(2.0*SIN(0.0087266*DE))
      IF(TYP.EQ.0)WRITE(9,143) M,DE,SDE,PK
      IF(LIST.EQ.1) WRITE(7,143) M,DE,SDE,PK
      IF(TYP.EQ.0)WRITE(9,41)
   41 FORMAT(1X)
   43 FORMAT(1X,I3,F10.4,2F10.1,F10.3)
  143 FORMAT(1X,I3,F10.3,F10.4,2F10.1,F10.3)
      IM=M
      M=M+1
      GO TO 21
96    CALL TSORT(D,P,W,IM) ! SORT ON D CODE (2THETA)
      DO 110 I=1,IM
      IF(D(I).EQ.0) GO TO 110
      SDE=XL/(2.0*SIN(0.0087266*D(I)))
      IPK=P(I)*100/X
      WRITE(10,144) SDE,IPK
  144 FORMAT(F7.3,I10)
  110 CONTINUE
	IF(TYP.EQ.2) THEN
	  DO 100 I=1,IM
	  SDE=XL/(2.0*SIN(0.0087266*D(I)))
	  WRITE(9'J)SDE
	  J1=J+1
	  PK=P(I)*DY
	  WRITE(9'J1)PK
	  J2=J1+1
	  WRITE(9'J2) W(I)
100	  J=J+6
	  WRITE(9'21) IM,IR
	ENDIF
      RETURN
  900 WRITE(6,1000)
 1000 FORMAT(1X,'PROBLEM P2T IS ZERO ? ? ?')
      return
      end

	SUBROUTINE TSORT (T2,PK,W,NDSINT)
C
C  BUBBLE SORTS 2THETA ARRAY FROM LOW TO HIGH
C
	DIMENSION T2(100),PK(100),W(100)
	N=NDSINT-1
100	NSWAP=0
	DO 300 K=1,N
	IF(T2(K).LE.T2(K+1))GO TO 300
	TEMP=T2(K+1)
	T2(K+1)=T2(K)
	T2(K)=TEMP
	TEMP=PK(K+1)
	PK(K+1)=PK(K)
	PK(K)=TEMP
	TEMP=W(K+1)
	W(K+1)=W(K)
	W(K)=TEMP
	NSWAP=1
300	CONTINUE
	IF(NSWAP.NE.0)GO TO 100
	RETURN
	END
