      SUBROUTINE VIM5SCF(SCF,TIME,BAD)
C
C COMPUTE 48 SECOND AVERAGED SPACECRAFT FIELD FOR VIM-5 RECORD
C
C INPUT 48 SECONDS OF DETAIL SPACECRAFT FIELD - SCF
C OUTPUT RMS(SCF)(1,2,3), #DETAIL PTS, SCF(1,2,3), NORM(SCF(1,2,3)
C
      INTEGER*2 TIME(6)
C
      INTEGER*4 IB192(25),IB96(5),IB48
C
      REAL*4 SCFLD(155),SCF(3,100),FMOD(100),DEL(100),LAM(100),
     &       FMAG192(25),FMOD192(25),DEL192(25),
     &       LAM192(25),B192(3,25),RMS192(3,25),
     &       X192(25),Y192(25),Z192(25),
     &       XRMS192(25),YRMS192(25),ZRMS192(25),
     &       FMAG96(5),FMOD96(5),DEL96(5),
     &       LAM96(5),B96(3,5),RMS96(3,5),
     &       X96(5),Y96(5),Z96(5),
     &       XRMS96(5),YRMS96(5),ZRMS96(5),
     &       FMAG48,FMOD48,DEL48,
     &       LAM48,B48(3),RMS48(3),
     &       X48,Y48,Z48,HG(3,25),
     &       SPV(6),RANGE,ANG(2),
     &       MTB(3,3),MTB5(3,3),MHG(3,3)
C
      REAL*8 TD,TN,TP
C
      INCLUDE 'UNPACK.INC'
C
      EQUIVALENCE (SUMOUT(342),SCFLD(1))
C
      EQUIVALENCE (SCFLD(148),RMS48(1)), (SCFLD(151),IB48),
     &            (SCFLD(152),X48),      (SCFLD(153),Y48),
     &            (SCFLD(154),Z48),      (SCFLD(155),FMOD48)
C
C COMPUTE DETAIL FIELD MODULUS AND ANGLES FOR 48 SECOND PERIOD
C
      CALL ANGLES(SCF,100,FMOD,DEL,LAM,BAD)
C
C COMPUTE 25 1.92 SECOND AVERAGES FOR 48 SECOND PERIOD
C
      DO I = 1,100,4
C
       J = (I-1)/4 + 1
C
C COMPUTE 1.92 SECOND FIELD COMPONENTS, MAGNITUDE AND COMPONENT RMS
C
       CALL STATS(SCF(1,I),FMOD(I),4,B192(1,J),
     &            FMAG192(J),RMS192(1,J),IB192(J),BAD)
C
      END DO     
C
C ROTATE 1.92 SECOND AVERAGES
C
      IF ( .NOT.SYS2(9) ) THEN
       CALL GETSEDR(TIME,TD,TN,TP,SPV,RANGE,ANG,MTB,MTB5,MHG)
       CALL ROTATE(HG,B192,MHG,25,BAD)
       DO I192 = 1,25
        B192(1,I192) = HG(1,I192)
        B192(2,I192) = HG(2,I192)
        B192(3,I192) = HG(3,I192)
       END DO
      END IF
C
C GENERIC AVERAGING ROUTINE TO COMPUTE 9.6 AND 48 SECOND AVERAGES
C
      DO I = 1,25,5
C
C COMPUTE 1.92 SECOND FIELD MODULUS AND ANGLES
C
       CALL ANGLES(B192(1,I),5,FMOD192(I),DEL192(I),LAM192(I),BAD)
C
       J = (I-1)/5 + 1
C
C COMPUTE 9.6 SECOND FIELD COMPONENTS, MAGNITUDE AND COMPONENT RMS
C 
       CALL STATS(B192(1,I),FMOD192(I),5,B96(1,J),FMAG96(J),RMS96(1,J),
     &            IB96(J),BAD)
C
      END DO
C
C COMPUTE 9.6 SECOND FIELD MODULUS AND ANGLES
C
      CALL ANGLES(B96,5,FMOD96,DEL96,LAM96,BAD)
C
C COMPUTE 48 SECOND FIELD COMPONENTS, MAGNITUDE AND COMPONENT RMS
C
      CALL STATS(B96,FMOD96,5,B48,FMAG48,RMS48,IB48,BAD)
C
C COMPUTE 48 SECOND FIELD MODULUS AND ANGLES
C
      CALL ANGLES(B48,1,FMOD48,DEL48,LAM48,BAD)
C
C SEPARATE FIELD AND RMS COMPONENT VECTORS FROM MATRICES
C
      DO I96 = 1,5
       X96(I96) = B96(1,I96)
       Y96(I96) = B96(2,I96)
       Z96(I96) = B96(3,I96)
       XRMS96(I96) = RMS96(1,I96)
       YRMS96(I96) = RMS96(2,I96)
       ZRMS96(I96) = RMS96(3,I96)
       DO J = 1,5
        I192 = (I96-1)*5 + J
        X192(I192) = B192(1,I192)
        Y192(I192) = B192(2,I192)
        Z192(I192) = B192(3,I192)
        XRMS192(I192) = RMS192(1,I192)
        YRMS192(I192) = RMS192(2,I192)
        ZRMS192(I192) = RMS192(3,I192)
       END DO
      END DO
      X48 = B48(1)
      Y48 = B48(2)
      Z48 = B48(3)
C
      RETURN
      END
