      SUBROUTINE CURSXY(X0,Y0,N,XW,YW,A,BB,AY,BY,DSPACE
     1,ISH,XL)
C
      COMMON /SCN/ XS,XF,YS,YF,XXS,XXF,YYS,YYF,CSTR,CFIN,CYMIN,CYMAX,STR
     1,FIN,YMIN,YMAX,ZZ,CW,CH,ISP,JSP,IFL
      COMMON /XY/X,Y,X1,Y1,X2,Y2
C
C                                                           **********
C                                                           **CURSXY**
C                                                           **********
C                  ***********************
C   ISH=-1 FOR D COMMAND (XRD DSPACING)
C   ISH=-2 FOR L COMMAND (XRF LAMDA VALUE)
C   ISH=0  FOR X COMMAND
C   ISH=1  FOR Y COMMAND
C   ISH=2  FOR M COMMAND
C                  ***********************
      INTEGER CX,CD
      BYTE ISH,ISP,JSP,IFL
      DATA CX,CD/'X','D'/
      ID=CX
      DUMIN=1.0
    5 CALL X2Y2(X,Y,N,CW,CH)
      W=10*CW
      CALL XWYW(XW,YW,XS,XF,W,CW,CH)
      X2=A*X+BB
      Y2=AY*Y+BY
      IF(ISH.EQ.1) GO TO 10
      IF(ISH.GE.0) GO TO 11
      ID=CD
      IF(ISH.EQ.-2) ID='L'
      IF(ISH.EQ.-1) X2=XL/(2.0*SIN(0.008726646*X2))
      IF(X2.GT.0) Q=1./(X2*X2)
      IF(ISH.EQ.-2) X2=DSPACE*SIN(0.008726646*X2)
      IF(X2.GT.0.AND.ISH.EQ.-2) Q=12.4/X2
      IF(ISH.LT.0) WRITE(8,100) X2,Q,DUMIN
  100 FORMAT(13X,2F9.4,F9.1)
      ISH=0
   11 CONTINUE
      IF(X2.LT.1000.0) GO TO 81
      WRITE(7,51) ID,N,X2
   51 FORMAT('+',$,A1,'(',I2,')=',F7.1)
      GO TO 83
   81 IF(X2.LT.100.0) GO TO 82
      WRITE(7,54) ID,N,X2
   54 FORMAT('+',$,A1,'(',I2,')=',F7.2)
      GO TO 83
   82 IF(X2.LT.10.0) GO TO 70
      WRITE(7,55) ID,N,X2
   55 FORMAT('+',$,A1,'(',I2,')=',F7.3)
      GO TO 83
   70 IF(X2.LT.1.0) GO TO 71
      WRITE(7,72) ID,N,X2
   72 FORMAT('+',$,A1,'(',I2,')=',F7.4)
      GO TO 83
   71 WRITE(7,73) ID,N,X2
   73 FORMAT('+',$,A1,'(',I2,')=',F7.5)
   83 XW=XW+196.0
   10 IF(ISH.EQ.0) GO TO 20
      W=10*CW
      CALL XWYW(XW,YW,XS,XF,W,CW,CH)
      IF(ABS(Y2).LT.1000.0) GO TO 110
      WRITE(7,57) N,Y2
   57 FORMAT('+',$,'Y(',I2,')',F7.0)
      GO TO 89
  110 IF(ABS(Y2).LT.100.0) GO TO 85
      WRITE(7,56) N,Y2
   56 FORMAT('+',$,'Y(',I2,')=',F7.1)
      GO TO 89
   85 IF(ABS(Y2).LT.10.0) GO TO 86
      WRITE(7,87) N,Y2
   87 FORMAT('+',$,'Y(',I2,')=',F7.2)
      GO TO 89
   86 IF(ABS(Y2).LT.1.0.AND.Y2.GT.0.0) GO TO 84
      WRITE(7,88) N,Y2
   88 FORMAT('+',$,'Y(',I2,')=',F7.3)
      GO TO 89
   84 WRITE(7,14) N,Y2
   14 FORMAT('+',$,'Y(',I2,')=',F7.4)
   89 XW=XW+14*CW
   20 IF(ISH.LT.3) RETURN
      X=X0
      Y=Y0
      ISH=ISH-1
      IF(ISH.EQ.3) GO TO 5
      X=X1
      Y=Y1
      GO TO 5
      END

      SUBROUTINE TOP(LU,DX,N,ASMX,BSMX,PX,NN,XW,YW,XL,DSPACE
     1,IN,IPF)
C
	IMPLICIT INTEGER*2 (A-H,O-Z)
      COMMON /SCN/ XS,XF,YS,YF,XXS,XXF,YYS,YYF,CSTR,CFIN,CYMIN,CYMAX
     1,STR,FIN,YMIN,YMAX,ZZ,CW,CH,ISP,JSP,IFL
      COMMON /XY/X,Y,X1,Y1,X2,Y2
