##
# Invoke the import of a solver result
#
# gateway_import <solvekey> <variable list> <avail results>  <type> <out file>
#
set gateway_dir ""
if [info exists env(GATEWAY_DIR)] {
    lappend gateway_dir $env(GATEWAY_DIR)
}
lappend gateway_dir .

if [info exists env(ICEM_ACN)] {
    lappend gateway_dir $env(ICEM_ACN)/lib/gateway_gui
}

foreach f {
    gateway
} {
    set found 0
    foreach gd $gateway_dir {
	if [file exists $gd/$f.tcl] {
	    set ICC_gateway(tempfile) $gd/$f.tcl
	    set stat [catch {source $ICC_gateway(tempfile)} msg]
	    if !$stat {
		set found 1 
		break
	    }
	}
    }
    if !$found {
	error "File $f.tcl not found in gateway_dir list \"$gateway_dir\""
    }
}

# set guibase_dir_list

set guibase_dir_list ""
if [info exists env(GUIBASE_DIR)] {
    lappend guibase_dir_list $env(GUIBASE_DIR)
}

lappend guibase_dir_list guibase ../guibase

if [info exists env(ICEM_ACN)] {
    lappend guibase_dir_list $env(ICEM_ACN)/lib/gateway_gui/guibase
    lappend guibase_dir_list $env(ICEM_ACN)/lib/guibase
}

set match_file ""
foreach gd $gateway_dir {
    if [file exists $gd/v3_solver_match.tcl] {
	set match_file $gd/v3_solver_match.tcl
	break
    }
}

# bring in all tcl files and withdraw top level window

ICC_gateway_initimport $match_file

# <solver key> <variable list> <file info> <req type> <tempfile>
ICC_gateway_matchresult [lindex $argv 0] [lindex $argv 1] \
    [lindex $argv 2] [lindex $argv 3] [lindex $argv 4]

exit
