global env

set revn 140
set config 1
set unconfig 0

set i 0
foreach arg $argv {
   switch -glob -- $arg {
      -noconfig       { set config 0; set unconfig 0 }
      -unconfig       { set unconfig 1; set config 0 }
      -installdir     { set installDir       [lindex $argv [expr $i + 1]] }
      -rev            { set revn             [lindex $argv [expr $i + 1]] }
      -scripttosource { set scripttosource   [lindex $argv [expr $i + 1]] }
   }
   incr i
}

catch {source $scripttosource}

if { $config == 1 || $unconfig == 1 } {
   if { [ string compare -nocase "$env(ANSYS_SYSDIR)" "intel" ] == 0 || [ string compare -nocase "$env(ANSYS_SYSDIR)" "winx64" ] == 0 } {
      set config_dir "$installDir\\v$revn\\commonfiles\\configs"
      if { [ string compare -nocase "$env(ANSYS_SYSDIR)" "intel" ] == 0 } {
         set config_dir "$config_dir\\win32"
      } else {
         set config_dir "$config_dir\\$env(ANSYS_SYSDIR)"
      }

      set cmdPath ""
      if { $config == 1 } {
         puts "Configuring AIM ..."
         set config_dir "$config_dir\\config"
         set cmdPath "$config_dir\\AnsConfigAIM.exe"
      } else {
         #$unconfig
         puts "Unconfiguring ASim ..."
         set config_dir "$config_dir\\unconfig"
         set cmdPath "$config_dir\\AnsUnconfigAIM.exe"
      }

      puts "\nRunning $cmdPath"
      exec $cmdPath
   }
}

