C==========================================================================
	SUBROUTINE SHOWHKL(fil1,fil2)
	INTEGER fil1,fil2
C==========================================================================
C----------------------------------------------------------------------
C Used to show which peaks would be expected to become extinct. 
C A symmetry operation is supplied to the program and reflections
C from the file are displayed in one of three colors (or line styles
C if the graphics device is incapable of displaying color graphics). 
C The basic color is used for peaks that would not be extinct, the second
C color is used for peaks that would be extinct. A third color is used 
C for peaks that would be overlapped.
C 
C If raw data is in the diffractogram file, that data is also displayed.
C If two file numbers are given, the data from the second file is displayed.
C 
C If the interactive graphics device has a graphics cursor, the cursor can
C be used to selectively label the indices of selected reflections
C----------------------------------------------------------------------
C display peaks from file 1 (FIL1)
C display data from file 2  (FIL2)
C==========================================================================
	include 'cmpr.common'
	include '[-.shared]flabel.common'

	REAL PPOS(M$PKS)
	INTEGER*2 PNUM(M$PKS)
	LOGICAL FLAG, hardf, colflag
	REAL peakscl/0.0/,datscl/1.0/
	CHARACTER*30 LBL

	INTEGER IEXTCD(13)/13*0/
	INTEGER nh, nk, nl
	LOGICAL TSTEXTN,EXTFLAG,curflag,XLIMFL

	real POVER/.05/

	INTEGER STATUS,CLI$GET_VALUE,CLI$PRESENT,lib$spawn
	EXTERNAL CLI$_PRESENT,CLI$_DEFAULTED,CLI$_ABSENT,CLI$_NEGATED
	LOGICAL GET_NUMBER,GET_LOGICAL,GET_FNUMBER

	CHARACTER*20 pklbl	  
	REAL xmar, ymar, xln, yln, xln1, yln1
	CHARACTER*1 ID

	HARDF = .FALSE.
	WAVEL = WAVE(fil1)

C convert peaks to two-theta values
	IF (WAVEL .GT. 0) THEN
	  npk = 0
	  DO J=1,NPKS(fil1)
	    call XYCONV(dspace(j,fil1),0.0,xtyp_D,1,0.0
	1	,ppos(npk+1),x1,XTYP_TT,I,wavel,.false.,*22)
	    IF (I .gt. 0) THEN
	      npk = npk + 1
	      pnum(npk) = J
	    ENDIF
	  ENDDO
	ELSE
	  DO J=1,NPKS(fil1)
	    ppos(j) = TT(J,fil1)
	    pnum(npk) = J
	  ENDDO
	  npk = NPKS(fil1)
	ENDIF

C no peaks to plot -- error
	IF (npk .eq. 0) THEN
	  write (lo,'(A)') ' Warning -- no peaks to plot!'
	  CALL PS_PAUSE(PROMPT)
	  return
	ENDIF
C sort the peaks by two-theta
	CALL SORT(PNUM,PPOS,NPK,1)

C convert raw data find the maximum and minimum two-theta value in the raw data
	IF (NPOINT(fil2) .gt. 0) THEN
	  IF (WAVEL .GT. 0.0 .and. WAVE(fil2) .ne. WAVEL) THEN
	    call XYCONV(BX(1,fil2),B(1,fil2),FXTYP(fil2),NPOINT(fil2)
	1	,WAVE(fil2),AX,A,XTYP_TT,npnt,wavel,.false.,*23)
	  ELSE
	    DO J=1,NPOINT(fil2)
	      AX(j) = BX(J,fil2)
	      A(j)  = B(J,fil2)
	    ENDDO
	    npnt = NPOINT(fil2)
	  ENDIF
	ELSE
	  npnt = 0
	ENDIF
	IF (npnt .gt. 0) THEN
	  XMIN = ax(1)
	  XMAX = ax(1)
	  DO J=2,npnt
	    XMIN = MIN(XMIN,ax(J))
	    XMAX = MAX(XMAX,ax(J))
	  ENDDO
	ENDIF
C no points to plot in data
23	IF (npnt .eq. 0)  fil2 = 0

C if there are no data use the maximum and minimum two-theta value in the peaks
	IF (fil2 .eq. 0) then
	  xmin = ppos(1) - .1
	  xmax = ppos(npk) + .1
	ENDIF
