C-------------------------------------------------------------------------
	SUBROUTINE GETFILE(NOPEAK,NODATA,filename)
C-------------------------------------------------------------------------
C This is a general purpose subroutine to read peaks or diffractograms. 
C-------------------------------------------------------------------------
C Parameters:
C   NOPEAK	  FALSE if a peak file has been read
C   NODATA	  FALSE if a data file has been read
C   filename	  name of peak/data file that was read

	include 'logic.common'
	include '[-.shared]flabel.common'

	LOGICAL nopeak,nodata
	LOGICAL flag,STATUS,GET_LOGICAL

	CHARACTER*(*) filename

	CHARACTER*80 filform
	CHARACTER*80 peakform
	CHARACTER*80 datafile/' '/,peakfile/' '/
	SAVE datafile,peakfile
	INTEGER ln

	nopeak = .true.
	noDATA = .true.
	filename = ' '

	IF(PEAKFILE .ne. ' ') THEN
	  write(lo,'(a)') '$Display peaks from file '//
	1	PEAKFILE(:lench(PEAKFILE))//'? ([Y]/N): '
	  read(li,'(a1)',end=900) ians
	  IF (IANS .ne. 'N' .and. IANS .ne. 'n') then 
	    filename = peakfile
	    goto 230
	  ENDIF
	ENDIF

C is there a current search file? If so get the file name
	flag = GET_LOGICAL('SEARCH_FILE',filename,80,ln,lgprc)
	if (flag .and. ln .gt. 0) THEN
	  write(lo,'(a)') ' Current SEARCH Load file is '
	1	//filename(:ln)
	  write(lo,'(a)') '$Display peaks from this file? ([Y]/N): '
	  read(li,'(a1)',end=900) ians
	  IF (IANS .ne. 'N' .and. IANS .ne. 'n') then 
	    filename = filename(:ln)//'/format=peak'
	    peakfile = filename 
	    goto 230
	  ENDIF
	ENDIF

100	write(lo,'(A)') ' ',
	1	' Enter a data/peak file name with a wild card (* or %)',
	1	' to see directory listing.',' ',
	1	'$Enter name of peak file [default= no peak file]: '
	read(li,'(a)',end=900) filename
	do I=1,lench(filename)
	  if (filename(I:I) .eq. '*' .or. filename(I:I) .eq. '%') THEN
	    ln= lench(filename)
	    call lib$spawn('$ directory/nosiz/notra/bri '//filename(1:ln))
	    goto 100
	  ENDIF
	enddo

230	k = lench(filename)
	nopeak = .true.
	if (k .gt. 0) then 
	  CALL READDATA(filename,1,STATUS,.true.,.false.,
	1	filform,peakform,.false.)
	  IF (STATUS .and. NPKS(1) .gt. 0) then
	    nopeak = .false.
	    filename = filename(:lench(filename))//'/form='//peakform
	    RETURN
	  ELSE
	    WRITE (*,'(1x,2a)') 'Unable to read peaks from file: ',
	1	filename(:lench(filename))
	    peakfile = ' '
	    goto 100
	  ENDIF
	endif

C------------------------------------------------------------------------
	IF(DATAFILE .ne. ' ') THEN
	  write(lo,'(a)') '$Display data from file '//
	1	DATAFILE(:lench(DATAFILE))//'? ([Y]/N): '
	  read(li,'(a1)',end=900) ians
	  IF (IANS .ne. 'N' .and. IANS .ne. 'n') then 
	    filename = DATAfile
	    goto 330
	  ENDIF
	ENDIF

200	write(lo,'(a)') 
	1	'$Enter name of data file [default= no data file]: '
	read(li,'(a)',end=900) filename
	do I=1,lench(filename)
	  if (filename(I:I) .eq. '*' .or. filename(I:I) .eq. '%') THEN
	    ln= lench(filename)
	    call lib$spawn('$ directory/nosiz/notra/bri '//filename(1:ln))
	    goto 200
	  ENDIF
	enddo

330	ln= lench(filename)
	nodata = .true.
	if (ln.gt. 0) then 
	  CALL READDATA(filename,1,STATUS,.false.,.true.,
	1	filform,peakform,.false.)
	  IF (STATUS .and. NPOINT(1) .gt. 0) then
C convert the data array to the proper units -- wavelength or d-space
	    IF (wave0 .gt. 0) THEN
	      call DATCONV(BX(1,1),fxtyp,npoint(1),wave(1),
	1	Xarray,XTYP_TT,nxarr,WAVE0,*800)
	    ELSE
	      call DATCONV(BX(1,1),fxtyp,npoint(1),wave(1),
	1	Xarray,XTYP_D,nxarr,0.0,*800)
	    ENDIF
	    filename = cfilnam(1)
	    filename = filename(:lench(filename))//'/form='//filform
	    datafile = filename
	    nodata = .false.
	  ELSE
	    WRITE (*,'(1x,2a)') 'Unable to read data from file: ',
	1	filename(:lench(filename))
	    datafile = ' '
	    goto 100
	  ENDIF
	ENDIF

900	RETURN
800	WRITE(lo,'(2A)') 
	1	' GETFILE ERROR -- unable to convert data in file',
	2	cfilnam(1)(:lench(cfilnam(1)))
	CALL ps_PAUSE(PROMPT)
	END
