C***********************************************************************
C
      SUBROUTINE WRREC
C
C	WRITE A RECORD TO THE RAW DATA FILE
C
C***********************************************************************
C
C     DESCRIPTION:
C
C           THIS ROUTINE WRITES THE COLLECTED DATA TO THE
C        OUTPUT FILE.  THIS CONSISTS OF COUNT TIMES AND X-RAY
C        COUNTS THAT WERE COLLECTED.  THIS ROUTINE IS NORMALLY
C        CALLED WHEN THERE ARE SIXTEEN DATA SETS TO BE OUPUT
C        EXCEPT ON THE LAST CALL WHERE ANY REMAINING DATA IS
C        WRITTEN.
C	## This was originally subroutine WRFILE
C***********************************************************************
C
      INCLUDE 'COMMON.FTN'
C
C Uses STPSIZ, ANGLE, CNT, ICOUNT, NREC, IRAW, IERR, ITIM, IDAT
C Calls IFTEMP, SYTIME
C
C***********************************************************************
C
C  IS THERE ANY DATA IN THE BUFFER TO BE WRITTEN? IF NOT THEN RETURN
C
      IF(ICOUNT.EQ.0) GOTO 9999
C
C***********************************************************************
C
C  GET THE TEMPERATURE (COMMENTED OUT)
C
      CALL IFTEMP(ITEMP)
C
C  GET THE TIME
C
      CALL SYTIME
C
C  GET THE ANGLE (IN DEGREES) FOR THE LAST POINT
C
      CANGD = ANGLE * STPSIZ
C
C***********************************************************************
C
C  WRITE THE DATA TO THE OUTPUT FILE.
C
      WRITE(IRAW,300) CANGD,ITIM(1),ITIM(2),ITEMP,
     1      (IFIX(CNT(I)),I=1,ICOUNT)
300   FORMAT(F7.3,2I2,I5,16I7)
C300   FORMAT(F8.3,2I2,I4,16F7.0)
C
C  KEEP TRACK OF THE NUMBER OF RECORDS WRITTEN
C
      NREC = NREC + 1
C
C***********************************************************************
C
C  TEST SUM OF COUNT ARRAY FOR SUM>0 AN INDICATION THAT SHUTTER IS OPEN
C  ALSO ZERO BUFFER ARRAY AND RESET POINTER
C
400   SUM=0.0
      DO 500 I=1,ICOUNT
      SUM=SUM+CNT(I)
500   CNT(I) = 0.0
C
      ICOUNT = 0
C
C  IF THE SUM IS ZERO TYPE A WARNING
C
      IF (SUM.NE.0.0) GOTO 9999
      WRITE(IERR,510) ITIM,IDAT,CANGD
510   FORMAT(' >> WARNING << - ZERO COUNTS! ARE XRAYS ON?',
     & I4,':',I2,':',I2,I3,'/',I2,'/',I2,' 2TH=',F8.3)
C     & I4,':',I2.2,':',I2.2,I3,'/',I2,'/',I2.2,' 2TH=',F8.3)
C
C***********************************************************************
C
C  ALL DONE
C
9999  RETURN
      END