C XLOW and XHIGH qualifier
	SLIM = XMIN
	FLIM = MIN(XMAX,ppos(npk))
	XLIMFL = .false.
	IF (CLI$PRESENT('XLOW')) THEN
	  FLAG = GET_FNUMBER('XLOW',slim)
	  IF (.not. FLAG) XLIMFL = .true.
	ENDIF
	IF (CLI$PRESENT('XHIGH')) THEN
	  FLAG = GET_FNUMBER('XHIGH',flim)
	  IF (.not. FLAG) XLIMFL = .true.
	ENDIF

100	IF (.not. XLIMFL) then
	  WRITE (LO,10) 'lower','x-axis',XMIN
10	  FORMAT (/'$Enter ',a,' limit for ',a,' [Default=',F7.3']: ')
	  READ (LI,'(Q,f10.0)',end=999,err=100) I,SLIM
	  IF (I.EQ.0) SLIM = XMIN

	  WRITE (LO,10) 'upper','x-axis',MIN(XMAX,ppos(npk)+.1)
	  READ (LI,'(Q,f10.0)',end=999,err=100) I,flim
	  IF (I.EQ.0) FLIM = MIN(XMAX,ppos(npk)+.1)
	ENDIF

C find the maximum and minimum intensity for the peaks
	FLAG = .false.
	DO J=1,NPK
	  yt = PKHT(pnum(J),fil1)
	  IF (ppos(J) .ge. min(SLIM,FLIM) 
	1	.and. ppos(J) .le. max(SLIM,FLIM) .and. .not. FLAG) THEN
	    FLAG = .true.
	    ymin = yt
	    ymax = yt
	  ELSEIF (ppos(J) .ge. min(SLIM,FLIM) 
	1	.and. ppos(J) .le. max(SLIM,FLIM)) THEN
	    ymin = MIN(ymin,yt)
	    ymax = MAX(ymax,yt)
	  ENDIF
	ENDDO
C no peaks to plot -- error
	IF (.not. flag) THEN
	  write (lo,'(A)') 'Warning -- no peaks to plot!'
	  XLIMFL = .false.
	  goto 100  
	ENDIF

C find the maximum and minimum intensity in the raw data
	rmax = 0.0
	FLAG = .false.
	DO J=1,NPNT
	  IF (AX(J) .ge. min(SLIM,FLIM) 
	1	.and. AX(J) .le. max(SLIM,FLIM) .and. .not. FLAG) THEN
	    FLAG = .true.
C	    rmin = A(J)
	    rmax = A(J)
	  ELSEIF (AX(J) .ge. min(SLIM,FLIM) .and. AX(J) .le. 
	1	max(SLIM,FLIM)) THEN
C	    rmin = MIN(rmin,A(J))
	    rmax = MAX(rmax,A(J))
	  ENDIF
	ENDDO
C no data to plot in data
	IF (npnt .gt. 0 .and. .not. flag) Then
	  write (lo,'(A)') 
	1	' There are no data points in region. Continue? (Y/[N]): '
	  read(li,'(A1)',end=999,err=100) ians
	  XLIMFL = .false.
	  if (ians .ne. 'y' .and. ians .ne. 'Y') goto 100
	ENDIF

20	FORMAT ('$Enter magnification factor for ',a,
	1	' [Default=',F7.3']: ')
	FLAG = .TRUE.
	IF (CLI$PRESENT('PEAKSCALE'))
	1	FLAG = GET_FNUMBER('PEAKSCALE',peakscl)
	IF (FLAG) THEN
	  write (lo,'(/1x,2A)') 
	1	'Peak magnification: 1.0 - full scale; 2.0 - x 2;',
	2	' 0.0 - all peaks to full scale'
27	  WRITE (LO,20) 'peaks',peakscl
	  READ (LI,'(Q,f10.0)',end=999,err=27) I,x1
	  IF (I.ne.0) peakscl = x1
	ENDIF

	FLAG = .TRUE.
	IF (CLI$PRESENT('DATASCALE'))
	1	FLAG = GET_FNUMBER('DATASCALE',datscl)
	IF (FLAG .and. fil2 .gt. 0) THEN
	  write (lo,'(/1x,2A)') 
	1	'Data magnification: 1.0 - full scale; 2.0 - x 2;',
	2	' 0.0 - d not plot data'
	  WRITE (LO,20) 'data',datscl
	  READ (LI,'(Q,f10.0)',end=999,err=27) I,x1
	  IF (I.ne.0) datscl = x1
	ELSEIF (fil2 .le. 0) THEN
	  datscl = 0.0
	ENDIF

	FLAG = .TRUE.
	IF (CLI$PRESENT('WIDTH'))
	1	FLAG = GET_FNUMBER('WIDTH',pwidth)
	IF (FLAG) THEN
