	PRO SENSOR_DECODE, SENSOR, BITS, MAGNITUDE, RANGE, MAP=MAP
;+
; Project     :	SOHO - CDS
;
; Name        :	SENSOR_DECODE
;
; Purpose     :	Decode MCU telemetry format for sun sensor pitch or yaw.
;
; Explanation :	This procedure takes the sun sensor pitch or yaw magnitude in
;		MCU telemetry format, and extracts the status bits and
;		magnitude value.
;
; Use         :	SENSOR_DECODE, SENSOR, BITS, MAGNITUDE [, RANGE]  [, /MAP ]
;
; Inputs      :	SENSOR	  = Short integer input scalar or array containing the
;			    telemetry bits corresponding to the sun sensor
;			    pitch or yaw magnitude.
;
; Opt. Inputs :	None.
;
; Outputs     :	BITS	  = The status bits in one of two formats:
;
;				* Character string containing the status bits
;				  as ones and zeros.  This is the default, and
;				  is suitable for use in FITS header.
;
;				* Byte variable with the status bits shifted
;				  all the way to the right.  Requires the /MAP
;				  keyword.  Suitable for use with FITS binary
;				  table bit array fields.
;
;		MAGNITUDE = The sun sensor pitch or yaw magnitude.
;
; Opt. Outputs:	RANGE	  = The sun sensor auto-range gain selected, either 0
;			    (4X) or 1 (1X).
;
; Keywords    :	MAP	  = If set, then the format of the BITS output variable
;			    is changed.
;
; Calls       :	None.
;
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	None.
;
; Category    :	Data_handling, I/O, Telemetry.
;
; Prev. Hist. :	None.
;
; Written     :	William Thompson, GSFC, 16 December 1993.
;
; Modified    :	Version 1, William Thompson, GSFC, 16 December 1993.
;		Version 2, William Thompson, GSFC, 30 August 1994
;			Added optional RANGE parameter.
;
; Version     :	Version 2, 30 August 1994
;-
;
	ON_ERROR, 2
;
;  Check the number of parameters.
;
	IF N_PARAMS() LT 3 THEN MESSAGE,	$
		'Syntax:  SENSOR_DECODE, SENSOR, BITS, MAGNITUDE  [, RANGE ]'
;
;  Make sure that the input is of the correct type.
;
	IF DATATYPE(SENSOR,1) NE 'Integer' THEN MESSAGE,	$
		'SENSOR must be a short integer'
;
;  Extract the status bits, 0 through 3.
;
	IF KEYWORD_SET(MAP) THEN BEGIN
		BITS = BYTE(ISHFT(SENSOR,-12))
	END ELSE BEGIN
		DEC2BIN, SENSOR, SENSORBITS, /QUIET
		BITS = STRTRIM(FIX(SENSORBITS(0)),2)
		FOR I = 1,3 DO BITS = BITS + STRTRIM(FIX(SENSORBITS(I)),2)
	ENDELSE
;
;  Extract the unsigned magnitude, bits 4 through 15.
;
	MAGNITUDE = SENSOR AND 'FFF'X
;
;  Extract the auto-range gain, bit 0.
;
	RANGE = BYTE(ISHFT(SENSOR,-15))
;
	RETURN
	END
