C==========================================================================
	SUBROUTINE quickPLT(ltmp,NPH,dname,sname,wavel)
C==========================================================================
C	PLOT OUT NGCARD PDF CARDS AS STICK DIAGRAMS
C
C NPH is the total number of entries
	INTEGER ltmp,NPH
	character*(*) sname,dname
	REAL WAVEL
C==========================================================================
	include '[-.shared]jcpds.parms'
	include 'SEARCH.cmn'
	include 'SEARCH.par'
	include '[-.shared]flabel.common'
C up to 30 cards/page
	INTEGER*4 NAMREC(30),DIREC(30),ISEQ(30),JCARD(30),ICRD(30)
	DIMENSION dsp(200),xt(2),yt(2)
	INTEGER*2 INT(200)
	CHARACTER*1 QM,name*60
	REAL PEAK
	CHARACTER str1*8,str2*8,lbl*32
	BYTE ians,hardf
	INTEGER*2 i2
	INTEGER ngcard/4/
	INTEGER icol/3/
	LOGICAL FLAG,RAWF,EXTRAF
	LOGICAL EXRtst,PDFTOD,DTOTT,TTtoD,DTOPDF
	integer MAXCOL
	LOGICAL colflag

	REWIND(UNIT=LTMP)
C set up plot size
	chars = 1.1
	charss = chars/40.
C overall plot borders
	YTOP = 0.
	ybot = 5.0*charss
	ybot1 = 1.5*charss
	Xleft = 2.5*charss
	Xright = 2.75*charss
C individual plot borders
	ymart = 0.0*charss
	ymarb = 0.0*charss
	if (wavel .LE. 0.0) then
	  lbl = 'd (\A)'
	else
	  lbl = '2\gH (degrees)'
	endif

C NGCARD is the number of JCPDS cards per page/screen
100	write(lo,'(a,i2,a)') 
	1	'$Maximum cards per page (default=',ngcard,'): '
	read(li,'(q,i)',end=999,err=100) k,j
	if (k .ne. 0) ngcard = j
C RAWF   is TRUE plot the raw data
C	     FALSE plot the observed peaks
	IF (NPTS .eq. 0) then 
	  RAWF = .FALSE.
	ELSEIF (RAWF) THEN
	  write(lo,'(a)') 
	1	'$Plot observed diffractogram and "hits" ([Y]/N): '
	  read(li,'(a1)',end=999) ians
	  IF (IANS .eq. 'N' .or. IANS .eq. 'n') RAWF = .FALSE.
	ELSE
	  write(lo,'(a)') 
	1	'$Plot observed peak positions and "hits" ([Y]/N): '
	  read(li,'(a1)',end=999) ians
	  IF (IANS .eq. 'N' .or. IANS .eq. 'n') RAWF = .TRUE.
	ENDIF
C EXTRAF is TRUE the observed peaks/data are in a separate box
C	     FALSE the observed peaks/data are superimposed in every
	IF (RAWF) THEN
	  write(lo,'(a)') 
	1	'$Superimpose diffractogram and each "hit" ([Y]/N): '
	  read(li,'(a1)',end=999) ians
	  EXTRAF = .FALSE.
	  IF (IANS .eq. 'N' .or. IANS .eq. 'n') EXTRAF = .TRUE.
	ELSE
	  write(lo,'(a)') 
	1	'$Superimpose observed peaks and each "hit" (Y/[N]): '
	  read(li,'(a1)',end=999) ians
	  EXTRAF = .TRUE.
	  IF (IANS .eq. 'Y' .or. IANS .eq. 'y') EXTRAF = .FALSE.
	ENDIF
!	IF (.not. EXTRAF) THEN
	  write(lo,'(a,i3,a)') 
	1	'$Enter color code for observed data/peaks (default=',
	1	icol,'): '
	  read(li,'(q,i)',end=999,err=100) k,j
	  if (k .ne. 0) icol = j