28	  WRITE (LO,'(/,2a,/,A,f6.3,A)') 
	1	'$Peaks more closely spaced than PWIDTH are considered ',
	1	'to be overlapped',
	1	'$Enter PWIDTH [Default=',pover,' degrees]: '
	  READ (LI,'(Q,f10.0)',end=999,err=28) I,x1
	  IF (I.NE.0) pover = x1
	ENDIF
C----------------------------------------------------------------------
C get the symmetry information
	IF (PROMPT) THEN
	  WRITE (lo,'(/2a)') ' SELECT SYMMETRY EXTINCTIONS TO TEST'
	  CALL GETEXTN(IEXTCD,lo,li)
	ENDIF

C batch mode -- produce a labeled plot and exit
	IF (.NOT. PROMPT) THEN
	  HARDF = .true.
	  curflag = .false.
	ENDIF
C----------------------------------------------------------------------
200	IF (HARDF) then
	  CALL OPNHD(lo,li)
	ELSE
	  CALL BGRAF(ICRT,lo,li)
          CALL PGQINF ('CURSOR', ID, LN)
	  curflag = .false.
	  IF (ID .EQ. 'Y') curflag = .true.
	ENDIF
C get maximum color index
	CALL PGQCOL(I,MAXCOL)
	if (maxcol .lt. 3) THEN 
	  colflag = .false.
	  maxcol = 4
	ELSE
	  colflag = .true.
	ENDIF

C set up plot size
	chars = 1.1
	charss = chars/40.
	call pgsch(chars)

C overall plot borders
	Xleft = 3.5*charss
	Xright = 0.5*charss
	ybot = 4.*charss
	YTOP = 3.*charss
	CALL PGVPORT(Xleft,1.-Xright,ybot,0.8)
C--------------------------------------------------------------------
C--------------------------------------------------------------------
	IF (peakscl .gt. 0) THEN
	  CALL PGWINDOW(SLIM,FLIM,0.0,100.0/peakscl)
	  CALL PGBOX('bnist',0.0,0,'bcnvist',0.0,0)
	  CALL PGWINDOW(SLIM,FLIM,0.0,ymax/peakscl)
	  ylim = 1.02*ymax/peakscl
	ELSEIF (fil2 .gt. 0 .and. datscl .gt. 0.0) THEN
	  CALL PGWINDOW(SLIM,FLIM,0.0,100.0/DATSCL)
	  CALL PGBOX('bnist',0.0,0,'bcnvist',0.0,0)
	  CALL PGWINDOW(SLIM,FLIM,0.0,1.0)
	  ylim = 1.02
	ELSE
	  CALL PGWINDOW(SLIM,FLIM,0.0,1.0)
	  CALL PGBOX('bnist',0.0,0,'bc',0.0,0)
	  ylim = 1.02
	ENDIF

	if (wavel .LE. 0.0) then
	  lbl = '2\gH (degrees)'
	else
	  write(lbl,'(A,f7.5)') '2\gH (degrees), \gl =',wavel
	endif
	CALL PGLABEL(lbl,' ',' ')
C----------------------------------------------------------------------
C Plot the non-extinct peaks 
	DO II=1,NPK
	  if (ppos(ii) .ge. MIN(SLIM,FLIM) .and. 
	1		ppos(II) .le. MAX(SLIM,FLIM)) THEN
	    ICOL = PCOLOR(FIL1)
C test for extinctions
	    NH = IH(pnum(ii),FIL1)
	    NK = IK(pnum(ii),FIL1)
	    NL = IL(pnum(ii),FIL1)
	    EXTFLAG = TSTEXTN(NH,NK,NL,IEXTCD)
	    IF (.NOT. EXTFLAG) THEN
	      IF (colflag) THEN 
	        call PGSCI(ICOL)
	      ELSE
	        call PGSLS(icol)
	      ENDIF
	      call PGMOVE(ppos(II),0.0)
	      yt = PKHT(pnum(II),fil1)
	      IF (peakscl .le. 0) YT = 1.0
	      call PGDRAW(ppos(II),yt)
	    ENDIF
	  ENDIF
	ENDDO
