c
c MAIN MENU ADDED RPG TO CUSTOMIZE 5/1985 (MMENU) 
C 
      SUBROUTINE MENU(FN,DSP,IG,YD,ITERM,TYP,IX,D1,D2,D3,D4,LOGO,FR,VER
     1,INST)
C
      INTEGER INST(2)
      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 /COLOR/ CL,CLB,CLA,CLG
      COMMON /MFG/ KBKGR,KK2,KSCH,KNRM,KSTD
      COMMON /DPRC/ IDPRC,IBKGR,ISCH,INRM,ISTD,NDER,MF,MB,IK2,ISM,IPF
     1,NT,SENS,INSTD,EXSTD,E2T
C
      BYTE IBKGR,IK2,ISCH,INRM,IDPRC,ISTD,NDER,MF,MB,ISM,INSTD(30)
     1,EXSTD(30),A2,KBKGR,KK2,KSCH,KNRM,KSTD
      DIMENSION DP(2)
	DOUBLE PRECISION DD(5),SS(9),X1(4),Y1(7)
      BYTE CL,CLB,CLA,CLG(5)
      BYTE ISP,JSP,DSP,IG,ITERM,IX,IFL,JIN,TYP
      BYTE FN(9,30),ANS,VER(72)
      BYTE D1(13),D2(13),D3(13),D4(13),LOGO(12)
	DATA DD/'FULL    ','SPLIT   ','OVERLAY ','ADDITION','SUBTRACT'/
	DATA SS/'SPEC.RAW','SPEC.SPC','D11.RAW','D11.DIF'
     1,'D500.RAW','D500.DIF','PGT.ASC ','PIXE.ASC','DENS.ASC'/
	DATA X1/'2-THETA ','DSPACING','LAMBDA  ','ENERGY  '/
	DATA Y1/'LINEAR  ','INTEGRAL','LOG     ','SQRT    ','SC 0-100'
     1	,'1ST DIFF','2ND DIFF'/
      DATA DP/'NO  ','YES '/
C
C
C  LU-1 DEFAULT FILE ON SY0:
C
C  VER ARRAY CONTAINING CURRENT VERSION OF SPECPLOT
C  TYP IS FILE TYPE SPECPLOT OR SIEMENS
C  TYP=0 SPECPLOT.RAW
C  TYP=1 SPECPLOT.DIF
C  TYP=2 DIFF11.RAW
C  TYP=3 DIFF11.DIF
C  TYP=3 DIF500.RAW
C  TYP=4 DIFF500.DIF
C  TYP=6 PGT.ASC -- ASCII PGT EDS DATA
C  TYP=7 PIXE.ASC -- ASCII PIXIE DATA
C  TYP=8 RAW DENSITOMETER DATA -- ASCII
C
C  D1 IS DISK VOL WITH DATA FILES
C  D2 IS DISK VOL WITH JCPDS DATA BASE
C  D3 IS DISK VOL WITH ELEMENTAL DATA BASE
C  D4 IS DISK VOL WITH HELP FILES
C
C  IDPRC  ONLINE DATA PROCESSING (0-NO  1-YES)
C  IBKGR=0 NONE
C  IBKGR=1 LINEAR BKGR
C  IBKGR=2 PARABOLIC BKGR
C  NB NUMBER BACK  AND NF NUMBER FORWARD  FOR BKGR SUBTRACTION
C  ISCH=0 NONE
C  ISCH>0 NUMBER OF PTS TO CALCULATE 2ND DERIVATIVE OVER (SMOOTH)
C  SENS  SENSITIVITY FOR SEARCH  IE  SENS* Std Dev
C  INRM=0 NONE
C  INRM=1 NORMALIZE DATA
C  ISTD=0 NONE
C  ISTD=1 EXTERNAL STD
C  ISTD=2 INTERNAL STD (INTERNAL.STD)
C  ISTD=3 EXTERNAL & INTERNAL STD (EXTERNAL.STD & INTERNAL.STD)
C
C  ISM=0 NO REAL DATA SMOOTH
C  ISM>0 NUMBER OF PTS TO SMOOTH OVER
C  NDER  NUMBER OF PTS TO TAKE DERIVATIVE OVER 5,7,9,11,15,19,25
C  IK2=0 NO K ALPHA ELIMINATION
C  IK2=1 RACHINGER
C  IK2=2 LADELL
C
C  ****    MENU OUTPUT      ***********
200	CALL CLEAR(ITERM)
	IF(ISP.EQ.2.OR.ISP.EQ.3) IDPRC=0
C	TYPE *,'RP Goehner, Adv. in X-Ray Analysis, 23, 305-381, 1980'
C	TYPE *,'Modified for Siemens file structure May 1985'
	TYPE *,' '
      WRITE(6,9002) VER
 9002 FORMAT(1X,72A1)
	TYPE *,' '
	TYPE *,'  ***************** MAIN MENU ************************'
