******************************************************************
*
*	TITLE:  CONVERT RECONSTRUCTED DIGITAL VALUES INTO GAMMAS
*
*	FILE NAME:  CR6LFM.FOR
*
*	PURPOSE:  TO CONVERT DIGITAL CR-6 MAG SCIENCE DATA
*
*	HISTORY:
*
*	AUTHOR            DATE            CHANGE
*	--------          ----            -------
*       S. B. KRAMER     03/21/96         ORIGINAL CODE
*                                         (MODE CR-6)
*
*
*	COMMON AREAS:
*
*		SEE UNPACK.INC FOR COMMON AREA DEFINITIONS
*
*	NOTES:
*
*          CR-6 FORMAT LACKS MAG STATUS 2 WORDS.  ONLY INSTRUMENT
*          RANGE AND MODE AVAILABLE.
*
*	PDL:
*
*	   CALL COMMAND AND STATUS WORD EXTRACTION ROUTINE
*          CALL DELTA MODULATION RECONSTRUCT ROUTINES
*	   CALL COUNTS TO GAMMAS CONVERSION ROUTINE
*	   CALL SENSOR ALIGNMENT ROUTINE
*	   CALL BOOM ALIGNMENT ROUTINE
*
*	RETURN
*
******************************************************************
      SUBROUTINE CR6LFM(GAMMA,GAMMA2,BAD,TIME)
C
C CR-6 MASTER ROUTINE TO PRODUCE GAMMAS FOR BIGAVE
C
      INTEGER*2 TIME(6)
      LOGICAL*1 SROTATE,BROTATE,INBOARD
      REAL*4 GAMMA(3,750),GAMMA2(3,375)
C
      INCLUDE 'UNPACK.INC'
C
      DATA SROTATE/.TRUE./,
     &     BROTATE/.TRUE./,
     &     ICALL/0/
C
      ICALL = ICALL + 1
C
C SENSOR ROTATION SWITCH
C
      IF ( SYS2(13) ) SROTATE = .FALSE.
C
C BOOM ALIGNMENT ROTATION SWITCH
C
      IF ( SYS2(23) ) BROTATE = .FALSE.
C
C EXTRACT INSTRUMENT STATUS FROM STAT WORDS
C
      CALL MAGSTATUS(TIME,10,0)
C
C NO MAG STATUS 2 WORDS AVAILABLE IN CR-6 
C
      IF ( SYS2(24) ) THEN
       INBOARD = .TRUE.
      ELSE
       INBOARD = .FALSE.
      END IF
C
C RECOVER 12 BIT PREDICTED WORDS
C
      CALL DELTA(PDELTA,750,PREF,25,PREC)
      CALL DELTA(SDELTA,375,SREF,25,SREC)
C
C ADJUST LEVEL OF RECONSTRUCTED PREDICT WORDS
C
      CALL SHIVOT(PREF,25,PREC,750,SYS2(8))
      CALL SHIVOT(SREF,25,SREC,375,SYS2(8))
C
C CONVERT COUNTS INTO GAMMAS (MODE SENSITIVE)
C
      CALL MAKEGAMMAS(GAMMA,750,GAMMA2,375,10,0,BAD,TIME)
C
C ORTHOGONALIZE DATA WITH SENSOR MATRIX AFTER GAMMAS (MODE SENSITIVE)
C
      IF ( SROTATE ) CALL SENSOR_ALIGN(GAMMA,GAMMA2,750,375,0,BAD)
C
C ROTATE DATA WITH BOOM ALIGNMENT MATRIX AFTER GAMMAS (MODE SENSITIVE)
C
      IF ( BROTATE ) CALL BOOM_ALIGN(GAMMA,GAMMA2,750,375,0,BAD)
C
      RETURN
      END
