;+
; Project     :	SOLAR-B - EIS
;
; Name        :	EIS_CPT_ULONGTOBYTES
;
; Purpose     :	Converts ULONG array to big endian BYTE array.
;
; Explanation :	Arranges BYTE data values MSByte first.
;               If fails then sets error.
;
; Use         :	< byte_array = eis_cpt_ulongtobytes(unit_array) >
;
; Inputs      :	uint_array : ULONGARR[n] ulong values.
;
; Opt. Inputs : None.
;
; Outputs     : byte_array : BYTARR[4n] byte values.
;
; Opt. Outputs:	None.
;
; Keywords    : None.
;
; Calls       : None.
;
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	Loses any extra dimensions of input array.
;
; Category    :	EIS_CPT.
;
; Prev. Hist. :	None.
;
; Written     :	Martin Carter RAL 18/10/04
;
; Modified    :	Version 0.0, 18/10/04, MKC
;
; Version     :	0.0, 18/10/04
;-
;**********************************************************

FUNCTION eis_cpt_ulongtobytes, ulong_array

  ; ensure uint

  ulong_array = ULONG(ulong_array)

  ; get size of input

  nulong = N_ELEMENTS(ulong_array)

  ; form byte array

  byte_array = BYTARR(4,nulong)

  byte_array[0,*] = ISHFT(ulong_array,-24)

  byte_array[1,*] = ISHFT(ulong_array,-16)

  byte_array[2,*] = ISHFT(ulong_array,-8)

  byte_array[3,*] = ulong_array

  ; this cannot be tested on big endian machine

  ;byte_array = BYTE(ulong_array,0,4*nulong)

  ;BYTEORDER, byte_array, /SWAP_IF_LITTLE_ENDIAN

  ; return array

  RETURN, REFORM(byte_array,4*nulong)

END