C----------------------------------------------------------------------
C Plot the extinct peaks 
	xmar = -999.
	xmar1 = -999.
	DO II=1,NPK
	  if (ppos(ii) .ge. MIN(SLIM,FLIM) .and. 
	1		ppos(II) .le. MAX(SLIM,FLIM)) THEN
C test for extinctions
	    NH = IH(pnum(ii),FIL1)
	    NK = IK(pnum(ii),FIL1)
	    NL = IL(pnum(ii),FIL1)
	    EXTFLAG = TSTEXTN(NH,NK,NL,IEXTCD)
	    IF (EXTFLAG) THEN
	      ICOL = MOD(PCOLOR(FIL1), maxcol) + 1
C reflection is extinct, is there a non-extinct reflection nearby?
	      DO III=ii+1,npk
	        if (ABS(ppos(iii)-ppos(ii)).le.POVER) THEN
		  NH = IH(pnum(iii),FIL1)
		  NK = IK(pnum(iii),FIL1)
		  NL = IL(pnum(iii),FIL1)
		  IF (.not. TSTEXTN(NH,NK,NL,IEXTCD)) THEN
		    ICOL = MOD(PCOLOR(FIL1)+1, maxcol) + 1
		    goto 127
		  ENDIF
		ELSE
		  goto 126
	        ENDIF
	      ENDDO
C reflection is extinct, is there a non-extinct reflection nearby?
126	      DO III=ii-1,1,-1
	        if (ABS(ppos(iii)-ppos(ii)).le.POVER) THEN
		  NH = IH(pnum(iii),FIL1)
		  NK = IK(pnum(iii),FIL1)
		  NL = IL(pnum(iii),FIL1)
		  IF (.not. TSTEXTN(NH,NK,NL,IEXTCD)) THEN
		    ICOL = MOD(PCOLOR(FIL1)+1, maxcol) + 1
		    goto 127
		  ENDIF
		ELSE
		  goto 127
	        ENDIF
	      ENDDO
127	      IF (colflag) THEN 
	        call PGSCI(ICOL)
	      ELSE
	        call PGSLS(ICOL)
	      ENDIF
	      call PGMOVE(ppos(II),0.0)
	      yt = PKHT(pnum(II),fil1)
	      IF (peakscl .le. 0) YT = 1.0
	      call PGDRAW(ppos(II),yt)
	    ENDIF
	  ENDIF
	ENDDO
C----------------------------------------------------------------------
C create and plot HKL labels
	if (HARDF) THEN
	  call pgsch(chars/2.)
	  DO II=1,NPK
	    if (ppos(ii) .ge. MIN(SLIM,FLIM) .and. 
	1		ppos(II) .le. MAX(SLIM,FLIM)) THEN
C test for extinctions
	      NH = IH(pnum(ii),FIL1)
	      NK = IK(pnum(ii),FIL1)
	      NL = IL(pnum(ii),FIL1)
	      EXTFLAG = TSTEXTN(NH,NK,NL,IEXTCD)
	      ICOL = PCOLOR(FIL1)
	      IF (EXTFLAG) ICOL = MOD(PCOLOR(FIL1), maxcol) + 1
	      IF (colflag) THEN
	        call PGSCI(ICOL)
	      ELSEIF (EXTFLAG) THEN
	        call PGSLW(3)
	      ELSE
	        call PGSLW(1)
              ENDIF
	      CALL GENHKL(pklbl,ln,IH(pnum(ii),FIL1),
	1		IK(pnum(ii),FIL1),IL(pnum(ii),FIL1))
C since PGLEN does not give the correct height, use the length of a square
C as reference for the height; use also to convert units
	      CALL PGLEN(4,'\(254)',xLN,yLN)
	      CALL PGLEN(4,PKlbl(:ln),xLN1,yLN1)
	      IF (ppos(II)-1.05*xln/2 .gt. xmar .or. 
	1	ppos(II)-1.05*xln/2 .gt. xmar1) THEN
	        xmar1 = ppos(II) + xln/2.
	        ymar = ylim
	      ENDIF
C print label @ [ppos(II),ymar] top justified and centered on PPOS(II)
	      call PGPTEXT(ppos(II)+xln/2,ymar,90.,0.0,PKLBL(:ln))
	      xmar = ppos(II) + xln/2.
	      ymar = ymar + (xln1/xln + .3)*yln
	    ENDIF
	  ENDDO
	ENDIF
