C---------------------------------------------------------------------------
	SUBROUTINE WRITGSAS(nfil,filename,STATUS)
C---------------------------------------------------------------------------
C	Write out a file in GSAS datafile Format
C
C---------------------------------------------------------------------------
	INTEGER STATUS
	CHARACTER*(*) filename

	include 'shared$common'

	OPEN(UNIT=OUT,NAME=filename,TYPE='NEW',FORM='FORMATTED',
	1	CARRIAGECONTROL='LIST',err=99,defaultfile='.GSAS',
	1	recordsize=80,recordtype='fixed')

	WRITE (OUT,'(a)',err=3) ATITLE(nfil)
	NPT  = NPOINT(nfil)
	nrec = (npt-1)/5 + 1
	write(OUT,273)npt,nrec,START(nfil)*100.,DELTA(nfil)*100.
273	format('BANK  1 ',2i8,' CONST ',2f10.2,' 0 0 ESD',21x)

	WRITE(OUT,'(5(f8.1,f8.2))',err=3) 
	1	(B(I,nfil),BESD(I,nfil),I=1,NPT)
	CLOSE(UNIT=OUT)

	WRITE (OUT,'(a)') ATITLE(nfil)
	NPT = NPOINT(nfil)
	WRITE(OUT,'(3f10.3)') START(nfil),DELTA(nfil),FINISH(nfil)
	DO I=1,NPT,10
	  WRITE(OUT,'(10f8.2)',err=3) (B(J,nfil), J = I, MIN(I+9,NPT))
	  WRITE(OUT,'(10f8.3)',err=3) (BESD(J,nfil), J = I, MIN(I+9,NPT))
	ENDDO
	CLOSE(UNIT=OUT)
	STATUS = 0
	RETURN

99	STATUS = 1
	RETURN

3	STATUS = 2
	CLOSE(UNIT=OUT)
	RETURN
	END
