      SUBROUTINE INTER(NN,TYP,INST,YL,DSPACE,ID,BG,DB2,XH,JIN,ISH
     1,IX,D4)
C
      COMMON /XY/ X,Y,X1,Y1,X2,Y2
      COMMON /LBL/LABX,LABY,LX0,LX1,LX2,LX3,LY0,LY1,LY2,LY3,LY4,LY5,LY6
      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 /SCN/ XS,XF,YS,YF,XXS,XXF,YYS,YYF,CSTR,CFIN,CYMIN,CYMAX,STR
     1,FIN,YMIN,YMAX,ZZ,CW,CH,ISP,JSP,IFL
      BYTE DSP,ISP,JSP,ITERM,JIN,ISH,IX,IFL,TYP
      BYTE LABX(8),LABY(8),LX0(8),LX1(8),LX2(8),LX3(8),LY0(8),LY1(8)
     1,LY2(8),LY3(8),LY4(8),TEXT(80),LY5(8),LY6(8),D4(13)
C
C WRITTEN BY RAY GOEHNER FOR SPECPLOT  1/84
C
C SUBROUTINE OF SPECPLOT AN INTERACTIVE PLOTTING PROGRAM
C INTERACTIVE PORTION OF PROGRAM
C TWO CURSOR INPUTS
C INPUTS ARE (X,Y) LOWER LEFT HAND CORNER AND (X2,Y2) UPPER
C RIGHT HAND CORNER FOR E COMMAND 
C ********************************************************
C **************  CURSOR COMMANDS  ******************
C   ? WRITES OUT THE CURSOR COMMANDS TO THE SCREEN
C  X ACTUAL X POSITION
C  Y ACTUAL Y POSITION
C  P  CETROID TYPE FIT TO TOP OF THE PEAK IE IPF FIT
C  A RETURNS POSITION OF HIGHEST PT,HEIGHT,INTEGRAL,INTEGRAL WIDTH, CENTROID
C  C SAME AS A BUT INTEGRATES EVERYTHING ABOVE ZERO
C POSITION FOR THE BACKGROUND
C AND TWO FOR THE RANGE OF THE FIT
C  E EXPANDS THE WINDOWED AREA OF THE SPECTRA RETURNS JIN=20 OR 24
C  R REFRESHES THE PLOT RETURNS JIN=21
C  # REPLOTS THE SPECTRUM AS IT WAS   JIN=22
C  O WRITES THE 2THETA POSITION OF THE CURSOR ON THE PLOT
C  M GIVES ACTUAL X AND Y POSITION OF CURSOR
C  D RETURNS DSPACE OF CURSOR FOR DIF DATA
C  L RETURNS LAMDA OF CURSOR FOR XRF SPECTRUM
C  S  CONVERTS TO SEMILOG IF LINEAR OR CONVERTS TO LINEAR IF SEMILOG
C  I  CONVERTS TO INTEGRAL DISPLAY
C  Q  CONVERTS TO SQUARE ROOT DISPLAY
C  N  CONVERTS TO NORMATIZED DISPLAY
C  1 CONVERTS TO 1ST DERIVATIVE DISPLAY
C  2 CONVERTS TO 2ND DERIVATIVE DISPLAY
C  K  DISPLAYS THE ELEMENT MARKERS WITHIN THE DISPLAY RANGE FOR XRF DATA
C  J  JCPDS PDF#(FILE,CARD) INPUT TO PLOT D&I
C  W  2THETA TO DSPACING TO WAVELENGTH - DIF AND XRF
C  F,G  DISPLAY RESULTS OF PK SEARCH (TYP=2 OR 3) *.PKS OR *.SPC
C  T  TEXT COMMAND PLACE TEXT FROM KEYBOARD ONTO PLOT
C  B  POLY BKGR FIT <CR> TERMINATES CURSOR INPUTS
C  H  HARDCOPY TO LP
C  -  DELETE PEAK FROM *.SPC  JIN=10
C
C  JIN=1 CALL TOP
C  JIN=2 CALL ALL
C  JIN=3 PROFILE FIT
C  JIN=4 CALL CURSXY
C  JIN=5 CALL MARKER (ELEMENTAL MARKERS)
C  JIN=6 CALL JCPDS (DISPLAY CARD)
C  JIN=7 (F) DISPLAY RESULTS   OF PK SEARCH (TYP=2 OR 3)
C  JIN=8 (G) SAME AS F BUT ASKS FOR FILENAME
C  JIN=9 (B) POLYNOMIAL BKGR SUBTRACT
C  JIN=10 (-) DELETE PEAKS FROM *.SPC
C
C  JIN=20  E COMMAND
C  JIN=21  R COMMAND  REPLOT
C  JIN=22  RF OR # COMMAND REFRESH SCREEN
C   JIN=23  I,S,N, OR Q
C
C   JIN=24  E  OVERLAY EXPAND
C
C BG=0 INTEGRATE USING USER BKGR FROM TWO CURSOR POSITIONS
C BG=1 INTEGRATE ABOVE ZERO
C BG=2 USE ACTUAL VALUE OF DATA AT X CURSOR POSITION FOR BKGR
C
C DB2=1 CALCULATE DEBYE HALF WIDTH    AND FWHM
C
C XH=1 CALCULATE HIGHEST POINT
C
C  ISH=-1 D COMMAND
C  ISH=-2 L COMMOND
C  ISH=0  X COMMOND
C  ISH=1  Y COMMOND
C  ISH=2  X&Y POSITIONS
C
      INTEGER CR,CE,CX,CY,CP,CF,CS,CI,CA,CC,CO,CD,CM,CT
      INTEGER CG,CZ,CQ
      DATA CR,CE,CX,CY/'R','E','X','Y'/
      DATA CP,CF,CS,CI,CC,CA/'P','F','S','I','C','A'/
      DATA CO,CD,CM,CT/'O','D','M','T'/
      DATA CG,CZ,CQ/'G','Z','?'/
