;+
; NAME:
;	SMEI_IMAGE_BLOCK
;
;
; PURPOSE:
;	Gets the actual image data from a SMEI_SEQUENCE as a 3-D array
;
;
; CATEGORY:
;	CLI
;
;
; CALLING SEQUENCE:
;	smei_image_image, seqref, image, [, /raw]
;
;
; INPUTS:
;	seqref	objref	Object reference to the SMEI_SEQUENCE
;			containing the image to be extracted.
;
;
; KEYWORD PARAMETERS:
;	plane	int	If set, then select the specified 1-based
;			plane of the raw image.
;	flag	int	If set, then extract the image flag data.
;			1: Flags for the current orbit astrometry
;			2: Flags for the next orbit astrometry
;	/time		If set, then extract the times from the
;			ancillary data
;	/longitude	If set, then extract the s/c longitude from
;			the ancillary data
;	/latitude	If set, then extract the s/c latitude from the
;			ancillary data
;
; OUTPUTS:
;	image	float	A named variable to receive the image data.
;
; NOTES:
; 	Unlike SMEI_IMAGE_IMAGE, this routine cannot get multi-plane
; 	values, i.e. you can't get both flag planes or all raw planes.
;
; MODIFICATION HISTORY:
;	Original (after SMEI_IMAGE_IMAGE): 8/1/03; SJT
;-

pro smei_image_block, source, image, plane = $
                      plane, flag = flag, time = time, longitude = $
                      longitude, latitude = latitude, help = help

if keyword_set(help) then begin
    self_help
    return
endif

if not arg_present(image) then begin
    smei_msg, /warn, ['SMEI_IMAGE_BLOCK 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
    smei_msg, /warn, ['The source argument of SMEI_IMAGE_BLOCK must ', $
                      'be a SMEI_SEQUENCE']
    return
endif

; Determine the size of the output block.

n_images = source -> get_count()
sz =  source -> get_biggest_image()

if (keyword_set(flag)) then image = uintarr([sz, n_images]) $
else image = fltarr([sz, n_images])

img = source -> get_first()
for j = 0, n_images-1 do begin
    if keyword_set(flag) then case flag of
        2: image[*, *, j] = img -> get_flag_data(/next)
        1: image[*, *, j] = img -> get_flag_data(/current)
        else: begin
            smei_msg, /warn, 'Invalid flag selection, using FLAG=1'
            image[*, *, j] = img -> get_flag_data(/current)
        end
    endcase else if keyword_set(time) then $
      image[*, *, j] = img -> get_ancil(/time) $
    else if keyword_set(longitude) then $
      image[*, *, j] = img -> get_ancil(/longitude)  $
    else if keyword_set(latitude) then $
      image[*, *, j] = img -> get_ancil(/latitude) $
    else if keyword_set(plane) then $
      image[*, *, j] = img -> get_raw_image(plane = plane) $
    else image[*, *, j] = img -> get_image()

    img = img -> get_next()
endfor
  
    
end
