      SUBROUTINE CR1AVE(GAMMA,GAMMA2,BAD,TIME)
C
C MASTER CALLING ROUTINE FOR THE PRODUCTION OF CR-1 AVERAGES
C 
C WRITTEN BY S. B. KRAMER  10/04/95
C
      INTEGER*2 TIME(6)
C
      REAL*4 GAMMA(3,800),GAMMA2(3,800),SCF(3,800),AMBIENT(3,800)
C
      DATA SCF /2400*999.0/
C
      INCLUDE 'UNPACK.INC'
C
C GET SPACECRAFT FIELD AND AMBIENT FIELD VALUES
C
      CALL CR1FLD(GAMMA,GAMMA2,SCF,AMBIENT,TIME,BAD)
C
C DETAIL OUTPUT
C
      IF ( SYS2(4).OR.SYS2(5) ) THEN
       CALL CR1DET(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 CR1PRI(GAMMA,SCF,TIME,BAD)
C
C SINGLE MAG MODE - SECONDARY
C
      ELSE IF ( (.NOT.SYS2(21)) .AND. SYS2(22) ) THEN
       CALL CR1PRI(GAMMA2,SCF,TIME,BAD)
C
C SINGLE MAG MODE - PRIMARY AND SECONDARY
C
      ELSE IF ( SYS2(21) .AND. SYS2(22) ) THEN
       CALL CR1PRI(GAMMA,GAMMA2,TIME,BAD)
C
C DUAL MAG MODE - AMBIENT AND SPACECRAFT FIELDS
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 CR1PRI(SCF,SCF,TIME,BAD)
       ELSE
        CALL CR1PRI(AMBIENT,SCF,TIME,BAD)
       END IF
C
      END IF
C
      RETURN
      END