!	ENDIF
C set plotting limits
	amax = 31416
	amin = 31415
	DO I2=-31416,31416
	  if (.not. EXRtst(extbl,i2)) THEN
	    AMIN = I2 - 100
	    goto 701
	  ENDIF
	ENDDO
701	DO I2=31416,amin,-1
	  if (.not. EXRtst(extbl,i2)) THEN
	    AMAX = I2 + 100
	    goto 702
	  ENDIF
	ENDDO

702	FLAG = PDFTOD(AMAX,DMIN)
	FLAG = PDFTOD(AMIN,DMAX)
	IF (wavel .ne. 0) THEN
C convert the from d-spaces to an angle, if appropriate
	   call DATCONV(BX(1,1),fxtyp(1),npts,wave(1),
	1	BX(1,1),XTYP_TT,npts,wavel,*997)
	  fxtyp(1) = xtyp_tt
	  wave(1) = wavel
	  FLAG = DTOTT(dmin,xhigh,wavel)
	  FLAG = DTOTT(dmax,xlow,wavel)
	ELSE
	  xlow = DMIN
	  xhigh = DMAX
	ENDIF
	write(lo,'(a,f7.3,a)') 
	1	'$Enter lower plotting limit (default=',xlow,'): '
	read(li,'(q,f10.0)',end=999,err=100) k,x1
	if (k .ne. 0) xlow = x1
	write(lo,'(a,f7.3,a)') 
	1	'$Enter high plotting limit (default=',xhigh,'): '
	read(li,'(q,f10.0)',end=999,err=100) k,x1
	if (k .ne. 0) xhigh = x1

	icrdt = 0
	DO IPHASE=1,NPH,NGCARD
C NBOX   is the number of boxes per page/screen for current page
	  nbox = min(1+NPH-IPHASE,NGCARD)
	  IF (EXTRAF) nbox = nbox + 1
C get the entry numbers to be plotted
	  DO I=1,nbox
	    IF (I .ne. 1 .or. .not. EXTRAF) THEN
	      read(ltmp,end=996) JCARD(I),Q,jmiss,jmatch,NDSINT,FOMI,
	1	FOMA,FOMF,avei,namrec(I),ISEQ(I),DIREC(I)
	      icrdt = icrdt + 1
	      icrd(I) = icrdt
	    ENDIF
	  ENDDO

	  HARDF = .FALSE.
21	  IF (HARDF) then
	    CALL OPNHD(lo,li)
	  ELSE
	    CALL BGRAF(ICRT,lo,li)
	  ENDIF
C get maximum color index
	  CALL PGQCOL(I,MAXCOL)
	  if (maxcol .lt. 3) THEN 
	    colflag = .false.
	    maxcol = 4
	  ELSE
	    colflag = .true.
	  ENDIF
	  call pgsch(chars)
C draw outer box
	  CALL PGVPORT(Xleft,1.-Xright,yBOT,1.-YTOP)
	  CALL PGLABEL(lbl,' ',' ')
	  CALL PGBOX('bc',0.0,0,'bc',0.0,0)
C size of each box
	  ysize = (1. - ytop - ybot) / (1.*nbox)
C--------------------------------------------------------------------
C--------------------------------------------------------------------
	  ylow = ybot - ybot1
	  yhgh = ybot
	  CALL PGVPORT(Xleft,1.-Xright,ylow,yhgh)
	  if (wavel .LE. 0.0) then
	    CALL PGWINDOW(xhigh,xlow,0.0,1.0)
	  else
	    CALL PGWINDOW(xlow,xhigh,0.0,1.0)
	  endif
	  CALL PGBOX('bnist',0.0,0,'bc',0,0)
C----------------------------------------------------------------------
C  plot the excluded regions
C----------------------------------------------------------------------
	  if (colflag) call pgsci(2)
	  call pgslw(3)