C----------------------------------------------------------------------
C----------------------------------------------------------------------
	call PGSLW(1)
	call pgsch(chars)
        call PGSLS(1)
	IF (fil2 .gt. 0 .and. datscl .gt. 0.0) THEN
C Plot the observed data
	  CALL PGWINDOW(SLIM,FLIM,0.0,rmax/DATSCL)
	  call PGSCI(PCOLOR(FIL2))
	  call pgline(npnt,ax,a)
	  if (datscl .ne. peakscl .and. peakscl .ne. 0.) THEN
	    write (lbl,'(A,f6.2)') 'Data \(2235)',datscl/peakscl
	    call pgmtext('T',-4.5,0.98,1.0,lbl)
	  ENDIF
	ENDIF
	IF (HARDF) then
	  call pgsch(chars/2.)
	  ICOL = PCOLOR(FIL1)
	  call PGSCI(ICOL)
	  call PGMTXT ('L', 6.0, .25, 0.5, 'observed')
	  ICOL = MOD(PCOLOR(FIL1), maxcol) + 1
	  call PGSCI(ICOL)
	  call PGMTXT ('L', 6.0, .5, 0.5, 'extinct')
	  ICOL = MOD(PCOLOR(FIL1)+1, maxcol) + 1
	  call PGSCI(ICOL)
	  call PGMTXT ('L', 6.0, .75, 0.5, 'overlapped')
	ELSE
	  call pgsch(chars/1.3)
	  ICOL = PCOLOR(FIL1)
	  call PGSCI(ICOL)
	  call PGMTXT ('L', 5.0, .25, 0.5, 'obs.')
	  ICOL = MOD(PCOLOR(FIL1), maxcol) + 1
	  call PGSCI(ICOL)
	  call PGMTXT ('L', 5.0, .5, 0.5, 'ext.')
	  ICOL = MOD(PCOLOR(FIL1)+1, maxcol) + 1
	  call PGSCI(ICOL)
	  call PGMTXT ('L', 5.0, .75, 0.5, 'over')
	ENDIF
	call PGSCI(1)
	call pgsch(chars)

	IF (CURFLAG .AND. .NOT. HARDF) then
	  CALL PGVPORT(Xleft,1.-Xright,ybot,1.)
	  CALL PGMTXT('T',-.9,0.0,0.05,
	1		'Commands: L, A, R, S, M, P, H, N, E, ?')
	  CALL PGVPORT(Xleft,1.-Xright,ybot,0.8)
	  CALL PGWINDOW(SLIM,FLIM,0.0,1.0)
	  ylim = 1.02
	  xmar = -999.
	  xmar1 = -999.

500	  CALL PGCURSE(X1,Y1,ID)
C---------
501	  IF (ID.EQ.'?') THEN 
	    CALL EGRAF(ICRT,lo,li)
	    CALL TERASE(ICRT,lo,li)
	    WRITE (LO,104)
104	    FORMAT(' Press a key for the following actions: ')
	    WRITE (LO,'(4x,A)') '"L" label reflections near cursor',
	1	'"A" label all reflections',
	1	'"R" Rescale X or Y axes',
	1	'"S" change symmetry element(s)',
	1	'"M" change magnification factors',
	2	'"P" change PWIDTH','"H" Generate Hardcopy',
	3	'"N" New data file','"E" Exit'
	    write(lo,'(/a)') '$Enter a command: '
	    read (li,'(A)',err=999) ID
	    GOTO 501
C---------
	  ELSEIF (ID.EQ.'L' .or. ID.EQ.'l') THEN 
C label the peaks 
	    DO II=1,NPK
	      ICOL = PCOLOR(FIL1)
	      if (ABS(x1-ppos(ii)).le. ABS(FLIM-SLIM)/50.) THEN
C test for extinctions
	        NH = IH(pnum(ii),FIL1)
	        NK = IK(pnum(ii),FIL1)
	        NL = IL(pnum(ii),FIL1)
	        EXTFLAG = TSTEXTN(NH,NK,NL,IEXTCD)
