;+
; Project     :	SOLAR-B - EIS
;
; Name        :	EIS_CPT_READ_UNFORMATTED_FILE
;
; Purpose     :	Reads an unformatted file into a byte array.
;
; Explanation :	If read fails then returns 0.
;               NB This routine does not work under VMS since VMS files contain a 2byte record-length descriptor.
;               NB This routine does not work with compressed files.
;
; Use         :	< res = eis_cpt_read_unformatted_file(unit,data) >
;
; Inputs      :	unit : LONG logical unit number for file.
;
; Opt. Inputs : None.
;
; Outputs     : res    : INT FLAG indicating result
;                           1 : ok
;                           0 : not ok
;               data     : BYTARR[] data values.
;
; Opt. Outputs:	None.
;
; Keywords    : None.
;
; Calls       : None.
;
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	None.
;
; Category    :	EIS_CPT.
;
; Prev. Hist. :	None.
;
; Written     :	Martin Carter RAL 15/10/04
;
; Modified    :	Version 0.0, 15/10/04, MKC
;               Version 0.1, 04/03/05, MKC
;                 Changed so that returns data through arguments and an
;                 error code through function call.
;
; Version     :	Version 0.1, 04/03/05
;-
;**********************************************************

FUNCTION eis_cpt_read_unformatted_file, unit, data

  ON_IOERROR, io_error

  ; get file info

  file_info = FSTAT(unit)

  ; check file not compressed

  IF file_info.compress NE 0 THEN GOTO, io_error

  ; check file size

  IF file_info.size LE 0 THEN GOTO, io_error

  ; set up byte array

  data = BYTARR(file_info.size)

  ; read data

  READU, unit, data

  ; return OK

  RETURN, 1

io_error :

  ; issue routine name

  MESSAGE, 'ERROR', /INFORMATIONAL

  ; return error

  eis_cpt_message, 'INVALID UNFORMATTED FILE'

  RETURN, 0

END





