;+
; NAME:
;	SMEI_SEQUENCE::MAKE_MVI
;
;
; PURPOSE:
;	Saves a SMEI sequence to a LASCO MVI format movie.
;
;
; CATEGORY:
;	SMEI_SEQUENCE
;
;
; CALLING SEQUENCE:
;	seqref->make_mvi, file
;
;
; OPTIONAL INPUTS:
;	file	string	Name of the MVI file to create
;
;
; KEYWORD PARAMETERS:
;	group	long	A possible group leader (strictly dialogue
;			parent) for the menu.
;	/no_progress	If set, then disable the progress bars (useful
;			if slow network means the progress bars are
;			slowing operation).
;
;
; SIDE EFFECTS:
;	An MVI file is created
;
;
; MODIFICATION HISTORY:
;	Original: 17/12/02; SJT
;	Skip hidden images: 13/6/03; SJT
;	Add no_progress keyword: 25/8/05; SJT
;-

pro smei_sequence::make_mvi, file, group = group, no_progress = $
  no_progress

if n_params() eq 0 then file = ''
if n_elements(group) eq 0 then group = 0l

if file eq '' then begin
    sfile = dialog_pickfile(dialog_parent = group,  $
                            filter = '*.mvi', $
                            file = self -> get_file(), $
                            title = "Select file to which to write")
    if (sfile eq "") then return
endif else sfile = file

im = self -> get_first()
new = 1
n = self -> get_count()

if not widget_info(/active) or keyword_set(no_progress) then isprog = $
  0b $
else isprog = 1b


if isprog then $
  pid = cw_progress(/column, $
                    title = 'Saving frames', $
                    xsize = 200, $
                    ysize = 20, $
                    value = 0., $
                    max = n) $
else pid = 0l
ispid = widget_info(/valid, pid)

j = 0
while obj_valid(im) do begin
    if not im -> get_pflags(/skip) then begin
        im -> mvi_frame, sfile, new = new
        j = j+1
        if ispid then widget_control, pid, set_value = j
        new = 0
    endif
    im = im -> get_next()
endwhile

if ispid then widget_control, pid, /destroy

end
