;+
; NAME:
;	SMEI_IMAGE_HEADER
;
;
; PURPOSE:
;	Gets the FITS header from a SMEI_IMAGE
;
;
; CATEGORY:
;	CLI
;
;
; CALLING SEQUENCE:
;	smei_image_header, imref, header[, /fitshead]
;	or
;	smei_image_header, seqref, header, index=index[, /fitshead]
;
;
; INPUTS:
;	imref	objref	Object reference to the image object
;
;
; OPTIONAL INPUTS:
;	seqref	objref	Object reference to the SMEI_SEQUENCE
;			containing the image to be extracted.
;
;
; KEYWORD PARAMETERS:
;	index	long	Image index (1-based) used when the first
;			argument is a sequence
;	/fitshead	If set, then return a string array FITS
;			header, rather than a structure.
;
; OUTPUTS:
;	header	struct|string	A named variable to receive the header.
;
;
; RESTRICTIONS:
;	If the source is a sequence, then the index keyword must be
;	used. If it is an image then index is ignored.
;
;
; MODIFICATION HISTORY:
;	Original (after SMEI_IMAGE_IMAGE): 8/1/03; SJT
;	Fix clot error: 18/6/03; SJT
;-

pro smei_image_header, source, header, index = index, fitshead = $
                       fitshead, help = help

if keyword_set(help) then begin
    self_help
    return
endif


if not arg_present(header) then begin
    smei_msg, /warn, ['SMEI_IMAGE_HEADER must have 2 arguments,', $
                      'the second must be writable']
    return
endif

if not obj_valid(source) then begin
    smei_msg, /warn, ['The specified source for the image must be', $
                      'a valid object reference']

    return
endif

if obj_isa(source, 'SMEI_SEQUENCE') then begin

    if n_elements(index) eq 0 then begin
        smei_msg, /warn, ['If the source in SMEI_IMAGE_HEADER is a', $
                          'sequence then the INDEX keyword must be given']
        return
    endif
    if index lt 1 or index gt source -> get_count() then begin
        smei_msg, /warn, 'The image number is out of range'
        return
    endif

    img = source -> get_image(index-1)
endif else if obj_isa(source, 'SMEI_IMAGE') then img = source $
else begin
    smei_msg, /warn, ['The source argument of SMEI_IMAGE_HEADER must ' + $
                      'be', $
                      'a SMEI_IMAGE or a SMEI_SEQUENCE']
    return
endelse

header = img -> get_header(fitshead = fitshead)

end