C create and plot HKL label
	        call pgsch(chars/1.2)
		CALL GENHKL(pklbl,ln,IH(pnum(ii),FIL1),
	1		IK(pnum(ii),FIL1),IL(pnum(ii),FIL1))
	        IF (EXTFLAG .and. colflag) THEN
	          ICOL = MOD(PCOLOR(FIL1), maxcol) + 1
	        ELSEIF (EXTFLAG) THEN
	          call PGSLW(3)
	        ENDIF
	        IF (colflag) call PGSCI(ICOL)
C since PGLEN does not give the correct height, use the length of a square
C as reference for the height; use also to convert units
	        CALL PGLEN(4,'\(254)',xLN,yLN)
	        CALL PGLEN(4,PKlbl(:ln),xLN1,yLN1)
	        IF (ppos(II)-1.05*xln/2 .gt. xmar 
	1		.or. ppos(II)+xln .lt. xmar
	1		.or. ppos(II)-1.05*xln/2 .gt. xmar1) THEN
		  xmar1 = ppos(II) + xln/2.
		  ymar = ylim
		ENDIF
C print label @ [ppos(II),ymar] top justified and centered on PPOS(II)
		call PGPTEXT(ppos(II)+xln/2,ymar,90.,0.0,PKLBL(:ln))
		xmar = ppos(II) + xln/2.
		ymar = ymar + (xln1/xln + .3)*yln
		call PGSLW(1)
	      ENDIF
	    ENDDO
	    call pgsch(chars)
	    IF (colflag) call PGSCI(1)
C---------
	  ELSEIF (ID.EQ.'A' .or. ID.EQ.'a') THEN 
C label the peaks 
	    DO II=1,NPK
	      ICOL = PCOLOR(FIL1)
	      if (ppos(ii) .ge. MIN(SLIM,FLIM) .and. 
	1		ppos(II) .le. MAX(SLIM,FLIM)) THEN
C test for extinctions
	        NH = IH(pnum(ii),FIL1)
	        NK = IK(pnum(ii),FIL1)
	        NL = IL(pnum(ii),FIL1)
	        EXTFLAG = TSTEXTN(NH,NK,NL,IEXTCD)
C create and plot HKL label
	        call pgsch(chars/1.4)
		CALL GENHKL(pklbl,ln,IH(pnum(ii),FIL1),
	1		IK(pnum(ii),FIL1),IL(pnum(ii),FIL1))
	        IF (EXTFLAG .and. colflag) THEN
	          ICOL = MOD(PCOLOR(FIL1), maxcol) + 1
	        ELSEIF (EXTFLAG) THEN
	          call PGSLW(3)
	        ENDIF
	        IF (colflag) call PGSCI(ICOL)
C since PGLEN does not give the correct height, use the length of a square
C as reference for the height; use also to convert units
	        CALL PGLEN(4,'\(254)',xLN,yLN)
	        CALL PGLEN(4,PKlbl(:ln),xLN1,yLN1)
	        IF (ppos(II)-1.05*xln/2 .gt. xmar 
	1		.or. ppos(II)+xln .lt. xmar
	1		.or. ppos(II)-1.05*xln/2 .gt. xmar1) THEN
		  xmar1 = ppos(II) + xln/2.
		  ymar = ylim
		ENDIF
C print label @ [ppos(II),ymar] top justified and centered on PPOS(II)
		call PGPTEXT(ppos(II)+xln/2,ymar,90.,0.0,PKLBL(:ln))
		xmar = ppos(II) + xln/2.
		ymar = ymar + (xln1/xln + .3)*yln
		call PGSLW(1)
	      ENDIF
	    ENDDO
	    call pgsch(chars)
	    IF (colflag) call PGSCI(1)
C---------
	  ELSEIF (ID.EQ.'S' .or. ID.EQ.'s') THEN 
	    CALL EGRAF(ICRT,lo,li)
	    CALL TERASE(ICRT,lo,li)
	    WRITE (lo,'(/2a)') ' SELECT SYMMETRY EXTINCTIONS TO TEST'
	    CALL GETEXTN(IEXTCD,lo,li)
	    goto 200
C---------
	  ELSEIF (ID.EQ.'R' .or. ID.EQ.'r') THEN 
	    CALL EGRAF(ICRT,lo,li)
	    CALL TERASE(ICRT,lo,li)
