# ICEM CFD solver interface routine for the manager.
#
# Copyright (c) 1993-1995 ICEM Systems.

proc impns_write_input {} {
    global confname file_name impns_output_path icem_powermesh
    global file_name

#    set domains [multiblock_domain_list]
    set domains [domain_select $file_name(domains_dir) "Select structured domains." struct 0]
    if {$domains == {}} {
	errormsg "No multiblock mesh available!"
	return
    }
    
    get_boco_topo

    set outfile $file_name(transfer_dir)/info
    
    if {![dialog .impns "IMPNS" \
          "Please edit the following IMPNS options." {
	{topofile -type path -title "Topo file" -help "Topology file"}
	{bocofile -type path -title "Boco file" -help "Boundary condition file"}
	{outfile -type path -title "Output file" -help "Output file"}
    }]} return
	
    if {![file exists $topofile]} {
	errormsg "Topology file doesn't exist!"
	return
    }
    if {![file exists $bocofile]} {
	errormsg "Boundary condition file doesn't exist!"
	return
    }
    
    cmd_rm domain_list
#   set fp [open domain_list w]
#   foreach d $domains { puts $fp $d }
#   close $fp
    set text ""
    foreach d $domains { append text "$d\n" }
    ic_write_file domain_list $text

    set command "\"$impns_output_path\" -b \"$bocofile\" -t \"$topofile\" -f \"$ftopofile\""
    set command "$command -dom_list domain_list \"$outfile\""
    
    runcom $command ""
    cmd_rm domain_list
}
