
# The main driver script for Med.
#
# Copyright (c) 1993 ICEM Systems.
# Author:  Wayne A. Christopher, wayne@pmac.com
#          Pacific Marketing and Consulting, Berkeley, California

if ![info exists env(ICEM_ONE_INTERP)] {
    set env(ICEM_MULTI_INTERP) 1
}
if ![info exists env(MED_ROOT)] {
    set env(MED_ROOT) $env(ICEM_ACN)
}

# I don't know what is going on but this works around a problem on sgi
catch [list v3_batch_interp eval set saved_path_from_start $env(PATH)]

# -------------------------------------------------------------------

if {[info exists env(ICEM_AI_VA)] && [file exists $env(ICEM_AI_VA)]} {
    catch {source $env(ICEM_AI_VA)}
    return
}

# -------------------------------------------------------------------

if {[info exists env(ICEM_AI_ENVIRONMENT)] == 1} {
    if { $env(ICEM_AI_ENVIRONMENT) == 1 } {
        if {[info exists env(MED_ROOT)] &&
            [file exists $env(MED_ROOT)/../ai_env/init.tcl]} {
            #  flat data structure of CVS
            if {[file exists $env(MED_ROOT)/../tcllib1.4]} {
                lappend auto_path $env(MED_ROOT)/../tcllib1.4
            }
            if {[file exists $env(MED_ROOT)/../bwidget1.4]} {
                lappend auto_path $env(MED_ROOT)/../bwidget1.4
            }
            if {[file exists $env(MED_ROOT)/../tcllib1.2/struct]} {
                lappend auto_path $env(MED_ROOT)/../tcllib1.2/struct
            }
            source $env(MED_ROOT)/../ai_env/init.tcl
        } else {
            if [file exists $env(ICEM_ACN)/lib/bwidget1.4] {
               lappend auto_path $env(ICEM_ACN)/lib/bwidget1.4
            }
            if [file exists $env(ICEM_ACN)/lib/tcllib1.4] {
               lappend auto_path $env(ICEM_ACN)/lib/tcllib1.4
            }
            source [file join $env(ICEM_ACN) lib ai_env init.tcl]
        }
        # Bail out here
        return
    }
}
#
# --------------------------------------------------------------------
if {[info commands label] != ""} {
    # Since the script interpreter has Tk we have to withdraw it's . window
    script_interp eval wm withdraw .
    
    wm withdraw .
    catch {console hide}
    update idletasks
    catch {WinLoadIcon icemcfd}
    set please_wait_font [font create -size 20 -weight bold -family helvetica]
    label .startup -text "ICEM CFD starting..." \
	    -font $please_wait_font -fg blue -bg bisque -padx 10 -pady 10
	wm title . "Mesh Editor"
    pack .startup
    wm geometry . +300+300
    wm deiconify .
    raise .
    update
}

for {set i 0} {$i < $argc} {incr i} {
    if {[lindex $argv $i] == "-med_root"} {
	set d [lindex $argv [expr $i + 1]]
	foreach v {env(ICEM_ACN) env(MED_ROOT) med_root} {
	    set $v $d
	}
	foreach v {guibase_dir tdv_library env(MED_DIR)} {
	    catch {unset $v}
	}
    }
}

foreach v {ICEM_ACN LM_LICENSE_FILE ICEM_LICENSE_FILE} {
    if [info exists env($v)] {
	regsub -all \\\\ $env($v) / env($v)
    }
}

set guibase_dir $med_root/lib/med/guibase
if ![file exists $guibase_dir/guibase.tcl] {
    set guibase_dir $med_root/lib/guibase
}
if ![file exists $guibase_dir] {
    set guibase_dir $med_root/../guibase
}
set tdv_library $med_root/lib/med/tdv
if ![file exists $tdv_library] {
    set tdv_library $med_root/lib/tdv
}
if ![file exists $tdv_library] {
    set tdv_library $med_root/../tdv/lib
}

set env(MED_DIR) $med_root/lib/med_gui
set file med_gui

set has_blt 0
incr argc 2
set argv [concat [list -tool $env(MED_DIR)/$file.tcl] $argv]
#set va_win(do_not_show_main) 1
source $guibase_dir/guibase.tcl
