#
# Create schema file for specified solver
#
# tclsh gateway_schema.tcl <proj dir> <solver> <schema file>
#
# Copyright (c) 2002 ICEMCFD Engineering, a subsidary of ANSYS
# Author: Forest Rouse
#

# Grab main gateway interface proc 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 gateway_sources
} {
    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
}

# bring in all tcl files 

ICC_gateway_initialize 1

set proj_dir [lindex $argv 0]
if {$proj_dir == ""} {
    set proj_dir [pwd]
}
set old_dir [pwd]
cd $proj_dir

set solver [lindex $argv 1]
set scheme [file tail [lindex $argv 2]]
set ret [ICC_gateway_solverscheme $solver $scheme]
ICC_gateway_catalog
ICC_gateway_menus
ICC_gateway_NLS
ICC_gateway_dictionary
ICC_gateway_bccode
cd $old_dir
exit
