proc rmi_Batch {file} {
global env rmi

    if ![file exists $file] {
      puts "Settings file not found: $file"
      exit
    }        
    if ![string match Windows* [winfo server .]] {
      set prog med
    } else {
      set prog "med_batch.exe"
    }
    set fn ./script.batch.chadice
    set f [open $fn w]
    puts $f "global rmi"
    if [string match Windows* [winfo server .]] {
      puts $f "source [win_shortname $env(ICEM_ACN)/lib/rmi/rmi_params.tcl]"
      puts $f "source [win_shortname $env(ICEM_ACN)/lib/rmi/rmi_app.tcl]"
      puts $f "source [win_shortname $env(ICEM_ACN)/lib/rmi/rmi_misc.tcl]"
      puts $f "source [win_shortname $env(ICEM_ACN)/lib/rmi/rmi_file.tcl]"
    } else {
      puts $f "source $env(ICEM_ACN)/lib/rmi/rmi_params.tcl"
      puts $f "source $env(ICEM_ACN)/lib/rmi/rmi_app.tcl"
      puts $f "source $env(ICEM_ACN)/lib/rmi/rmi_misc.tcl"
      puts $f "source $env(ICEM_ACN)/lib/rmi/rmi_file.tcl"
    }
    puts $f "set rmi(chadice) 1"
    puts $f "set rmi(Product) CHADICE"
    puts $f "set rmi(batch_mode) 1"
    puts $f "set rmi(settings_fn) $file"
    puts $f "if \[rmi_OpenSettings\] \{ exit \}"
    puts $f "set n \[rmi_SetMeshParams 1\]"
    puts $f "if \[rmi_AppRunBatch\] \{ exit \}"
    puts $f "exit"
    close $f   
    set log logfile.batch.chadice
    puts "Start chadice batch mode ... logfile name is <$log>"
    if ![string match Windows* [winfo server .]] {
      set cmd "$env(ICEM_ACN)/bin/$prog -batch -script $fn"
      eval exec $cmd >& ./$log
    } else {
      set cmd "[win_shortname $env(ICEM_ACN)/bin/$prog -script $fn]"
      eval exec start /wait $cmd >& ./$log
    }
    puts "Done chadice batch mode."
    exit        
}

set file [lindex $argv 0]
rmi_Batch $file