C        WRITE(6,8900)INST
8900    FORMAT(1X,T5,' 0   DATA TYPE ',T55,2A2)
C        WRITE(6,9001)SS(TYP+1)
9001	FORMAT(1X,T5,' 1   FILE TYPE ',T55,A8)
	WRITE(6,9005)DD(ISP)
9005	FORMAT(1X,T5,' 1   DISPLAY ',T55,A8) ! MOD RPG
	VV=IX+1
	IF(IX.EQ.1.AND.INST(1).EQ.'XR')VV=2
	IF(IX.EQ.1.AND.INST(1).EQ.'DI')VV=3
        IF(INST(1).EQ.'ED')VV=4  ! EDA DATA CAN ONLY DISPLAY IN ENERGY
	WRITE(6,9010)X1(VV)
9010	FORMAT(1X,T5,' 2   X-AXIS ',T55,A8)! MOD RPG
	WRITE(6,9020)Y1(DSP+1)
9020	FORMAT(1X,T5,' 3   Y-AXIS ',T55,A8) ! MOD RPG
	IF(ISP.GT.1.AND.JSP.LT.2)JSP=2
	IF(ISP.EQ.1)JSP=1
	WRITE(6,9030)JSP
9030	FORMAT(1X,T5,' 4   NUMBER OF FILES TO DISPLAY ',T55,I2)! MOD RPG
      WRITE(6,9035) ISM
 9035 FORMAT(1X,T5,' 5   SMOOTH DATA',T55,I2)! MOD RPG
	IF(ISP.GT.3)WRITE(6,9040)FR
9040	FORMAT(1X,T5,' 6   FRACTION OF SECOND FILE TO ADD/SUBTRACT '
     1	,T55,F4.2) ! MOD RPG
	IF(ISP.EQ.3)WRITE(6,9050)YD
9050	FORMAT(1X,T5,' 6   PERCENT DISPLACEMENT FOR OVERLAY ',T55,F4.2)!MOD RPG
	IF(DSP.GT.4)WRITE(6,9060)NDER
9060	FORMAT(1X,T5,' 7   # OF POINTS FOR DERIVATIVE CALCULATION '
     1	,T55,I2) ! MOD RPG
      I=IDPRC+1
      IF(JSP.EQ.1) WRITE(6,9070) DP(I)
 9070 FORMAT(1X,T5,' 8   DATA PROCESSING',T55,A4) ! MOD RPG
	IF(JSP.EQ.1) WRITE(6,9080)
9080	FORMAT(T5,' 9   SHOW DATA PROCESSING PARAMETERS')! MOD RPG
C ADDITIONS BY RLS 2/86
	WRITE(6,9082)INST
9082	FORMAT(1X,T5,' A   DATA TYPE: DIF OR XRF ',T55,2A2)
	WRITE(6,9084) ITERM
9084	FORMAT(1X,T5,' B   TERMINAL: 0=4010 1=4027 2=4662 5=4105',
     1' 6=VT240',T55,I2)
	WRITE(6,9085) TYP
C  TYP=0 SPECPLOT.RAW
C  TYP=1 SPECPLOT.DIF
9085	FORMAT(1X,T5,' C   FILE TYPE: 0=SPECPLOT.RAW, 1=SPECPLOT.SPC'/
     120X,'2=DIFF11.RAW, 3=DIFF11.DIF,'/
     120X,'4=DIFF500.RAW, 5=DIFF50.DIF',T55,I2)
	WRITE(6,9086) IBKGR
9086	FORMAT(1X,T5,' D   BACKGROUND: 0=NONE, 1=LINEAR, 2=PARABOLIC',
     1 T55,I2)
	WRITE(6,9087) ISTD
9087	FORMAT(1X,T5,' E   DATA CORRECTION: 0=NONE, 1=EXTERNAL,',
     1 ' STANDARD'/8X,' 2=INTERNAL STANDARD, 3=INTERNAL',
     2 ' & EXTERNAL',T55,I2)
	WRITE(6,9088) IK2
9088	FORMAT(1X,T5,' F   ALPHA 2 REMOVAL: 0=NONE, 1=RACHINGER,',
     1 ' 2=LADELL',T55,I2)
	TYPE *, ' '
	TYPE *,' '
	WRITE(6,9200)
9200	FORMAT('$ ENTER ITEM TO CHANGE OR <CR> TO CONTINUE > ')
	IQ=0
	READ(5,9210,END=999)IQ,ANS,A2
9210	FORMAT(Q,2A1)
	IF(IQ.EQ.0)GOTO 303
C
C  ADDED FOR SIEMENS CUS FOR XRF & XRD DATA
C
	IF(ANS.EQ.'9') THEN
	  ANS='1'
	  A2='0'
	ELSE
	  ANS=ANS+1
	ENDIF
