;+
; NAME:
;	SMEI_SUBTRACT_MODEL
;
;
; PURPOSE:
;	Subtract a background model from a SMEI sequence.
;
;
; CATEGORY:
;	CLI
;
;
; CALLING SEQUENCE:
;	smei_subtract_model, seqref, model
;
;
; INPUTS:
;	seqref	object	The smei_sequence object on which to operate.
;	model	string	The model identifier for the model to subtract.
;
; KEYWORD PARAMETERS:
;	plane	int	An optional specification of which plane of
;			the model to use. This should only be used for
;			diagnostic purposes to subtract only the
;			stellar or only the solar components.
;	/restore	If set, then restore the original processed
;			image.
;	path	string	The path to the model files, if not the
;			default.
;
;
; SIDE EFFECTS:
;	The processed image is updated.
;
;
; RESTRICTIONS:
;	Cannot be used on compacted images.
;
;
; MODIFICATION HISTORY:
;	Original: 25/5/04; SJT
;	Add restore key: 23/9/04; SJT
;	Add PATH & PLANE keys: 19/11/10; SJT
;-

pro smei_subtract_model, seq, model, restore = restore, plane = plane, $
                         path = path, help = help

if keyword_set(help) then begin
    self_help
    return
endif

if not obj_valid(seq) then begin
    smei_msg, /alert, 'The specfied sequence is not a valid object'
    return
endif

if not obj_isa(seq, 'SMEI_SEQUENCE') then begin
    smei_msg, /alert, 'The specified sequence is not a SMEI_SEQUENCE'
    return
endif

if seq -> get_n_planes() lt 2 then begin
    smei_msg, /alert, ['Cannot subtract models from sequences with', $
                       'fewer than 2 raw data planes']
    return
endif
 
if (keyword_set(restore) && (keyword_set(path) || $
                             keyword_set(plane))) then begin 
    smei_msg, /inform, "The PATH & PLANE keys are ignored if RESTORE is " + $
      "set"
endif else if (keyword_set(plane)) then begin
    smei_msg, /warn, "The PLANE keyword is only intended for testing"
    ans = ''
    read, "Do you really mean to do that? (Y/n) :_",  ans
    ans = strupcase(ans)
    if (ans eq 'N' || ans eq 'NO') then return
endif

if keyword_set(restore) then seq -> subtract_model, /restore $
else seq -> subtract_model, model, path = path, plane = plane

end
