# Invoke the import of a solver result
#
# gateway_result <projdir> <output file> <reader> <import information>
#
# <reader> and <import info> are optional
#

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 batch_mode 0

# 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
}

# bring in all tcl files and withdraw top level window

ICC_gateway_initialize
top_withdraw .

# Get the reader, parse it and we are done

set old_dir [pwd]
set projdir [lindex $argv 0]
if {$projdir == ""} {
    if [info exists env(ICEMCAAV5_ProjDir)] {
	set projdir $env(ICEMCAAV5_ProjDir)
    } else {
	set projdir .
    }
}
cd $proj_dir

set outfile [lindex $argv 1]
if {$outfile == ""} {
    set outfile ResultInfo
}

set reader [lindex $argv 2]
set line [lindex $argv 3]

set ret [ICC_gateway_reader $reader $line]
ICC_reader_line $ret $outfile
cd $old_dir
exit

