#! @TCL@ -f
#
# file: dec_reset.tcl
#

# this procedure resets the program cleanly
#
proc reset_proc {} {

    # import globals
    #
    global current_frame
    global num_frames
    global num_step

    global traces_new
    global traces_del
    global traces_tot

    global pipe_flag
    global decoder_pipe
    global wordlist_file
 
    # reset the counts
    #
    set traces_new 0
    set traces_del 0
    set traces_tot 0

    # close the decoder pipe
    # 
    if {($pipe_flag == 1) && ($current_frame < $num_frames)} { 
	catch {
	    puts $decoder_pipe "-1\n"
	    flush $decoder_pipe
	    close $decoder_pipe
	}
	set pipe_flag 0
    }

    # set the current frame to full count
    #
    set current_frame -1

    # reset step size
    #
    set num_step $num_step

    # remove the output file
    #
    if {[file exists $wordlist_file] == 1} {
	exec rm $wordlist_file
    }

    # get ready to restart
    #
    restart_proc

    # update the display
    #
    plot_data_proc

}

# procedure to restart things
#
proc restart_proc {} {

    # declare globals
    #
    global old_num_n_best
    global num_n_best

    # make sure that the parameters haven't changed
    #
    if {$num_n_best != $old_num_n_best} {
	
	# set new parameters
	#
	set old_num_n_best $num_n_best

	# reset
	#
	reset_proc
    }
}

# end of file
#