C
      BYTE ISP,JSP,IFL
C
C  IPF POINT CENTROID TYPE FIT TO TOP OF PEAK
      CALL X2Y2(X,Y,NN,CW,CH)
      XMIN=-9
      IF(IPF.LT.3) IPF=3
      I1=ASMX*X+BSMX-1.0
      I2=ASMX*X+BSMX+1.
      IF(I1.LT.1) RETURN
      IF(I2.GT.N) RETURN
      DO 10 I=I1,I2
      J=I
      READ(LU'J) B
      IF(B.LT.XMIN) GO TO 10
      XMIN=B
      IPK=I
   10 CONTINUE
      PX=FLOAT(IPK-1)*DX+STR
      IF(IPF.EQ.0) GO TO 20
      XI=0.0
      XX=0.0
      JPF=IPF/2
      LPF=IPK-JPF-1
      DO 30 I=1,IPF
      J=LPF+I
      READ(LU'J)B
      XX=XX+B*(PX+FLOAT(I-JPF-1)*DX)
   30 XI=XI+B
      PX=XX/XI
   20 CALL PPX(XW,YW,PX,PXX,Q,NN,XS,XF,XL,IN,XMIN,CW,CH)
      IF(IN.EQ.'ED') WRITE(8,350) NN,PX,Q,H
  350 FORMAT(1X,I3,F9.3,F9.4,F9.2)
      IF(IN.NE.'ED') WRITE(8,351) NN,PX,PXX,Q,H
  351 FORMAT(1X,I3,F9.3,2F9.4,F9.1)
      RETURN
      END

      SUBROUTINE ALL(LU,DX,PX,XIN,DB2,BG,H,NN,XW,YW,ISH,WL,DSPACE,IN)
C
	IMPLICIT INTEGER*2 (A-H,O-Z)
      COMMON /SCN/ XS,XF,YS,YF,XXS,XXF,YYS,YYF,CSTR,CFIN,CYMIN,CYMAX,STR
     1,FIN,YMIN,YMAX,ZZ,CW,CH,ISP,JSP,IFL
      COMMON /CRD/AUSX,BUSX,AUSY,BUSY,ASUX,BSUX,ASUY,BSUY,AMSX,BMSX
     1,ASMX,BSMX,AUMX,BUMX,AMUX,BMUX,DSP,ITERM,N,NS,NF
      COMMON /XY/X,Y,X1,Y1,X2,Y2
C
C                                                           **********
C                                                           **  ALL **
C                                                           **********
C SUBROUTINE OF DIFPLOT INTERACTIVE PLOT PROGRAM
C ***********************************************
C   INTEGRATES THE PEAK BETWEEN X&X1
C ***************************************
      BYTE ISH,ISP,JSP,IFL,DSP,ITERM
C
      IF(IN.EQ.'XR') WL=DSPACE
      XX1=ASMX*X+BSMX
      XX2=ASMX*X1+BSMX
      I1=XX1
      IF(I1.LT.1) RETURN
      I2=XX2
      IF(I2.GT.N) RETURN
      YY1=ASUY*Y+BSUY
      YY2=ASUY*Y1+BSUY
      IF(BG.NE.1.0) GO TO 25
C INTEGRATES USING ACTUAL POINT ON CURVE
      READ(LU'I1) YY1
      READ(LU'I2) YY2
C INTEGRATES ABOVE ZERO
      YY1=0.
      YY2=0.
   25 AAG=(YY1-YY2)/(XX1-XX2)
      BBG=(XX1*YY2-XX2*YY1)/(XX1-XX2)
      SUM=0.0
      SX=0.0
      XMAX=0.0
      DO 10 I=I1,I2
      YY=AAG*I+BBG
      J=I
      READ(LU'J) BX
C INTEGRATES ABSOLUTE NUMBERS
C     BX=ABS(BX-YY)
C INTEGRATES NUMBERS WITH SIGN
      BX=BX-YY
      IF(I.EQ.I1.OR.I.EQ.I2) BX=0.5*BX
      SUM=SUM+BX
      SX=SX+(AMUX*I+BMUX)*BX
      IF(BX.LT.XMAX) GO TO 10
      PX=AMUX*I+BMUX
      IPX=I
      XMAX=BX
   10 CONTINUE
      IF(DB2.NE.1) GO TO 200
      H2=XMAX/2.
      DO 201 I=I1,IPX
      YY=AAG*I+BBG
      J=I
      READ(LU'J) BX
      BX=BX-YY
  201 IF(BX.GE.H2) GO TO 202
  202 XL=AMUX*J+BMUX
      DO 203 I=IPX,I2
      YY=AAG*I+BBG
      J=I
      READ(LU'J) BX
      BX=BX-YY
  203 IF(BX.LE.H2) GOTO 204
  204 XR=AMUX*J+BMUX
      FWHM=XR-XL
      DB2=SUM*DX/XMAX
  200 IF(H.EQ.1.0) H=XMAX
      XIN=SUM*DX
      CEN=SX/SUM
      IF(H.EQ.0.) GO TO 100
      W=13*CW
      CALL XWYW(XW,YW,XS,XF,W,CW,CH)
C PX IS THE HIGHEST POINT OF THE PEAK
      CALL PPX(XW,YW,PX,PXX,Q,NN,XS,XF,WL,IN,H,CW,CH)
      W=11*CW
  100 CALL XWYW(XW,YW,XS,XF,W,CW,CH)
      IF(XIN.LT.1000000.) GO TO 52
      WRITE(7,53) XIN
   53 FORMAT('+',$,'I=',F8.0)
      GO TO 35
   52 IF(XIN.LT.10000.0) GO TO 30
      WRITE(7,48) XIN
   48 FORMAT('+',$,'I=',F7.0)
      GO TO 35
   30 IF(XIN.LT.1000.0) GO TO 31
      WRITE(7,71) XIN
   71 FORMAT('+',$,'I=',F6.1)
      GO TO 35
   31 WRITE(7,72) XIN
   72 FORMAT('+',$,'I=',F6.2)
   35 XW=XW+10*CW
      IF(H.EQ.0.0) GO TO 101
      W=10*CW
      CALL XWYW(XW,YW,XS,XF,W,CW,CH)
      IF(H.LT.1000000.0) GO TO 12
      WRITE(7,352) H
  352 FORMAT('+',$,'H=',F8.0)
      GO TO 45
   12 IF(H.LT.10000.0) GO TO 13
      WRITE(7,353)H
  353 FORMAT('+',$,'H=',F7.0)
      GO TO 45
   13 IF(H.LT.1000.0) GO TO 36
      WRITE(7,73) H
   73 FORMAT('+',$,'H=',F6.0)
      GO TO 45
   36 IF(H.LT.10.0) GO TO 37
      WRITE(7,74) H
   74 FORMAT('+',$,'H=',F5.1)
      GO TO 45
   37 WRITE(7,75) H
   75 FORMAT('+',$,'H=',F5.2)
   45 XW=XW+10*CW
      W=10*CW
      CALL XWYW(XW,YW,XS,XF,W,CW,CH)
  101 IF(DB2.EQ.0.0) GO TO 97
      IDB2=DB2
      IF(DB2.LT.100000.) GO TO 54
      WRITE(7,55) IDB2
   55 FORMAT('+',$,'DB2=',I6)
      GO TO 95
   54 IF(DB2.LT.1000.0) GO TO 80
      WRITE(7,76) DB2
   76 FORMAT('+',$,'DB2=',F6.1)
      GO TO 95
   80 IF(DB2.LT.100.0) GO TO 81
      WRITE(7,77) DB2
   77 FORMAT(1H+,'$','DB2=',F6.2)
      GO TO 95
   81 WRITE(7,78) DB2
   78 FORMAT(1H+,$,'DB2=',F6.3)
   95 XW=XW+11*CW
      W=10*CW
      CALL XWYW(XW,YW,XS,XF,W,CW,CH)
      WRITE(7,79) FWHM
   79 FORMAT(1H+,$,'FWHM=',F5.2)
      IF(IN.EQ.'ED') WRITE(8,350) NN,PX,Q,H,XIN,DB2,FWHM
  350 FORMAT(1X,I3,F9.3,F9.4,2F9.2,9X,2F9.2)
      IF(IN.NE.'ED') WRITE(8,351) NN,PX,PXX,Q,H,XIN,DB2,FWHM
  351 FORMAT(1X,I3,F9.3,2F9.4,2F9.1,9X,2F9.3)
      XW=XW+10*CW
      W=10*CW
      CALL XWYW(XW,YW,XS,XF,W,CW,CH)
      ICEN=CEN
      IF(CEN.LT.100000.) GO TO 56
      WRITE(7,57) ICEN
   57 FORMAT(1H+$,'C=',I7)
   56 IF(CEN.LT.1000.0) GO TO 1
      WRITE(7,82) CEN
   82 FORMAT(1H+$,'C=',F7.1)
      GO TO 6
    1 IF(CEN.LT.100.0) GO TO 2
      WRITE(7,83) CEN
   83 FORMAT(1H+$,'C=',F7.2)
      GO TO 6
    2 WRITE(7,84) CEN
   84 FORMAT(1H+$,'C=',F7.3)
    6 XW=XW+10*CW
   97 RETURN
      END
