;+
; NAME:
;	SMEI_IMAGE_PRINT
;
;
; PURPOSE:
;	Send a SMEI_IMAGE to a PostScript file.
;
;
; CATEGORY:
;	CLI
;
;
; CALLING SEQUENCE:
;	smei_image_print, image[, <option keys>]
;	or
;	smei_image_print, seqref, index=index[, <option keys>]
;
;
; INPUTS:
;	image	objref	Reference to the SMEI_IMAGE to be printed.
;
;
; 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
;	/menu		If specified then use a widget interface to
;			set up the print settings. If this is given,
;			then any keywords listed below are ignored.
;	/grid		If specfied, then add a grid to the image
;	/nodate		If specified, then do not add the date and
;			time range of the image
;	/file		If specified, then add the filename to the
;			image.
;	range	float	The min and max values for the display
;			(implies adding the range to the plot)
;	colour_table int The colour table to use. (-1 or unset to use
;			the sequence map)
;	xsize	float	The size in cm of the x-dimension of the image
;			(y is always adjusted to preserve the aspect
;			ratio)
;	/no_colour	Do not generate colour PS (equivalent to
;			colour_table=0)
;	/portrait	Print in portrait mode (default is landscape).
;	plot_file str	Specify a filename other than the default idl.ps
;	/encapsulated	If set, then make an eps file (handled
;			explicitly as other things are done
;			differently for eps).
;
;	Any keywords to DEVICE that do not clash with the above and
;	which are accepted by the PS device may be passed.
;
;
; MODIFICATION HISTORY:
;	Original: 9/1/03; SJT
;-

pro smei_image_print, source, index = index, menu = menu, _extra = $
                      _extra, help = help

if keyword_set(help) then begin
    self_help
    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_PRINT 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 = seq -> 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_PRINT must ', $
                      'be a SMEI_IMAGE or a SMEI_SEQUENCE']
    return
endelse

if keyword_set(menu) then img -> print_menu $
else img -> print, _extra = _extra

end
