C---------------------------------------------------------------------------
	SUBROUTINE WRITDU(nfil,filename,STATUS)
C---------------------------------------------------------------------------
C	Write out a file in DuPont Format
C
C---------------------------------------------------------------------------
	INTEGER STATUS
	CHARACTER*(*) filename

	include 'shared$common'

	OPEN(UNIT=OUT,NAME=filename,STATUS='NEW',ACCESS='SEQUENTIAL',
     1		FORM='UNFORMATTED',err=99,defaultfile='.ddat')
C get the actual name of the new file
	INQUIRE(FILE=filename,NAME=filename,defaultfile='.ddat')
C
	NPT = NPOINT(nfil)
C
	WRITE(OUT) ATITLE(nfil)
	WRITE(OUT) DATE(1,nfil),DATE(2,nfil),DATE(3,nfil),INST(nfil),
	1	SOURCE(nfil),iword,IRAD(nfil),WAVE(nfil),WKA1(nfil),
	2	WKA2(nfil),START(nfil),FINISH(nfil),DELTA(nfil),NPT,
	3	TIME(nfil),TEMP1(nfil),TEMP2(nfil),REFINT(nfil),
	4	NPKS(nfil),MONO(nfil),byte1,byte2,byte3,
	5	NBKGP(nfil),BSTIFF(nfil)
	WRITE(OUT) (B(I,nfil),I=1,NPT)
	WRITE(OUT) (BESD(I,nfil),I=1,NPT)
	IF (DELTA(nfil) .eq. 0)  WRITE(OUT) (BX(I,NFIL),i=1,NPT)
C
C	IF PEAKS ARE PRESENT, WRITE THEM
C
	IF (NPKS(nfil).GT.0) THEN
	  DO J=1,NPKS(nfil)
	    WRITE(OUT) TT(J,nfil),TTCOR(J,nfil),DSPACE(J,nfil),
	1	IWAVE(J,nfil),IH(J,nfil),IK(J,nfil),IL(J,nfil),PKHT(J,nfil),
	2	BKG(J,nfil),FINTEG(J,nfil),FWHM(J,nfil),FLPCOR(J,nfil),
	3	ABSCOR(J,nfil),CORINT(J,nfil),RELINT(J,nfil),ESDINT(J,nfil),
	4	ESDDSP(J,nfil),COMMT1(J,nfil),COMMT2(J,nfil),
	3	DELTT(J,nfil),WTINT(J,nfil),WTHKL(J,nfil)
	  ENDDO
	ENDIF
C
C	IF BASELINE (BACKGROUND) POINTS ARE PRESENT, WRITE THEM
C
	IF (NBKGP(nfil).GT.0) THEN
	  WRITE(OUT) (xbkg(I,nfil),I=1,NBKGP(nfil))
	  WRITE(OUT) (ybkg(I,nfil),I=1,NBKGP(nfil))
	  WRITE(OUT) (ybkgdel(I,nfil),I=1,NBKGP(nfil))
	ENDIF
	CLOSE(UNIT=OUT,STATUS='KEEP')

	FEXISTS(nfil) = .true.
C update the file name 
	CFILNAM(NFIL) = filename

	CLOSE(UNIT=OUT)
	STATUS = 0
	RETURN

99	STATUS = 1
	RETURN

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