210	    WRITE (LO,'(A,2f12.2)') ' Range of data:  ',xmin,xmax
	    WRITE (LO,'(A,2f12.2)') ' Range of peaks: ',ppos(1),ppos(npk)
	    WRITE (LO,10) 'lower','x-axis',slim
	    READ (LI,'(Q,f10.0)',end=999,err=210) I,x1
	    IF (I.NE.0) SLIM = x1

	    WRITE (LO,10) 'upper','x-axis',flim
	    READ (LI,'(Q,f10.0)',end=999,err=210) I,x1
	    IF (I.NE.0) FLIM=x1
C find the maximum and minimum intensity for the peaks
	    FLAG = .false.
	    DO J=1,NPK
	      yt = PKHT(pnum(J),fil1)
	      IF (ppos(J) .ge. min(SLIM,FLIM) 
	1	.and. ppos(J) .le. max(SLIM,FLIM) .and. .not. FLAG) THEN
	        FLAG = .true.
	        ymin = yt
	        ymax = yt
	      ELSEIF (ppos(J) .ge. min(SLIM,FLIM) 
	1	.and. ppos(J) .le. max(SLIM,FLIM)) THEN
	        ymin = MIN(ymin,yt)
	        ymax = MAX(ymax,yt)
	      ENDIF
	    ENDDO
C no peaks to plot -- error
	    IF (.not. flag) THEN
	      write (lo,'(A)') 'Warning -- no peaks to plot!'
	      goto 210  
	    ENDIF

C find the maximum and minimum intensity in the raw data
	    rmax = 0.0
	    FLAG = .false.
	    DO J=1,NPNT
	      IF (AX(J) .ge. min(SLIM,FLIM) 
	1	.and. AX(J) .le. max(SLIM,FLIM) .and. .not. FLAG) THEN
	        FLAG = .true.
C	        rmin = A(J)
	        rmax = A(J)
	      ELSEIF (AX(J) .ge. min(SLIM,FLIM) .and. AX(J) .le. 
	1	max(SLIM,FLIM)) THEN
C	        rmin = MIN(rmin,A(J))
	        rmax = MAX(rmax,A(J))
	      ENDIF
	    ENDDO
C no data to plot in data
	    IF (npnt .gt. 0 .and. .not. flag) Then
	      write (lo,'(A)') 
	1	' There are no data points in region. Continue? (Y/[N]): '
	      read(li,'(A1)',end=999,err=210) ians
	      if (ians .ne. 'y' .and. ians .ne. 'Y') goto 210
	    ENDIF
	    GOTO 200
C---------
	  ELSEIF (ID.EQ.'M' .or. ID.EQ.'m') THEN 
	    CALL EGRAF(ICRT,lo,li)
	    CALL TERASE(ICRT,lo,li)
	    write (lo,'(/1x,2A)') 
	1	'Peak magnification: 1.0 - full scale; 2.0 - x 2;',
	2	' 0.0 - all peaks to full scale'
227	    WRITE (LO,20) 'peaks',peakscl
	    READ (LI,'(Q,f10.0)',end=999,err=227) I,x1
	    IF (I.ne.0) peakscl = x1

	    IF (fil2 .gt. 0) THEN
	      write (lo,'(/1x,2A)') 
	1	'Data magnification: 1.0 - full scale; 2.0 - x 2;',
	2	' 0.0 - d not plot data'
	      WRITE (LO,20) 'data',datscl
	      READ (LI,'(Q,f10.0)',end=999,err=227) I,x1
	      IF (I.ne.0) datscl = x1
	    ELSE
	      datscl = 0.0
	    ENDIF
	    GOTO 200
C---------
	  ELSEIF (ID.EQ.'P' .or. ID.EQ.'p') THEN 
	    CALL EGRAF(ICRT,lo,li)
	    CALL TERASE(ICRT,lo,li)
228	    WRITE (LO,'(/,2a,/,A,f6.3,A)') 
	1	'$Peaks more closely spaced than PWIDTH are considered ',
	1	'to be overlapped',
	1	'$Enter PWIDTH [Default=',pover,' degrees]: '
	    READ (LI,'(Q,f10.0)',end=999,err=228) I,x1
	    IF (I.NE.0) pover = x1
	    GOTO 200
C---------
	  ELSEIF (ID.EQ.'H' .or. ID.EQ.'h') THEN 
	    CALL EGRAF(ICRT,lo,li)
	    hardf = .true.
	    goto 200
