#! @TCL@ -f

# file: dec_write_0.tcl
#

# procedures to write the parameters into file
#

# procedure to open and read file
#
proc write_proc {filename} {

    # declare globals
    #
    global function_mode
    global data_dir
    global monophones_file
    global transitions_file
    global states_file
    global models_file
    global phones_file
    global lexicon_file
    global lm_file
    global transcription_file

    global tmp_outfile
    global tmp_outnbestfile
    global tmp_infile
    global tmp_latfile
    global tmp_lmfile

    global lm_scale
    global align_mode

    global word_penalty
    global context_mode
    global st_beam
    global ph_beam
    global wd_beam
    global mapmi
    global history_paths
    global num_n_best
    global gram_size
    global mfcc_format

    set fileptr [open $filename w]

    # define function mode
    #
    puts $fileptr "function = $function_mode"

    # define input files depend on context mode
    #
    if {$context_mode == "monophone"} {
	puts $fileptr "monophones_file = $data_dir/models/monophone_models/monophones.text"
	puts $fileptr "transitions_file = $data_dir/models/monophone_models/transitions.text"
	puts $fileptr "states_file = $data_dir/models/monophone_models/states.bin"
	puts $fileptr "models_file = $data_dir/models/monophone_models/models.text"
	puts $fileptr "phones_file = $data_dir/models/monophone_models/phones.text"
	puts $fileptr "lexicon_file = $data_dir/models/monophone_models/lexicon.text"
	puts $fileptr "context_mode = $context_mode"
    } elseif {$context_mode == "cross_word"} {
	puts $fileptr "monophones_file = $data_dir/models/xwrd_models/monophones.text"
	puts $fileptr "transitions_file = $data_dir/models/xwrd_models/transitions.text"
	puts $fileptr "states_file = $data_dir/models/xwrd_models/states.bin"
	puts $fileptr "models_file = $data_dir/models/xwrd_models/models.text"
	puts $fileptr "phones_file = $data_dir/models/xwrd_models/phones.text"
	puts $fileptr "lexicon_file = $data_dir/models/xwrd_models/lexicon.text"
	puts $fileptr "context_mode = $context_mode"
    } else {
	puts $fileptr "monophones_file = $data_dir/models/word_models/monophones.text"
	puts $fileptr "transitions_file = $data_dir/models/word_models/transitions.text"
	puts $fileptr "states_file = $data_dir/models/word_models/states.bin"
	puts $fileptr "models_file = $data_dir/models/word_models/models.text"
	puts $fileptr "phones_file = $data_dir/models/word_models/phones.text"
	puts $fileptr "lexicon_file = $data_dir/models/word_models/lexicon.text"
	puts $fileptr "context_mode = monophone"    
    }

    # define input format
    #
    puts "input_format = $mfcc_format"
    puts $fileptr "input_format = $mfcc_format"
   
    # define alignment mode
    # 
    puts $fileptr "align_mode = $align_mode"

    puts $fileptr "lm_scale = $lm_scale"
    puts $fileptr "word_penalty = $word_penalty"

    puts $fileptr "history_paths = $history_paths"
    puts $fileptr "nbest_paths = $num_n_best"

    # define pruning thresholds
    #
    puts $fileptr "beam_pruning = $st_beam $ph_beam $wd_beam"
    puts $fileptr "mapmi_limit = $mapmi"
    puts $fileptr "num_allowed_words = 50"

    # define input lattice list
    #
    if {$function_mode == "ngram_decoding"} {
	puts $fileptr "ngram_order = $gram_size"
	puts $fileptr "lm_file = $lm_file"
	puts $fileptr "input_lm_list = $tmp_lmfile"
	puts stdout "ngram mode"
    } elseif {$function_mode == "forced_alignment"} {
	puts $fileptr "transcription_file = $transcription_file"
	
    } elseif {$function_mode == "lattice_verification"} {
	puts $fileptr "ngram_order = $gram_size"
	puts $fileptr "lm_file = $lm_file"
	puts stdout "ngram mode"
	puts $fileptr "input_lattice_list = $tmp_latfile"
    }  else {
	puts $fileptr "input_lattice_list = $tmp_latfile"
    }
    
    # define input and output lists
    #
    puts $fileptr "mfcc_list = $tmp_infile"
    puts $fileptr "output_list = $tmp_outfile"
    puts $fileptr "output_nbest_list = $tmp_outnbestfile"
    
    flush $fileptr

    # close the file
    #
    close $fileptr
}

