	SUBROUTINE GETCARDS(*,trace,tracelen)
C
C Subroutine to get element input and logic
C
	include 'logic.common'
	INTEGER*2 tracelen
	CHARACTER*(*) trace
	CHARACTER*40 parm
	INTEGER*4 ICARD,NAMREC,FULREC,DIREC,ISEQ
	INTEGER*4 CARDNO
	LOGICAL GET_NUMBER,flag,GET_FNUMBER

	trace = '/CARDS=('
	tracelen = 8

	CALL TBLCLR(TABLE1,N_Lwords,nph1)
	ICARD = 0 
1	FLAG = GET_NUMBER('CARDS',CARDNO)
	IF (FLAG) goto 100
C is CARDNO a valid ICDD-JCPDS number?
	IF (CARDNO .le. 10000 .or. CARDNO/10000 .gt. N_SETNO) then
	  write (lo,'(A,i)')' Invalid ICDD-JCPDS entry number: ',cardno
	  goto 1
	ELSE
C lookup a sequence number
	  CALL CARDLOC(CARDNO,NAMREC,FULREC,DIREC,ISEQ,N_cards,LUNM,*2)
	ENDIF
C set bit number ISEQ in TABLE1
	CALL BITSET(TABLE1,ISEQ,N_cards,1)
	ICARD = ICARD + 1
	write(trace(tracelen+1:),'(i6.6,a1)') CARDNO,','
	tracelen = tracelen + 7
	GOTO 1

100	IF (ICARD .eq. 0 .and. PROMPT) then
	  WRITE(lo,'(a)') ' ',
	1	' Enter one ICDD-JCPDS entry number per line as'//
	1	' a 5-6 digit ',' number (set#*10000+entry#)'//
	1	' or as 2 numbers (set#, entry#). ',
	2	' Enter a blank line when done.'
101	  WRITE(lo,'(a)') '$NUMBER> '
	  READ(li,'(2i6)',END=200,err=101) CARDNO,i
	  if (i .gt. 0) cardno = cardno*10000 + i
	  IF (CARDNO .eq. 0) GOTO 200
C is CARDNO a valid ICDD-JCPDS number?
	  IF (CARDNO .le. 10000 .or. CARDNO/10000 .gt. N_SETNO) then
	    write (lo,'(A,i)') ' Invalid ICDD-JCPDS entry number: ',
	1	cardno
	    goto 101
	   ELSE
C lookup a sequence number
	    CALL CARDLOC(CARDNO,NAMREC,FULREC,DIREC,ISEQ,N_cards,LUNM,*2)
	  ENDIF
C set bit number ISEQ in TABLE1
	  CALL BITSET(TABLE1,ISEQ,N_cards,1)
	  ICARD = ICARD + 1
	  write(trace(tracelen+1:),'(i6.6,a1)') CARDNO,','
	  tracelen = tracelen + 7
	  GOTO 101
	ENDIF

200	IF (ICARD .eq. 0) THEN
	  write (lo,'(A)') ' Error -- no valid entries input'
	  return 1
	endif

	trace(tracelen:tracelen) = ')'
	RETURN
2	write (lo,'(A,i6)') ' Entry not in found in ICDD-JCPDS: ',
	1  CARDNO,' (Number not assigned or pattern has been deleted)'
	goto 1
	END