C    Find end and the begining range
	  amin = -31416
	  amax = 31416
	  do i=amin,amax
	    if (EXRtst(extbl,i)) then 
	      amin = i
	    else
	      goto 421
	    endif
	  enddo
421	  do i=amax,amin,-1
	    if (EXRtst(extbl,i)) then 
	      amax = i
	    else
	      goto 422
	    endif
	  enddo
422	  flag = pdftod(amin,dmax)
	  if (.not. flag) then
	    dmax = 1.e10
	    x = 0.0
	  elseIF (wavel .gt. 0) then
	    IF (.not. DTOTT(DMAX,X,wavel)) x = 180.0
	  ENDIF

	  flag = pdftod(amax,dmin)
	  if (.not. flag) then
	    dmin = 1.e10
	    x1 = 0.0
	  elseIF (wavel .gt. 0) then
	    IF (.not. DTOTT(DMIN,X1,wavel)) x1 = 180.0
	  ENDIF

	  IF (wavel .gt. 0) then
	    call pgmove(0.,.333)
	    call pgdraw(x,.333)
	    call pgmove(180.,.333)
	    call pgdraw(x1,.333)
	  ELSE
	    call pgmove(0.,.333)
	    call pgdraw(dmin,.333)
	    call pgmove(9999.,.333)
	    call pgdraw(dmax,.333)
	  ENDIF


430	  do i=amin+1,amax-1
	    if (EXRtst(extbl,i)) then 
	      amin = i
	      do j=amin+1,amax-1
		if (.not. EXRtst(extbl,j)) then 
		  amin = j
		  goto 431
		endif
	      enddo
431	      flag = pdftod(i,dmax)
	      flag = pdftod(j,dmin)
	      IF (wavel .gt. 0) then
		IF (.not. DTOTT(DMAX,dmax,wavel)) dmax = 0.0
		IF (.not. DTOTT(DMIN,dmin,wavel)) dmin = 180.
	      ENDIF
	      call pgmove(dmax,.333)
	      call pgdraw(dmin,.333)
	      goto 430
	    endif
	  enddo
	  call pgslw(1)
	  call pgsch(chars/1.5)
	  IF (hardf) THEN
	    call pgmtext('RV',0.5,0.333,0.0,'excl')
	  ELSE
	    call pgmtext('RV',0.5,0.333,0.0,'ex')
	  ENDIF
C----------------------------------------------------------------------
C  plot the null regions
C----------------------------------------------------------------------
	  call pgslw(3)
	  if (colflag) call pgsci(3)
	  CALL SETNULL
	  N = 0
200	  DO j=N+1,N_REGIONS
	    IF (NULLREG(j)) then
	      k1 = j
	      j1 = j 
	      N = j
	      DO k=J+1,N_REGIONS
		N = K
		IF (.not. NULLREG(K)) GOTO 201
		j1 = k
	      ENDDO
201	      FLAG = INDTOD(k1,j1,DMAX,DMIN,N_REGIONS)
	      if (wavel .gt. 0.0) THEN 
	        flag = dtott(dmin,dmin,wavel)
	        IF (.not. FLAG) dmin = 180.
	        x1 = 180.
	        flag = dtott(dmax,dmax,wavel)
	        IF (.not. FLAG) dmax = 0.
	      ENDIF
	      call pgmove(dmax,.667)
	      call pgdraw(dmin,.667)
	      goto 200
	    ENDIF
	  ENDDO
	  call pgslw(1)
	  call pgsch(chars/1.5)
	  IF (hardf) THEN
	    call pgmtext('RV',0.5,0.667,0.0,'null')
	  ELSE
	    call pgmtext('RV',0.5,0.667,0.0,'nu')
	  ENDIF
C----------------------------------------------------------------------
C loop for each box
	  call pgsch(chars)
	  call pgslw(1)
	  call pgsci(1)
	  DO 500 I=1,nbox