C
      JIN=0     ! NO INTERACTIVE COMMAND
   58 IF(ITERM.EQ.2) CALL T4662(0,0) !TURN PLOTTER OFF
      CALL CURSOR(ID,X,Y,ITERM)
      IF(ID.NE.'0') GO TO 158   !                             0
      JIN=30
      RETURN
  158 IF(ISP.EQ.1) GO TO 59 ! SPLIT SCREEN
      IF(ISP.GE.3) GO TO 59 ! OVERLAY - changed from '.GT.' -- MFG
      IF(ITERM.EQ.2) CALL T4662(1,3) ! TURN PLOTTER ON WITH PEN 3
      IF(ID.NE.'O'.AND.ID.NE.'o') GO TO 60                !O
      X2=X-2*CH
      Y2=Y+CW
      CALL TPLOT(2,X2,Y2)
      X2=ASUX*X+BSUX
      WRITE(7,6) X2
      GO TO 58
   60 IF(ID.NE.'D'.AND.ID.NE.'d') GO TO 61              ! D
      IF(INST.NE.'DI') GO TO 58                         ! 'DIF' ONLY
      X2=X-2*CH
      Y2=Y+CW
      CALL TPLOT(2,X2,Y2)
      X2=ASUX*X+BSUX
      X2=YL/(2.*SIN(0.00872665*X2))
      WRITE(7,7) X2
      GO TO 58            
   61 IF(ID.NE.'L'.AND.ID.NE.'l') GO TO 62               !L
      IF(INST.NE.'XR') GO TO 58                          ! 'XRF' ONLY
      X2=X-2*CH
      Y2=Y+CW
      CALL TPLOT(2,X2,Y2)
      X2=ASUX*BSUX
      X2=DSPACE*SIN(0.00872665*X2)
      WRITE(7,7) X2
      GO TO 58
   62 IF(ISP.EQ.2) GO TO 63
      IF(ID.NE.'E'.AND.ID.NE.'e') GO TO 63                !E
      CALL CURSOR(ID,X2,Y2,ITERM)
      CSTR=ASUX*X+BSUX
      CFIN=ASUX*X2+BSUX
      CYMAX=ASUY*Y2+BSUY
      JIN=24
      RETURN
   63 IF(ID.NE.'T'.AND.ID.NE.'t') GO TO 64               ! T
      CALL TPLOT(2,X,Y)
      READ(7,2000,END=999) TEXT
      GO TO 58
   64 IF(ID.NE.' ') GO TO 58
      RETURN
