      SUBROUTINE GS3AVE(GAMMA,GAMMA2,BAD,TIME)
C
C MASTER CALLING ROUTINE FOR THE PRODUCTION OF GS-3 AVERAGES
C
C ORIGINAL SOURCE WRITTEN BY SANDY KRAMER, HUGHES STX, CODE 692  07/05/94
C
      INTEGER*2 TIME(6)
C
      REAL*4 GAMMA(3,800),GAMMA2(3,400),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 GS3FLD(GAMMA,GAMMA2,SCF,AMBIENT,TIME,BAD)
C
C DETAIL OUTPUT
C
      IF ( SYS2(4).OR.SYS2(5) ) THEN
       CALL GS3DET(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 GS3PRI(GAMMA,SCF,TIME,BAD)
C
C SINGLE MAG MODE - SECONDARY
C
      ELSE IF ( (.NOT.SYS2(21)) .AND. SYS2(22) ) THEN
       CALL GS3SEC(GAMMA2,SCF,TIME,BAD)
C
C SINGLE MAG MODE - PRIMARY AND SECONDARY
C
      ELSE IF ( SYS2(21) .AND. SYS2(22) ) THEN
       CALL GS3PNS(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 GS3PRI(SCF,SCF,TIME,BAD)
       ELSE
        CALL GS3PRI(AMBIENT,SCF,TIME,BAD)
       END IF
C
      END IF
C
      RETURN
      END