C set up plot limits 
	    ylow = ybot + ymarb + (nbox-i)*ysize
	    yhgh = ybot - ymart + (nbox-i+1.)*ysize
	    CALL PGVPORT(Xleft,1.-Xright,ylow,yhgh)
C scale, draw and relabel the box
	    if (wavel .LE. 0.0) then
	      CALL PGWINDOW(xhigh,xlow,0.0,99.9)
	    else
	      CALL PGWINDOW(xlow,xhigh,0.0,99.9)
	    endif
	    CALL PGBOX('bist',0.0,0,'bvnist',25.0,3)
	    call pgsch(1.0)
	    call pgsci(1)
	    call pgsch(chars)
	    IF (RAWF .and. (I .eq. 1 .or. .not. EXTRAF)) THEN 
C Plot the observed data
	      IF (colflag) call pgsci(icol)
	      Ymax = max(B(1,1),.00001)
	      do ii=2,npts
	        ymax = max(ymax,b(ii,1))
	      enddo
	      if (wavel .LE. 0.0) then
	        CALL PGWINDOW(xhigh,xlow,0.0,ymax)
	      else
	        CALL PGWINDOW(xlow,xhigh,0.0,ymax)
	      endif
	      ii = npts
	      call pgline(ii,BX(1,1),B(1,1))
	      IF (EXTRAF) THEN
	        call pgmtext('T',-1.2,0.98,1.0,dname)
	      ELSE
	        call pgmtext('T',-2.4,0.98,1.0,dname)
	      ENDIF
	      if (wavel .LE. 0.0) then
	        CALL PGWINDOW(xhigh,xlow,0.0,99.9)
	      else
	        CALL PGWINDOW(xlow,xhigh,0.0,99.9)
	      endif
	      call pgsch(1.0)
	    ENDIF
	    IF (I .eq. 1 .and. (EXTRAF .or. .not. RAWF) .or. 
	1	.not. (EXTRAF .or. RAWF)) THEN
C Plot the observed peaks always in extra box, or if not plotting RAW data
	      DO II=1,numob
	        IF (wavel .GT. 0) THEN 
	          FLAG = DTOTT(ds(ii),xpos,wavel)
	        ELSE
	          FLAG = .true.
		  xpos = ds(ii)
	        ENDIF
	        if (FLAG .and. xpos.ge.xlow .and. xpos.le.xhigh) THEN
		  XT(1) = xpos
		  XT(2) = xpos
		  YT(1) = 0.0
		  YT(2) = inten(ii)
C Is the peak excluded?
		  amax = 31416
		  flag = dtott(ds(ii),peak,1.5405598)
		  x1 = min(180.,peak+abs(d2t))
		  flag = tttod(dmin,x1,1.5405598)
	    	  IF (FLAG) flag = DTOPDF(amax,dmin)
		  amin = -31416
		  x1 = max(0.,peak-abs(d2t))
		  flag = tttod(dmax,x1,1.5405598)
		  IF (FLAG) flag = DTOPDF(amin,dmax)
C   If one bit is not excluded, draw the peak with a solid line
		  call PGsls(1)
	          IF (colflag) call pgsci(2+mod(icol-1,maxcol-1))
		  do i2=amin,amax
		    if (.not. EXRtst(extbl,i2)) goto 707
		  ENDDO
	          IF (colflag) THEN
		    call pgsci(3+mod(icol-2,maxcol-2))
		  else
		    call PGsls(4)
		  endif
707		  call PGLINE(2,XT,YT)
	        ENDIF
	      ENDDO
	      IF (colflag) call pgsci(2+mod(icol-1,maxcol-1))
	      IF (RAWF .or. .not. EXTRAF) THEN
	        call pgmtext('T',-2.4,0.98,1.0,sname)
	      ELSE
	        call pgmtext('T',-1.2,0.98,1.0,sname)
	      ENDIF
	    ENDIF
	    IF (I .ne. 1 .or. .not. EXTRAF) THEN 