C
C  ALL OTHERS
C
   59 IF(ID.NE.CR.AND.ID.NE.'r') GO TO 20                  ! R
      JIN=21
      CSTR=STR
      CFIN=FIN
      CYMIN=YMIN
      CYMAX=YMAX
      RETURN
   20 IF(ID.NE.CE.AND.ID.NE.'e') GO TO 30                  ! E
      CALL CURSOR(ID,X2,Y2,ITERM)
      CSTR=ASUX*X+BSUX
      CFIN=ASUX*X2+BSUX
      CYMIN=ASUY*Y+BSUY
      CYMAX=ASUY*Y2+BSUY
      JIN=20
      RETURN
   30 IF(ID.NE.CX.AND.ID.NE.'x') GO TO 34                   ! X
      JIN=4
      ISH=0
      RETURN
   34 IF(ID.NE.CM.AND.ID.NE.'m') GO TO 31                  ! M
      ISH=2
      JIN=4
      RETURN
   31 IF(ID.NE.CO.AND.ID.NE.'o') GO TO 21                  ! O
      IF(ITERM.EQ.2) CALL T4662(1,3)
      X2=X-2*CH
      Y2=Y+CW
      CALL TPLOT(2,X2,Y2)
      X2=ASUX*X+BSUX
      I=X2
      Y2=Y+CW
      IF(X2.LT.10000.) GO TO 1
      WRITE(7,22) I
   22 FORMAT('+',$,I6)
      GO TO 58
    1 IF(X2.LT.1000.0) GO TO 2
      WRITE(7,5) X2
    5 FORMAT('+',$,F6.1)
      GO TO 58
    2 IF(X2.LT.100.) GO TO 3
      WRITE(7,6) X2
    6 FORMAT('+',$,F6.2)
      GO TO 58
    3 WRITE(7,7) X2
    7 FORMAT('+',$,F6.3)
      GO TO 58
   21 IF(ID.NE.CY.AND.ID.NE.'y') GO TO 32                  ! Y
      ISH=1
      JIN=4
      RETURN
   32 IF(ID.NE.CP.AND.ID.NE.'p') GO TO 33                  ! P
      IF(ISP.EQ.5) GO TO 58
      JIN=1
      IF(INST.EQ.'XR') YL=DSPACE ! ITS EASIER THIS WAY
      RETURN
   33 IF(ID.NE.CI.AND.ID.NE.'i') GO TO 41                   ! I
      JIN=23
      IF(DSP.NE.1) GO TO 86
      DSP=0
      DO 87 I=1,8
   87 LABY(I)=LY0(I)
      RETURN
   86 DSP=1
      DO 88 I=1,8
   88 LABY(I)=LY1(I)
      RETURN
   41 IF(ID.NE.CA.AND.ID.NE.'a') GO TO 42                   ! A
      IF(ISP.EQ.5) GO TO 58
      XH=1.0
      BG=0.0
      DB2=1.0
      GO TO 44
   42 IF(ID.NE.CC.AND.ID.NE.'c') GO TO 70                    ! C
      IF(ISP.EQ.5) GO TO 58
      BG=1.
      XH=1.
      DB2=1.
   44 CALL CURSOR(ID,X1,Y1,ITERM)
      IF(ITERM.EQ.2) CALL T4662(1,3)
      IF(BG.EQ.1.0) GO TO 17
      CALL TPLOT(0,X,Y)
      CALL TPLOT(1,X1,Y1)
   17 X2=0.5*(X1+X)
      Y2=0.5*(Y1+Y)-40.
      CALL X2Y2(X2,Y2,NN,CW,CH)
      JIN=2
      IF(ITERM.EQ.2) CALL T4662(0,0)
      RETURN
   70 IF(ID.NE.CD.AND.ID.NE.'d') GO TO 73                     ! D
      IF(INST.NE.'DI') GO TO 58                            ! 'DIF ONLY'
      X2=X-2*CH
      Y2=Y-CW
      CALL TPLOT(2,X2,Y2)
      X=ASUX*X+BSUX
      X=YL/(2.*SIN(0.00872665*X))
      WRITE(7,7) X
      GO TO 58
   73 IF(ID.NE.'L'.AND.ID.NE.'l') GO TO 71                 ! L
      IF(INST.NE.'XR') GO TO 58                            ! 'XRF' ONLY
      JIN=4
      ISH=-2
      RETURN
   71 IF(ID.NE.CQ) GO TO 75                                  ! ?
      CALL HELP(ITERM,5,11,D4,XS,YF,CH)
      JIN=21
      RETURN
   75 IF(ID.NE.CS.AND.ID.NE.'s') GO TO 74                   ! S
      JIN=23
      IF(DSP.NE.2) GO TO 83
      DSP=0
      DO 84 I=1,8
   84 LABY(I)=LY0(I)
      RETURN
   83 DSP=2
      DO 85 I=1,8
   85 LABY(I)=LY2(I)
      RETURN
   74 IF(ID.NE.'K'.AND.ID.NE.'k') GO TO 76                   ! K
      JIN=5
      RETURN
   76 IF(ID.NE.'#') GO TO 77                                  ! #
      JIN=22
      RETURN
   77 IF(ID.NE.'J'.AND.ID.NE.'j') GO TO 78                  ! J
      JIN=6
      RETURN
   78 IF(ID.NE.'Q'.AND.ID.NE.'q') GO TO 95                  ! Q
      JIN=23
      IF(DSP.NE.3) GO TO 80
      DSP=0
      DO 81 I=1,8
   81 LABY(I)=LY0(I)
      RETURN
   80 DSP=3
      DO 82 I=1,8
   82 LABY(I)=LY3(I)
      RETURN
   79 CONTINUE
   95 IF(ID.NE.'N'.AND.ID.NE.'n') GO TO 102                   ! N
      JIN=23
      IF(DSP.NE.4) GO TO 103
       DSP=0
      DO 104 I=1,8
  104 LABY(I)=LY0(I)
      RETURN
  103 DSP=4
      DO 105 I=1,8
  105 LABY(I)=LY4(I)
      RETURN
  102 IF(ID.NE.'W'.AND.ID.NE.'w') GO TO 96                     ! W
      IF(INST.EQ.'ED')GO TO 58                   ! 'DIF' AND 'XRF' ONLY
      JIN=22
      IF(IX.NE.1) GO TO 97
      DO 98 I=1,8
   98 LABX(I)=LX0(I)
      IX=0
      RETURN
   97 IX=1
      IF(INST.NE.'DI') GO TO 99                            
      DO 100 I=1,8
  100 LABX(I)=LX1(I)
      RETURN
   99 DO 101 I=1,8
  101 LABX(I)=LX2(I)
      RETURN
   96 IF(ID.NE.'F'.AND.ID.NE.'G'.AND.ID.NE.'f'.AND.ID.NE.'g') GO TO 106  ! G F
      IF(JSP.GT.1) GO TO 58
      IF(TYP.EQ.1.OR.TYP.EQ.3.OR.TYP.EQ.5) GO TO 58
      JIN=7
      IF(ID.EQ.'F'.OR.ID.EQ.'f') RETURN
      JIN=8
      RETURN
  106 IF(ID.NE.'T'.AND.ID.NE.'t') GO TO 107                         ! T
      IF(ITERM.EQ.2) CALL T4662(1,3)
      CALL TPLOT(2,X,Y)
      READ(7,2000,END=999) TEXT
 2000 FORMAT(80A1)
      GO TO 58
  107 IF(ID.NE.'1') GO TO 111                                   ! '1'
      JIN=23
      IF(DSP.NE.5) GO TO 109
      DSP=0
      DO 108 I=1,8
  108 LABY(I)=LY0(I)
      RETURN
  109 DSP=5
      DO 110 I=1,8
  110 LABY(I)=LY5(I)
      RETURN
  111 IF(ID.NE.'2') GO TO 115                             ! '2'
      JIN=23
      IF(DSP.NE.6) GO TO 113
      DSP=0
      DO 112 I=1,8
  112 LABY(I)=LY0(I)
      RETURN
  113 DSP=6
      DO 114 I=1,8
  114 LABY(I)=LY6(I)
      RETURN
  115 IF(ID.NE.'B'.AND.ID.NE.'b') GO TO 116               ! B
      JIN=9
      RETURN
  116 IF(ID.NE.'-') GO TO 117                             ! -
      JIN=10
      RETURN
  117 IF(ID.NE.' ') GO TO 58
      JIN=0
      RETURN
  999 STOP 'INTER SIGNING OFF'
      END