C
C        IF(ANS.EQ.'0'.AND.IQ.EQ.1)CALL DTYPE(INST,ITERM)
C	IF(ANS.EQ.'1'.AND.IQ.EQ.1)CALL FTYPE(TYP,INST,ITERM)
	IF(ANS.EQ.'2')CALL DISPL(ISP,ITERM)
	IF(ANS.EQ.'3')CALL AXISX(IX,INST,ITERM,TYP)
	IF(ANS.EQ.'4')CALL AXISY(DSP,ITERM)
	IF(ANS.EQ.'5')CALL FNUM(JSP,ITERM,ISP)
      IF(ANS.EQ.'6') CALL MSRCH(ISM,ITERM)
	IF(ANS.EQ.'7'.AND.ISP.GT.2)CALL FRACT(FR,YD,ISP,ITERM)
	IF(ANS.EQ.'8'.AND.DSP.GT.4)CALL DPTS(NDER,ITERM)
C CHECK FILE TYPE
        IF(ANS .EQ. 'B')THEN
       		IF(INST(1).EQ.'DI')THEN
     			INST(1) = 'XR'
     			INST(2) = 'F '
     		ELSE
     			INST(1) = 'DI'
     			INST(2) = 'F '
     		ENDIF
     	ENDIF
C CHECK TERMINAL TYPE
       IF(ANS .EQ. 'C'.OR.ANS .EQ. 'D'.OR.ANS .EQ. 'E'.OR.ANS 
     1 .EQ. 'F'.OR. ANS .EQ. 'G') THEN
       		WRITE(6,9014) ANS-1
9014	FORMAT('$ENTER NEW VALUE FOR ITEM ',A1,':')
       		READ(5,9015) ITEMP
9015		FORMAT(I)
       		IF(ANS .EQ. 'C') ITERM = ITEMP
       		IF(ANS .EQ. 'D') TYP   = ITEMP
       		IF(ANS .EQ. 'E') IBKGR = ITEMP
       		IF(ANS .EQ. 'F') ISTD  = ITEMP
       		IF(ANS .EQ. 'G') IK2   = ITEMP
       ENDIF
	IF(ANS.NE.'9') GO TO 302
      IF(IDPRC.NE.0) GO TO 301
	IDPRC=1
C RESTORE OLD VALUES FOR DATA PROCESSING
	IBKGR=KBKGR
	IK2=KK2
	ISCH=KSCH
	INRM=KNRM
	ISTD=KSTD
	GO TO 302
301   IDPRC=0
        KBKGR=IBKGR
        KK2=IK2
        KSCH=ISCH
        KNRM=INRM
        KSTD=ISTD
302	IF(ANS.EQ.'1'.AND.A2.EQ.'0')CALL DPM2(ITERM,INST)
      IF(JSP.GT.1) IDPRC=0
	GOTO200
C
303	CALL CLEAR(ITERM)
C -- MAKE SURE THINGS ARE ZEROED IF DATA PROCESSING NOT SELECTED
      IF(IDPRC.NE.0) GO TO 306
      KBKGR=IBKGR
      IBKGR=0
      KK2=IK2
      IK2=0
      KSCH=ISCH
      ISCH=0
      KNRM=INRM
      INRM=0
      KSTD=ISTD
      ISTD=0
      GO TO 401
  306 IF(ISCH.NE.0) GO TO 307
      INRM=0
      ISTD=0
      GO TO 401
  307 IF(INRM.EQ.0) ISTD=0
      IF(IBKGR.EQ.0) IK2=0
C--
401   IF(JSP.GT.1) GO TO 110
  304 WRITE(6,1000)
 1000 FORMAT(1H$,'FILENAME > ')
      READ(5,1010,END=999) IQ,(FN(1,I),I=1,30)
 1010 FORMAT(Q,30A1)
      IF(IQ.EQ.0) GO TO 304
      IF(IQ.LT.30)FN(1,IQ+1)=0
      IJ=1
      CALL EXT(IQ,FN,IJ,D1,TYP)
      GO TO 120
  110 DO 130 I=1,JSP
  111 WRITE(6,1020) I
 1020 FORMAT(1H$,'FILENAME NUMBER ',I1,1X,'IS > ')
      READ(5,1010,END=999) IQ,(FN(I,J),J=1,30)
      IF(IQ.EQ.0) GO TO 111
      IF(IQ.LT.30)FN(I,IQ+1)=0
      IJ=I
      CALL EXT(IQ,FN,IJ,D1,TYP)
  130 CONTINUE
  120 RETURN
  999 STOP
 9000 WRITE(6,2000)
 2000 FORMAT(1X,'SPECPLOT.DFT WAS NOT OPENED'/
     1' DOES IT EXISTS UNDER THIS UIC')
   99 STOP
      END