C     plot a card
C        get name info
	      call pgsci(1)
	      call PGsls(1)
	      CALL READNAM(NAMREC(I)
	1	,LUNN,QM,FCOR,CHFORM,LCHFORM,CHNAME,LCHNAME)
C        get D/I info
	      CALL READDI(DIREC(I),dsp,INT,NDSINT,LPDF,0.0,200)
C label each plot in upper right corner
	      write(str1,'(a1,i6.6,a1)') '[',jcard(I),']'
	      call pgmtext('T',-1.2,0.98,1.0,str1)
	      IF (HARDF) then
	        IF (LCHFORM + LCHNAME .lt. 50) then 
		  write(name,'(60a)') (CHFORM(j),j=1,LCHFORM),' / ',
	1		(CHNAME(j),j=1,min(55-lchform,LCHNAME))
     	        ELSE
		  write(name,'(60a)') (CHFORM(j),j=1,min(60,LCHFORM))
	        ENDIF
	        call pgmtext('T',-1.2,0.02,0.0,name)
	      ELSE
	        WRITE(str1,'(i8)') icrd(I)
	        call press(str1,l1)
	        WRITE(str2,'(i8)') NPH
	        call press(str2,l2)
	        call pgmtext('T',-1.2,0.02,0.0,str1(1:l1)//'/'//str2(1:l2))
	      ENDIF
C Plot the JCPDS peaks 
	      DO II=1,NDSINT
		IF (wavel .GT. 0) THEN 
		  CALL DTOTT(dsp(II),xpos,wavel)
		ELSE
		  xpos = dsp(II)
		ENDIF
		if (xpos .ge. xlow .and. xpos .le. xhigh) THEN
		  XT(1) = xpos
		  XT(2) = xpos
		  YT(1) = 0.0
		  YT(2) = int(ii)
C Is the peak excluded?
		  amax = 31416
		  flag = dtott(dsp(II),peak,1.5405598)
		  x1 = min(180.,peak+abs(d2t))
		  flag = tttod(dmin,x1,1.5405598)
	    	  IF (FLAG) flag = DTOPDF(amax,dmin)
		  amin = -31416
		  x1 = max(0.,peak-abs(d2t))
		  flag = tttod(dmax,x1,1.5405598)
		  IF (FLAG) flag = DTOPDF(amin,dmax)
		  call PGsls(1)
	          call pgsci(1)
C   If one bit is not excluded, draw the peak with a solid line
		  do i2=amin,amax
		    if (.not. EXRtst(extbl,i2)) goto 708
		  ENDDO
	          IF (colflag) THEN
		    call pgsci(2)
		  else
		    call PGsls(2)
		  endif
708		  call PGLINE(2,XT,YT)
	        ENDIF
	      ENDDO
	    ENDIF
	    call PGsls(1)
	    call pgsci(1)
500	  CONTINUE

C close hardcopy graphics device and reopen terminal
	  IF (HARDF) then
	    CALL CLHD(lo,li)
	  ELSE
	    WRITE(LO,'(A)')
	1	'$Repeat this plot on hardcopy? (Y/[N]/^Z=exit to menu): '
	    ians = 'N'
	    READ (LI,'(a1)',end=998) IANS
C close the graphics terminal 
	    CALL EGRAF(ICRT,lo,li)
	    IF(IANS.EQ.'Y' .or. IANS.EQ.'y') THEN 
	      hardf = .true.
	      goto 21
	    ENDIF
	  ENDIF
	ENDDO

999	RETURN
998	CALL EGRAF(ICRT,lo,li)
	RETURN
997	WRITE(lo,'(A)') ' QUICKPLT -- Error processing raw data'
	NPTS = 0
	RETURN
996	WRITE(lo,'(A)') ' QUICKPLT -- Unexpected end-of-file'
	RETURN
	END
