	PRO VDS_PACK,INPUT,OUTPUT
;+
; Project     : SOHO - CDS
;
; Name        : 
;	VDS_PACK
; Purpose     : 
;	Packs 12-bit VDS values into 16 bit telemetry words.
; Explanation : 
;	Used to take VDS data and pack it into another array after the manner
;	of one of the compression schemes used on board the CDS instrument.
;	The values of OUTPUT are packed as 12 bits into 16, so that each OUTPUT
;	value contains part of two consecutive input values, and the INPUT
;	values can span across consecutive OUTPUT values.
; Use         : 
;	VDS_PACK, INPUT, OUTPUT
; Inputs      : 
;	INPUT	= Input array of VDS values.  Must be of type short integer.
;		  Must be positive integers between 0 and 4095.
; Opt. Inputs : 
;	None.
; Outputs     : 
;	OUTPUT	= Output array of packed VDS values.  For every four elements
;		  in the INPUT array, there will be three elements (six bytes)
;		  in the packed array.
; Opt. Outputs: 
;	None.
; Keywords    : 
;	None.
; Calls       : 
;	HOST_TO_IEEE
; Common      : 
;	None.
; Restrictions: 
;	None, except those described above for the INPUT array.
; Side effects: 
;	The OUTPUT array will contain a number of elements equal to a multiple
;	of three.  If necessary, this will be accomplished by padding the array
;	with zeros.
; Category    : 
;	Data Handling, Telemetry
; Prev. Hist. : 
;	None.
; Written     : 
;	William Thompson, GSFC, October 1992.
; Modified    : 
;	Version 1, William Thompson, GSFC, October 1992.
;	Version 2, William Thompson, GSFC, November 1992.
;		Rewrote to use ISHFT.
;	Version 3, William Thompson, GSFC, 24 March 1993.
;		Allowed INPUT to have an arbitrary number of elements.  Took
;		host byteordering into account.
;	Version 4, William Thompson, GSFC, 30 June 1993.
;		Added OVERWRITE keyword to REFORM to speed up.
;	Version 5, William Thompson, GSFC, 6 July 1995
;		Corrected bug where didn't work properly if input array was
;		multidimensional.
;		Corrected bug with use of HOST_TO_IEEE.
; Version     : 
;	Version 5, 6 July 1995
;-
;
	ON_ERROR,2
;
;  Check the number of parameters.
;
	IF N_PARAMS() NE 2 THEN MESSAGE, 'Syntax:  VDS_PACK, INPUT, OUTPUT'
;
;  Check the input array.
;
	SZ = SIZE(INPUT)
	TYPE = SZ(SZ(0)+1)
	IF TYPE NE 2 THEN MESSAGE, 'INPUT must be of type short integer'
	IMIN = MIN(INPUT,MAX=IMAX)
	IF (IMIN LT 0) OR (IMAX GT 4095) THEN MESSAGE,	$
		'The values of INPUT must be between 0 and 4095'
;
;  Rearrange INPUT into groups of four, padding if necessary, and define the
;  output array.  Take host byteordering into account.
;
	N = (N_ELEMENTS(INPUT) + 3) / 4
	TEMP = INTARR(4,N)
	TEMP(0) = INPUT(*)
	OUTPUT = INTARR(3,N)
;
;  Extract the output values from the input array.
;
	OUTPUT(0,0) = TEMP(0,*) OR ISHFT(TEMP(1,*) AND 'F'X, 12)
	OUTPUT(1,0) = (ISHFT(TEMP(1,*), -4) AND 'FF'X) OR	$
		ISHFT(TEMP(2,*) AND 'FF'X, 8)
	OUTPUT(2,0) = (ISHFT(TEMP(2,*), -8) AND 'F'X) OR ISHFT(TEMP(3,*), 4)
;
;  Redefine OUTPUT to be a simple string of numbers.
;
	OUTPUT = REFORM(OUTPUT,3*N,/OVERWRITE)
	HOST_TO_IEEE, OUTPUT
;
	RETURN
	END
