      SUBROUTINE CR4FLD(GAMMA,GAMMA2,SCF,AMBIENT,TIME,BAD)
C
C USING 48 SECOND CR-4 EDR RECORD, INTERPOLATE SECONDARY MAG 
C DETAIL (2.40 SEC) DATA POINTS TO PRIMARY MAG DETAIL RATE (0.30 SEC) 
C TO COMPUTE SPACECRAFT AND AMBIENT FIELDS.  
C
C ORIGINAL SOURCE WRIITEN BY SANDY KRAMER, HUGHES STX, CODE 692  03/26/96
C MODIFIED TO INTERPOLATE MISSING S/C FIELD - SBK  04/09/96
C
      INTEGER*2 TIME(6)
C
      REAL*4 GAMMA(3,640),GAMMA2(3,80),SCF(3,640),AMBIENT(3,640),
     &       SCFHOLD(3)
C
C     IMPLEMENT SPACECRAFT FIELD COUPLING COEFFICIENT, ALPHA, 
C     IN COMPUTATION OF S/C FIELD
C
C     COEF = ALPHA/(1.0-ALPHA)  WHERE ALPHA = .1846
C          = 0.230921
C
      DATA ALPHA/0.1876/,COEF/0.230921/
C
      INCLUDE 'UNPACK.INC'
C
      DO I=1,640
C
C STEP INTERPOLATE 2.40 SECOND CR-4 SECONDARY MAG DATA TO 0.30 SECOND PRIMARY 
C MAG RATE
C
       ISEC = (I-1)/8 + 1
       DO J = 1,3
C
C COMPUTER DIFFERENCE BETWEEN PRIMARY AND SECONDARY MAGNETOMETERS
C
        IF ( GAMMA(J,I).NE.BAD .AND.
     &       GAMMA2(J,ISEC).NE.BAD ) THEN
         SCF(J,I) = (GAMMA2(J,ISEC)-GAMMA(J,I))*COEF
         SCFHOLD(J) = SCF(J,I) ! HOLD NON-FILL SCF VALUE
        ELSE
         SCF(J,I) = BAD
        END IF
C
C COMPUTE AMBIENT FIELD FOR RETURN AT PRIMARY MODE RATE
C
        IF ( GAMMA(J,I).NE.BAD .AND. SCF(J,I).NE.BAD ) THEN
         AMBIENT(J,I) = GAMMA(J,I) - SCF(J,I)
        ELSE IF ( GAMMA(J,I).NE.BAD .AND. SCF(J,I).EQ.BAD ) THEN
         AMBIENT(J,I) = GAMMA(J,I) - SCFHOLD(J)
        ELSE
         AMBIENT(J,I) = BAD
        END IF
C
       END DO
C
      END DO
C
      RETURN
      END
