      SUBROUTINE CR4SCF(SCF,TIME,BAD)
C
C COMPUTE 48 SECOND AVERAGED SPACECRAFT FIELD FOR CR-4 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
C ORIGINAL SOURCE WRITTEN BY SANDY KRAMER, HUGHES STX, CODE 692  03/26/96
C
      INTEGER*2 TIME(6)
      INTEGER*4 IB192(25),IB96(5),IB48
C
      REAL*4 SCF(3,160),FMOD(160),DEL(160),LAM(160),SCFLD(155),
     &       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,5),
     &       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 
C
      CALL ANGLES(SCF,160,FMOD,DEL,LAM,BAD)
C
C COMPUTE 5 9.6 SECOND AVERAGES FOR 48 SECOND PERIOD
C
      DO J = 1,5
C
C 160 PRIMARY GAMMAS PER 48 SECOND PERIOD THEREFORE
C 32 PRIMARY GAMMAS PER 9.6 SECOND AVERAGE
C
       I = (J-1)*32 + 1
C
C COMPUTE 9.6 SECOND FIELD COMPONENTS, MAGNITUDE AND COMPONENT RMS
C
       CALL STATS(SCF(1,I),FMOD(I),32,B96(1,J),
     &            FMAG96(J),RMS96(1,J),IB96(J),BAD)
C
      END DO     
C
C ROTATE 9.6 SECOND AVERAGES
C
      IF ( .NOT.SYS2(9) ) THEN
       CALL GETSEDR(TIME,TD,TN,TP,SPV,RANGE,ANG,MTB,MTB5,MHG)
       CALL ROTATE(HG,B96,MHG,5,BAD)
       DO I96 = 1,5
        B96(1,I96) = HG(1,I96)
        B96(2,I96) = HG(2,I96)
        B96(3,I96) = HG(3,I96)
       END DO
      END IF
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
