#! @TCL@ -f
# File: dec_file_0.tcl
#

# procedure to put the data files in dummy files
#
proc make_tmp_proc {} {

    # declare globals
    #
    global mfcc_file
    global tmp_infile
    global wordlist_file
    global nbest_file
    global tmp_outfile
    global tmp_outnbestfile
    global lattice_file
    global tmp_latfile
    global lm_file
    global tmp_lmfile
    global mfcc_format

    global num_frames

    # place the output file in a dummy list file, if an output file exists
    # remove it
    #
    if {[file exists $wordlist_file] == 1} {
	exec rm $wordlist_file
    }
    set fileptr [open $tmp_outfile w]
    puts $fileptr $wordlist_file
    close $fileptr

    # place the output nbest file in a dummy list file, if an output
    # nbest file exists remove it
    #
    if {[file exists $nbest_file] == 1} {
	exec rm $nbest_file
    }
    set fileptr [open $tmp_outnbestfile w]
    puts $fileptr $nbest_file
    close $fileptr

    # open the input file and count the number of lines if this is ascii mode
    #
    if {$mfcc_format == "ascii"} {
	set num_frames 0
	set fileptr [open $mfcc_file r]
	while {[gets $fileptr line] >= 0} {
	
	    # make sure this is not a comment or a blank line
	    #
	    set line [string trim $line]
	    if {($line != "") && ([string index $line 0] != "#")} {
		incr num_frames
	    }
	
	}
	close $fileptr    
    } else {

	# use file size divide by 39 features and 8 byte per feature
	# to estimate the number of frames
	#
	set num_frames [expr [file size $mfcc_file]/(8*39)]
    }
    puts "num frame : $num_frames"

    # place the input file in a dummy list file
    #
    set fileptr [open $tmp_infile w]
    puts $fileptr $mfcc_file
    close $fileptr

    # place the lattice file in a dummy list file
    #
    set fileptr [open $tmp_latfile w]
    puts $fileptr $lattice_file
    close $fileptr



    # place the lattice file in a dummy list file
    #
    set fileptr [open $tmp_lmfile w]
    puts $fileptr $lm_file
    close $fileptr

}

# end of file
#
