;+
; Project     :	SOLAR-B - EIS
;
; Name        :	EIS_CPT_BYTESTOULONG
;
; Purpose     :	Converts big endian BYTE array to ULONG array.
;
; Explanation :	BYTE data values are MSByte first.
;               If fails then sets error.
;
; Use         :	< ulong_array = eis_cpt_bytestoulong(byte_array) >
;
; Inputs      :	byte_array : BYTARR[4n] byte values.
;
; Opt. Inputs : None.
;
; Outputs     : ulong_array : ULONARR[n] ulong 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, 27/06/05, MKC
;
; Version     :	Version 0.0, 27/06/05
;-
;**********************************************************

FUNCTION eis_cpt_bytestoulong, byte_array

  ; ensure bytes

  byte_array = BYTE(byte_array)

  ; get size of input

  nbytes = N_ELEMENTS(byte_array)

  ; check byte array is sensible size

  IF (nbytes MOD 4) NE 0 THEN eis_cpt_message, 'INVALID BYTE ARRAY FOR CONVERSION'

  ; this works slower but always

  array = ULONG(REFORM(byte_array,4,nbytes/4))

  ulong_array = REFORM(array[3,*] OR ISHFT(array[2,*],8) OR ISHFT(array[1,*],16) OR ISHFT(array[0,*],24))

  ; this should work but cannot be tested on big endian machine

  ; reform array

  ;ulong_array = ULONG(byte_array, 0, nbytes/4)

  ; swap byte ordering unless processor is big endian

  ;BYTEORDER, ulong_array, /SWAP_IF_LITTLE_ENDIAN

  ; return ULONG array

  RETURN, ulong_array

END





