     	SUBROUTINE WRWRIO
C
C  PROGRAMMER:  R. L. SNYDER
C		ALFRED UNIVERSITY,  March 1989
C
C	THIS ROUTINE WRITES A RIGAKU ORIGINAL UNFORMATED RAW DATA FILE
C	FROM THE CORRESPONDING COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
        INTEGER*2 FILNUM, MONTH, DAY, YEAR, MPTS
        CHARACTER INSTR*4
C
     	CLOSE( UNIT=IOUT )
     	OPEN( UNIT=IOUT, FILE=FILOUT, STATUS='NEW',
     	1 FORM='UNFORMATTED', ACCESS='SEQUENTIAL', ERR=777 )
C
C  SET UP THE FILE HEADER INFORMATION FOR WRITING
C
     	IDAY = DATM / 10000
     	DAY = IDAY
     	IMONTH = DATM / 100 - IDAY * 100
     	MONTH = IMONTH
     	IYEAR = DATM - (IDAY * 10000 + IMONTH * 100)
     	YEAR = IYEAR
     	FILNUM = 99
     	INSTR = '    '
C
C  WRITE THE FILE HEADER INFORMATION...
C
      WRITE(IOUT, ERR=777, IOSTAT=IERR) FILNUM, MONTH, DAY, 
     &          YEAR, INSTR,
     &		(SLID(I),I=1,12), BANG(1), BANG(3), BANG(10), 
     &          ANODE(IELE), WAVE(3,IELE), BANG(2), NPTS
C
C write the intensities 32 per record.
C
C	NREC = (MPTS-1)/32 + 1
        DO 50 I = 1, NPTS, 32
	WRITE( IOUT, ERR=777) (YOBS(J), J=I,I+31)
50	CONTINUE
     	GO TO 999
777	IERR = 1
     	GOTO 999
999	RETURN
     	END
