C----------------------------------------------------------------------
	SUBROUTINE READGSAS1(dname,pname,filform,nfil,STATUS)
C----------------------------------------------------------------------
C Read in file in GSAS format
C	THIS ROUTINE READS FROM AN ASCII GSAS RAW DATA FILE
C----------------------------------------------------------------------
	LOGICAL status
	INTEGER nfil
	character*(*) dname,pname,filform
	CHARACTER*7 thisform/'GSASASC'/

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

	LOGICAL exist
	character	line*80
	CHARACTER	FMT*5, ESDFL*3
C
C Assume that the read was not successful
	STATUS = .false.

C check the file format qualifier, if one exists
	IF (filform .ne. ' ') THEN
	  I = LENCH(filform)
	  IF (filform(:I) .ne. thisform(:I)) RETURN
	ENDIF

C Is there a datafile name?
	IF (dname .eq. ' ')  RETURN
C   First, Does the file exist?
	INQUIRE(FILE=dname,EXIST=exist,NAME=cfilnam(nfil),
	1	defaultfile='.gsas')
	IF (.not. exist) goto 200
	OPEN(UNIT=IN,FILE=cfilnam(nfil),TYPE='OLD',ERR=200,
	1	recordsize=80,recordtype='fixed',access='direct',
	1	defaultfile='.GSAS',FORM='FORMATTED',readonly,shared)

     	READ(IN,'(A)',rec=1,ERR=200) ATITLE(nfil)

	NR = 1

100	I = 1
	LINE = ' '
	DO WHILE (LINE(1:4) .ne. 'BANK')
	  NR = NR + 1
     	  READ(IN,'(A)',rec=nr,ERR=200) line
	  IF (I .gt. 10) goto 200
	ENDDO
	CALL GSAS1PAR(line, NBANK, NPNT, NREC, FMT, angi, STEP, ESDFL)
	IF (FMT .ne. 'CONST') THEN
	  write(lo,'(A,i3,2A)') ' BANK',NBANK,
	1		' -- Unable to handle file mode ',line
	  NR = NR + NREC
	  goto 100
	ELSE
	  write(lo,'(A,I3,A)') '$Read Bank',NBANK,'? ([Y]/N): '
	  read (li,'(A)',err=200) ians
	  IF (IANS .eq. 'N' .or. IANS .eq. 'n') THEN
	    NR = NR + NREC
	    goto 100
	  ENDIF
	ENDIF

	IF (NPNT .gt. m$pts) THEN
	  write(lo,'(A)') 
	1	' Warning -- not all points will be read'
	  NPNT = m$pts
	ENDIF

	IF (ESDFL .eq. 'ESD') THEN
	  do i=1,NPNT,5
	    read(in,'(10f8.0)',rec=nr+(I+5-1)/5,err=200) 
	1	(B(j,nfil),BESD(J,nfil),j=i,min(i+5-1,NPNT))
	  enddo
	  do J=1,NPNT
	    BX(J,nfil) = angI + (J-1)*STEP 
	  ENDDO
	  FYTYP(nfil) = YTYP_scl
	ELSE
	  do i=1,NPNT,10
	    read(in,'(10f8.0)',rec=nr+(I+10-1)/10,err=200) 
	1	(B(j,nfil),j=i,min(i+10-1,NPNT))
	  ENDDO
	  do J=1,NPNT
	    BESD(J,nfil) = SQRT( MAX(0., B(j,nfil) )) 
	    BX(J,nfil) = angI + (J-1)*STEP 
	  ENDDO
	  FYTYP(nfil) = YTYP_cnt
	ENDIF
C----------------------------------------------------------------------
C----------------------------------------------------------------------
	close(unit=IN)
	FXTYP(nfil) = XTYP_TT
C    get the wavelength since we don't have one
	CALL WAVEINQ(LO,LI,IRAD(nfil),WAVE(nfil),WKA1(nfil),WKA2(nfil),*33)
33	INST(nfil)='  '
	SOURCE(nfil)='GS'
	MONO(nfil)= .true.
	IF (WKA1(nfil) .ne. WKA2(nfil)) MONO(nfil)= .false.
	START(nfil) = angi
	FINISH(nfil) = angI + (npnt-1)*STEP 
	DELTA(nfil) = step
C set the date to now since we have no better choice
	CALL IDATE(DATE(1,nfil),DATE(2,nfil),DATE(3,nfil))
	IF (npnt .le. 0) goto 200
	write (LO,'(A)') ' File '//cfilnam(nfil)(:lench(cfilnam(nfil)))
	1		//' read in ASCII GSAS format'
	NPOINT(nfil) = min(m$pts,NPNT)
	filform = thisform
	STATUS = .true.
	RETURN
C----------------------------------------------------------------------------
200	close(unit=IN)
	RETURN
	END
C----------------------------------------------------------------------------
	SUBROUTINE GSAS1PAR(line, NBANK, NPNT, NREC, FMT, angi, STEP,
	1	ESDFL)
	CHARACTER*(*) LINE, FMT, ESDFL
	INTEGER NBANK, NPNT, NREC
	REAL ANGI, STEP

	INTEGER LN,n1,n2

	ln = lench(line)
C Find 1st token
	n1 = 5
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 1st token is the number of this bank
	read(line(n1:n2),'(I)') nbank

	n1 = n2 + 1
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 2nd token is the number of points
	read(line(n1:n2),'(I)') npnt

	n1 = n2 + 1
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 3rd token is the number of records
	read(line(n1:n2),'(I)') nrec

	n1 = n2 + 1
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 4th token is the file format
	FMT = line(n1:n2) 

	n1 = n2 + 1
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 5th token is the number of starting angle
	read(line(n1:n2),'(f10.0)') angi
	angi = angi / 100.

	n1 = n2 + 1
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 6th token is the number of step size
	read(line(n1:n2),'(f10.0)') step
	step = step / 100.

	n1 = n2 + 1
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 7th token is not used

	n1 = n2 + 1
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 8th token is not used

	n1 = n2 + 1
	do while(line(n1:n1) .eq. ' ' .and. n1 .lt. ln)
	  n1 = n1 + 1
	enddo
	n2 = n1
	do while(line(n2+1:n2+1) .ne. ' ' .and. n2+1 .lt. ln)
	  n2 = n2 + 1
	ENDDO
C 9th token is either ESD or not present
	ESDFL = line(n1:ln)
D	type *, line
D	type *, NBANK
D	type *, NPNT
D	type *, NREC 
D	type *, FMT 
D	type *, angi 
D	type *, STEP
D	type *, ESDFL
	RETURN
	END
