      SUBROUTINE BIGAVE(B192,TIME,BAD)
C
C PRODUCE 1 48 SECOND AVERAGE AND 5 9.6 SECOND AVERAGES FROM 25 1.92 SECOND
C FIELD COMPONENT AVERAGES (48 SEC PERIOD).  OUTPUT RECORD WITH TIME TAG
C FROM 48 SECOND AVERAGE MARKING THE BEGINNING OF THE AVERAGING PERIOD.
C ORIGINAL CODE  SBK 12/01/93
C REVISION 1     SBK 05/27/94
C NOTES:
C
C   TO MAINTAIN CONVENTIONS ESTABLISHED WITH THE ORIGINAL
C   VOYAGER PRODUCTION SYSTEM USED ON THE IBM MVS PLATFORM:
C
C   ALL FIELD AVERAGES WRITTEN IN THE ORDER XXX...,YYY...,ZZZ...
C   ALL FIELD RMS DATA IS WRITTEN IN THE ORDER X,Y,Z,...,X,Y,Z
C   SEDR ROTATION MATRICES MTB AND MHG ARE THE TRANSPOSE OF THOSE
C   DESCRIBED IN THE ORIGINAL VOYAGER SEDR DESCRIPTION.  THESE 
C   MATRICES ARE PROPERLY OPERATED UPON WITHIN THE CODE.
C
      CHARACTER DATAID*4
C
      INTEGER*2 TIME(6),SEDRTIME(6),AVETIME(6),
     &          DUMMTIME(6),CURRYEAR(6),
     &          WORD32(2),DATATYPE(2)
C
      INTEGER*4 IB192(25),IB96(5),IB48
C
      REAL*4 GAMMA(3,400),FMOD(400),DEL(400),LAM(400),
     &       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
C
      REAL*4 HDR(32),DATA(341),SCFLD(155),POSN(13),ATTD(27),
     &       HOLD(27)
C
      REAL*4 SPV(6),RANGE,ANG(2),HG(3,25),
     &       MTB(3,3),MTB5(3,3),MHG(3,3)
C
      REAL*8 DD,TD,TN,TP
C
      INCLUDE 'UNPACK.INC'
C
      EQUIVALENCE (SUMOUT(1),HDR(1)),    (SUMOUT(33),DATA(1)),  
     &            (SUMOUT(342),SCFLD(1)),
     &            (SUMOUT(529),POSN(1)), (SUMOUT(542),ATTD(1))  
C
      EQUIVALENCE (HDR(1),DATAID),       (HDR(4),AVETIME(1)),
     &            (HDR(7),DD),           (HDR(9),TD),
     &            (HDR(12),TIMEPD),      (HDR(17),DATATYPE(1)),
     &            (HDR(32),WORD32(1))
C
      EQUIVALENCE (DATA(1),FMAG48),      (DATA(2),FMOD48),
     &            (DATA(3),DEL48),       (DATA(4),LAM48),     
     &            (DATA(5),X48),         (DATA(6),Y48),
     &            (DATA(7),Z48),         (DATA(8),RMS48(1)),
     &            (DATA(11),IB48),       (DATA(12),FMAG96(1)),
     &            (DATA(17),FMOD96(1)),  (DATA(22),DEL96(1)),  
     &            (DATA(27),LAM96(1)),   (DATA(32),X96(1)),
     &            (DATA(37),Y96(1)),     (DATA(42),Z96(1)),
     &            (DATA(47),RMS96(1,1)), (DATA(62),IB96(1)),
     &            (DATA(67),FMAG192(1)), (DATA(92),FMOD192(1)),
     &            (DATA(117),DEL192(1)), (DATA(142),LAM192(1)),
     &            (DATA(167),X192(1)),   (DATA(192),Y192(1)),
     &            (DATA(217),Z192(1)),   (DATA(242),RMS192(1,1)),
     &            (DATA(317),IB192(1))
C
      EQUIVALENCE (POSN(1),TN),          (POSN(3),TP),
     &            (POSN(5),SPV(1)),      (POSN(11),RANGE),
     &            (POSN(12),ANG(1))
C
      EQUIVALENCE (ATTD(1), MTB(1,1)),   (ATTD(10),MTB5(1,1)),
     &            (ATTD(19), MHG(1,1))
C
C COUNT 48 SECOND SUMMARY OUTPUT RECORDS
C
      RECWRITE = RECWRITE + 1
C
      DATAID = 'LFM '
      DO IT = 1,6
       AVETIME(IT) = TIME(IT)
      END DO
      TIMEPD = 48.0
      DATATYPE(1) = 1
      WORD32(1) = RECWRITE
      WORD32(2) = 536
C
C COMPUTE DECIMAL DAY OF CURRENT YEAR
C
      CURRYEAR(1) = TIME(1)
      CURRYEAR(2) = 1
      CURRYEAR(3) = 0
      CURRYEAR(4) = 0
      CURRYEAR(5) = 0
      CURRYEAR(6) = 0
      CALL ELPSTIME(CURRYEAR,TIME,DD)
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
C OUTPUT MAG SUMMARY FILE
C
      WRITE(66) SUMOUT
C
C OUTPUT 1.92 SECOND AVERAGES
C
      IF (SYS2(1)) THEN
       DO I = 1,25
        WRITE(82,888) TIME,FMAG192(I),FMOD192(I),(B192(J,I),J=1,3),
     &                DEL192(I),LAM192(I),(RMS192(J,I),J=1,3),IB192(I)
       END DO
C
C OUTPUT 48 SECOND AVERAGES
C
      ELSE IF (SYS2(2)) THEN
        WRITE(83,888) TIME,FMAG48,FMOD48,B48,DEL48,LAM48,RMS48,IB48
      END IF
C
      RETURN
C
  888 FORMAT(1X,I2,1X,I3.3,3(1X,I2.2),1X,I3.3,5(1X,F7.3),
     &       2(1X,F5.1),3(1X,F7.3),1X,I2)
C
      END
