C---------------------------------------------------------------------------
	SUBROUTINE WRITPEAK(nfil,filename,STATUS)
C---------------------------------------------------------------------------
C	Write out a peak file in Penn State (.ADR) Format
C
C---------------------------------------------------------------------------
	INTEGER STATUS
	CHARACTER*(*) filename

	include 'shared$common'

	OPEN(UNIT=OUT,NAME=filename,STATUS='NEW',ACCESS='SEQUENTIAL',
	1	FORM='FORMATTED',CARRIAGECONTROL='LIST',err=99,
	1	defaultfile='.adr')

	NPT = NPOINT(nfil)
C
	WRITE (OUT,'(A)') ATITLE(nfil)
	WRITE (OUT,120,err=3) date(1,nfil),date(2,nfil),date(3,nfil),
	1	INST(nfil),SOURCE(nfil),MONO(nfil)
120	FORMAT('DATE = ',2(I2'/')I2,3X,'INST = 'A2,5X,'SOURCE = ',
	1	A2,5X,'KA12 = ',l5)
	WRITE (OUT,140,err=3) IRAD(nfil),WAVE(nfil),WKA1(nfil),WKA2(nfil)
140	FORMAT ('IRAD = 'A2,9X,'WAVE = ',F8.6,4X,'WKA1 = 'F8.6,4X,
	1	'WKA2 = 'F8.6)
	WRITE (OUT,160,err=3) TIME(nfil),TEMP1(nfil),TEMP2(nfil),
	1	REFINT(nfil)
160	FORMAT ('TIME = 'F6.2,5X,'TEMP1 ='F7.2,5X,'TEMP2 ='F7.2,5X,
	1	'REFINT ='F7.0)
	WRITE (OUT,180,err=3) START(nfil),FINISH(nfil),DELTA(nfil),NPT
180	FORMAT ('RMIN = 'F6.3,5X,'RMAX = 'F7.3,5X,'DELR = 'F7.3,5X,
	1	'NPTS = 'I4)

	WRITE (OUT,'(A)') 'PEAK '
C
	DO J=1,NPKS(nfil)
	  IF (RELINT(J,nfil) .lt. 10.0) THEN
	    WRITE(OUT,63,err=3) J, TT(J,nfil), DSPACE(J,nfil), 
	1	RELINT(J,nfil), TTCOR(J,nfil), PKHT(J,nfil), BKG(J,nfil), 
	2	FINTEG(j,nfil), FWHM(J,nfil), IWAVE(J,nfil),
	3	COMMT1(J,nfil), COMMT2(J,nfil)
63	  FORMAT(I4,f10.3,F8.4,f5.1,F10.3,F8.0,F6.0,1pg11.3,F6.3,I2,1x,2A4)
	  ELSE
	    WRITE(OUT,62,err=3) J, TT(J,nfil), DSPACE(J,nfil), 
	1	RELINT(J,nfil), TTCOR(J,nfil), PKHT(J,nfil), BKG(J,nfil), 
	2	FINTEG(j,nfil), FWHM(J,nfil), IWAVE(J,nfil),
	3	COMMT1(J,nfil), COMMT2(J,nfil)
62	  FORMAT(I4,f10.4,F8.4,F5.0,F10.3,F8.0,F6.0,F8.1,F6.2,I3,2A4)
	  ENDIF
	ENDDO
	CLOSE (UNIT=OUT,STATUS='KEEP')

	STATUS = 0
	RETURN

99	STATUS = 1
	RETURN

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