C
	SUBROUTINE HELP(ITERM,LTERM,LHELP,DHELP,XS,YF,CH)
C
C  SUBROUTINE OPENS FILE AND PRINTS MESSAGES FOUND THERE
C  USES SUBROUTINE CLEAR TO ERASE SCREEN -- ITERM IS TERMINAL TYPE
C
	BYTE DHELP(13),DSN(26),ITERM,DSP
	BYTE ALINE(73),A
C
        IF(ITERM.EQ.6) THEN
		CALL VT240(1)
		CALL VT240(3)
	ENDIF
C
	DO 100 I=1,13
100	DSN(I)=DHELP(I)
	DSN(14)='S'
	DSN(15)='P'
	DSN(16)='E'
	DSN(17)='C'
	DSN(18)='P'
	DSN(19)='L'
	DSN(20)='O'
	DSN(21)='T'
	DSN(22)='.'
	DSN(23)='H'
        DSN(24)='L'
	DSN(25)='P'
	DSN(26)=0
C
	OPEN(UNIT=LHELP,NAME=DSN,TYPE='OLD',SHARED,READONLY,ERR=950)
C
      CALL CLEAR(ITERM)
150	DO 200 I=1,23
	READ(LHELP,9000,END=800)ALINE
9000	FORMAT(73A1)
	WRITE(LTERM,9000)ALINE
200	CONTINUE
	WRITE(LTERM,9020)
9020	FORMAT('$ ENTER <CR> FOR MORE OR STOP TO RETURN >')
	READ(LTERM,9030,END=999)A
9030	FORMAT(A1)
	IF(A.EQ.'S')GO TO 810
      CALL CLEAR(ITERM)
	GO TO 150
800	WRITE(LTERM,9800)
9800	FORMAT('$ ENTER <CR> TO CONTINUE > ')
	READ(LTERM,9030,END=999)A
  810 CALL CLEAR(ITERM)
	CLOSE(UNIT=LHELP)
	IF(ITERM.EQ.6) CALL VT240(2)
	RETURN
950	WRITE(LTERM,9500)
9500	FORMAT(' ***** NO HELP AVAILABLE ******* ')
	IF(ITERM.EQ.6) CALL VT240(2)
	RETURN
999	STOP
	END