C---------
	  ELSEIF (ID.EQ.'N' .or. ID.EQ.'n') THEN 
	    CALL EGRAF(ICRT,lo,li)
	    CALL TERASE(ICRT,lo,li)
	    WRITE (LO,'(/,a)') '$Enter file number for data: '
	    read (li,'(I3)',err=999) fil2
	    IF (fil2 .le. 0 .or. fil2 .gt. MFILE .or. 
	1	NPOINT(fil2) .le. 0) THEN
	      fil2 = 0
	      npnt = 0
	      goto 200
	    ENDIF
C convert raw data find the maximum and minimum two-theta value in the raw data
	    IF (WAVEL .GT. 0.0 .and. WAVE(fil2) .ne. WAVEL) THEN
	      call XYCONV(BX(1,fil2),B(1,fil2),FXTYP(fil2),NPOINT(fil2)
	1	,WAVE(fil2),AX,A,XTYP_TT,npnt,wavel,.false.,*23)
	    ELSE
	      DO J=1,NPOINT(fil2)
	        AX(j) = BX(J,fil2)
	        A(j)  = B(J,fil2)
	      ENDDO
	      npnt = NPOINT(fil2)
	    ENDIF
	    IF (npnt .gt. 0) THEN
	      XMIN = ax(1)
	      XMAX = ax(1)
	      DO J=2,npnt
	        XMIN = MIN(XMIN,ax(J))
	        XMAX = MAX(XMAX,ax(J))
	      ENDDO
	    else
	      fil2 = 0
	      npnt = 0
	      goto 200
	    ENDIF
	    SLIM = xmin
	    FLIM = min(xmax,ppos(npk)+.1)
	    goto 210
C---------
	  ELSEIF (ID.EQ.'E' .or. ID.EQ.'e') THEN 
	    CALL EGRAF(ICRT,lo,li)
	    goto 999
C----------------------------------------------------------------------
	  ENDIF
	  GOTO 500

	ELSEIF (.NOT. HARDF) then
	  WRITE(LO,79)
79	  FORMAT ('$REPEAT PLOT ON HARDCOPY? (Y/[N]): ')
	  ians = 'N'
	  READ (LI,'(a1)',end=998) IANS
C close the graphics terminal 
998	  CALL EGRAF(ICRT,lo,li)
	  IF(IANS.EQ.'Y' .or. IANS.EQ.'y') THEN 
	    hardf = .true.
	    goto 200
	  ENDIF
	ELSEIF (CURFLAG) then
	  hardf = .false.
C close hardcopy graphics device and reopen terminal
	  CALL CLHD(lo,li)
	  write (lo,'(A)') '$Return to main menu? (Y/[N]): '
	  READ (li,'(A1)',err=999) ians
	  IF(IANS.EQ.'Y' .or. IANS.EQ.'y') goto 999
	  goto 200
	ELSE
	  hardf = .false.
C close hardcopy graphics device and possibly restart
	  CALL CLHD(lo,li)
	  WRITE(LO,'(A)') '$Replot? (Y/[N]): '
	  READ (LI,'(a1)',end=997) IANS
	  ians = 'N'
C close the graphics terminal 
997	  CALL EGRAF(ICRT,lo,li)
	  IF(IANS.EQ.'Y' .or. IANS.EQ.'y') goto 100
	ENDIF

999	RETURN
C no peaks to plot -- error
22	write (lo,'(A)') ' Error -- unable to convert peaks'
	CALL PS_PAUSE(PROMPT)
	return
	END
C---------------------------------------------------------------------------
	SUBROUTINE GENHKL(pklbl,ln,IH,IK,IL)
	CHARACTER*(*) pklbl
	INTEGER ln
	BYTE IH, IK, IL
C---------------------------------------------------------------------------
	IF (IH.ge.0 .and. IH.le.9 .and. IK.ge.0 .and. IK.le.9
	1	.and. IL.ge.0 .and. IL.le.9) THEN
	  write(pklbl,'(a1,3i1,a1)') '(',IH,IK,IL,')'
	ELSE
	  write(pklbl,'(a1,3i5,a1)') '(',IH,IK,IL,')'
	ENDIF
	ln = lench(pklbl)
	do J=ln-1,1,-1
	  IF (pklbl(j:j+1) .eq. '  ' .or. pklbl(j:j+1) .eq. ' -') THEN
	    pklbl(j:ln-1) = pklbl(j+1:ln)
	    ln = ln - 1
	  ENDIF
	ENDDO
	RETURN
	END
