C---------------------------------------------------------------------------
	SUBROUTINE WRITPROF(nfil,filename,STATUS)
C---------------------------------------------------------------------------
C	Write out a file in PROFPV (Cox et al. Rietveld) 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='.PROFIN')
	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
