;+
; Project     :	SOLAR-B - EIS
;
; Name        :	EIS_CPT_WRITE_INTEL_HEX_FILE
;
; Purpose     :	Writes data to intel hex file.
;
; Explanation :	Writes data to intel hex file.
;
; Use         :	< res = eis_cpt_write_intel_hex_file(file,data) >
;
; Inputs      :	file : STRING filename
;               data : BYTARR[] data values.
;
; Opt. Inputs : None.
;
; Outputs     : res    : INT FLAG indicating result
;                           1 : ok
;                           0 : not ok
;
; Opt. Outputs:	None.
;
; Keywords    : HEADER    : STRING header string for file.
;               ULBA      : UINT extended linear address
;               START_ADDRESS : UINT start address : lower 16 bits of 32 bit address.
;               NOENDOFFILE   : FLAG indicating not to output end of file record.
;               TIMESTAMP : STRING time stamp indicating should time stamp file names.
;
; Calls       : None.
;
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	None.
;
; Category    :	EIS_CPT.
;
; Prev. Hist. :	None.
;
; Written     :	Martin Carter RAL 22/10/04
;
; Modified    :	Version 0.1, 01/11/04, MKC
;                 Added HEADER keyword.
;                 Added ULBA keyword.
;              	Version 0.2, 04/11/04, MKC
;                 Added TIMESTAMP keyword.
;               Version 0.3, 07/02/05, MKC
;                 Renamed from eis ct write obstbl.
;               Version 0.4, 03/03/05, MKC
;                 Changed TIMESTAMP flag to string containing time.
;               Version 0.5, 09/03/05, MKC
;                 Incorporated TIMESTAMP within file name routine
;               Version 0.6, 17/03/05, MKC
;                 Used eis cpt file name.
;               Version 0.7, 11/04/05, MKC
;                 Renamed from  eis cpt obstbl write.
;                 Removed timestamp keyword and set up file name outside of routine.
;               Version 0.8, 13/05/05, MKC
;                 Added keyword START_ADDRESS.
;                 Added keyword NOENDOFFILE.
;
; Version     :	Version 0.8, 13/05/05
;-
;**********************************************************

FUNCTION eis_cpt_write_intel_hex_file, file, data, HEADER=header, ULBA=ulba, $
               START_ADDRESS=start_address, NOENDOFFILE=noendoffile

  ; transform data values into intel hex format
  ; this produces a BYTARR[]

  intel_hex = eis_cpt_compose_intel_hex_file ( data, HEADER=header, ULBA=ulba, START_ADDRESS=start_address, NOENDOFFILE=noendoffile )

  ; write out data

  ; open file for writing

  unit = eis_cpt_open_file(file,/WRITE)

  IF NOT KEYWORD_SET(unit) THEN GOTO, error

  ; write Hex format file

  IF NOT KEYWORD_SET(eis_cpt_write_unformatted_file(unit,intel_hex)) THEN BEGIN

    ; if error writing then close file

    dummy = eis_cpt_close_file(unit)

    GOTO, error

  ENDIF

  ; close file

  IF NOT KEYWORD_SET( eis_cpt_close_file(unit) ) THEN GOTO, error

  ; return ok

  RETURN, 1

error :

  ; issue routine name

  MESSAGE, 'ERROR', /INFORMATIONAL

  ; return error

  RETURN, 0

END





