      SUBROUTINE FILOUT(FILBUF,RECORD,HDATA,SDATA,RMSBUF,NBUF,NOR,MM)
C**********************************************************************
C                                                                     *
C     A ROUTINE TO WRITE THE OUTPUT FILE FROM VOYAGER POST            *
C     FILTERING. AFTER A STARTING HDR1 RECORD, THE FILE WILL          *
C     CONTAIN LFM RECORDS AND A TRAILER RECORD (HDR1).                *
C                                                                     *
C     R. S. KENNON CODE 694                                           *
C     S. B. KRAMER CODE 694  MODIFIED FOR VMS AND DEC FORTRAN         *
C                            02/15/94                                 *
C     S. B. KRAMER CODE 692  MODIFIED TO INCLUDE SEDR DATA BLOCK      *
C                            07/26/94                                 *
C                                                                     *
C     CALLING ROUTINE:  INTRFC.FOR                                    *
C                                                                     *
C     INPUT:                                                          *
C       FILBUF  INPUT BUFFER OF FILTERED 1.92 SEC AVERAGES            *
C       RECORD  SKELETAL SUMMARY RECORD STRUCTURE                     *
C       HDATA   INPUT BUFFER OF HEADER BLOCK                          *
C       RMSBUF  INPUT BUFFER OF 1.92 SEC RMS VALUES                   *
C       NBUF                                                          *
C       NOR     NUMBER OF SUMMARY RECORDS INPUTTED                    *
C       MM                                                            *
C                                                                     *
C**********************************************************************
      INTEGER*4 RECORD(568),HDATA(25600),SDATA(32000),
     &          NBUF(20000),OUTPUT_RECORD(568),NB(25),NSET(2)
      REAL*4 FILBUF(3,20000),RMSBUF(3,20000),FIL_OUTPUT(568),B(25,3),
     &       RMS(75),F1(25),F2(25)
      EQUIVALENCE (OUTPUT_RECORD(1), FIL_OUTPUT(1)),
     &            (F1(1),            OUTPUT_RECORD(99)),
     &            (F2(1),            OUTPUT_RECORD(124)),
     &            (B(1,1),           OUTPUT_RECORD(199)),
     &            (B(1,2),           OUTPUT_RECORD(224)),
     &            (B(1,3),           OUTPUT_RECORD(249)),
     &            (RMS(1),           OUTPUT_RECORD(274)),
     &            (NB(1),            OUTPUT_RECORD(349))
      DATA M/0/,NSET/10000,0/,K/0/,KS/0/
C
      IF (M.GE.20000) M=0
C
C****** COPY LAST SUMMARY TAPE LFM RECORD TO OUTPUT RECORD ************
C****** THIS GIVES A SKELETON LFM RECORD ******************************
C
      DO 10 I=1,568
       FIL_OUTPUT(I)=RECORD(I)
   10 CONTINUE
C
C**** FILL HEADER, 1.92 SECOND AND SEDR DATA PORTIONS OF LFM RECORD ***
C
      IF (K.GE.25600) K=0
      IF ( KS.GE.32000 ) KS = 0
      N=NSET(MM)
      DO 40 NR=1,NOR
C
C***** OUTPUT HEADER **************************************************
C******** EXTRACT 32 WORDS FROM HEADER BUFFER AND *********************
C******** PLACE AT BEGINNING OF OUTPUT RECORD *************************
C
       DO 20 J=1,32
        K=K+1
        OUTPUT_RECORD(J)=HDATA(K)
   20  CONTINUE
C
C***** OUTPUT 1.92 SECOND FILTERED DATA *******************************
C******** EXTRACT 25 B1,B2,B3 WORDS FROM BBUF *************************
C******** EXTRACT 75 RMS WORDS FROM RMS BUFFER ************************
C******** EXTRACT 25 N WORDS FROM N BUFFER ****************************
C******** STORE IN APPROPRIATE LOCATIONS IN OUTPUT RECORD *************
C
       DO 30 L=1,25
        N=N+1
        M=M+1
        F1(L)=0.
        F2(L)=0.
        B(L,1)=FILBUF(1,N)
        B(L,2)=FILBUF(2,N)
        B(L,3)=FILBUF(3,N)
        RMS(L)=RMSBUF(1,M)
        RMS(L+25)=RMSBUF(2,M)
        RMS(L+50)=RMSBUF(3,M)
        IF (B(L,1).EQ.999.) THEN
         F1(L)=999.
         F2(L)=999.
         RMS(L)=999.
         RMS(L+25)=999.
         RMS(L+50)=999.
        ENDIF
        NB(L)=NBUF(M)
   30  CONTINUE
C
C***** OUTPUT SEDR BLOCK **********************************************
C******** EXTRACT 40 WORD SEDR BLOCK FROM BUFFER **********************
C******** AND PLACE AT END OF OUTPUT RECORD ***************************
C
       DO 35 JS=1,40
        KS = KS + 1
        OUTPUT_RECORD(528+JS) = SDATA(KS)
   35  CONTINUE     
C
C**** WRITE OUTPUT FILE ***********************************************
C
       WRITE(12) OUTPUT_RECORD
   40 CONTINUE
C
      RETURN
      END
