      SUBROUTINE CR6AVE(GAMMA,GAMMA2,BAD,TIME)
C
C MASTER CALLING ROUTINE FOR THE PRODUCTION OF CR-6 AVERAGES
C
C ORIGINAL SOURCE BY SANDY KRAMER, HUGHES STX, CODE 692 - 03/21/96
C
      INTEGER*2 TIME(6)
C
      REAL*4 GAMMA(3,750),GAMMA2(3,375),SCF(3,750),AMBIENT(3,750)
C
      DATA SCF /2250*999.0/
C
      INCLUDE 'UNPACK.INC'
C
C GET SPACECRAFT FIELD AND AMBIENT FIELD VALUES
C
      CALL CR6FLD(GAMMA,GAMMA2,SCF,AMBIENT,TIME,BAD)
C
C DETAIL OUTPUT
C
      IF ( SYS2(4).OR.SYS2(5) ) THEN
       CALL CR6DET(GAMMA,GAMMA2,SCF,AMBIENT,TIME,BAD)
       RETURN
      END IF
C
C SINGLE MAG MODE - PRIMARY
C
      IF ( SYS2(21) .AND. (.NOT.SYS2(22)) ) THEN
       CALL CR6PRI(GAMMA,SCF,TIME,BAD)
C
C SINGLE MAG MODE - SECONDARY
C
      ELSE IF ( SYS2(22) .AND. (.NOT.SYS2(21)) ) THEN
       CALL CR6SEC(GAMMA2,SCF,TIME,BAD)
C
C SINGLE MAG MODE - PRIMARY AND SECONDARY
C
      ELSE IF ( SYS2(21) .AND. SYS2(22) ) THEN
       CALL CR6PNS(GAMMA,GAMMA2,TIME,BAD)
C
C DUAL MAG MODE
C
      ELSE IF ( (.NOT.SYS2(21)) .AND. (.NOT.SYS2(22)) ) THEN
C
C IF SYS2(27) IS TRUE, USE S/C FIELD AS AMBIENT
C
       IF (SYS2(27)) THEN
        CALL CR6PRI(SCF,SCF,TIME,BAD)
       ELSE
        CALL CR6PRI(AMBIENT,SCF,TIME,BAD)
       END IF
C
      END IF
C
      RETURN
      END
