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

proc flowlogic_write_input {} {
    global confname file_name flowlogic_output_path icem_powermesh
    global file_name

    get_boco_topo

    set outfile $file_name(transfer_dir)/flow_logic
    set structured 1
    
    if {![dialog .flowlogic "FLOWLOGIC" \
          "Please edit the following FLOWLOGIC options." {
	{structured -opt {{Structured 1} {Unstructured 0}} -title "Domain type"}
	{topofile -active {$structured} -type path -title "Topo file" -help "Topology file"}
	{bocofile -active {$structured} -type path -title "Boco file" -help "Boundary condition file"}
	{outfile -type path -title "Output file" -help "Output file"}
    }]} return
	
    if {$structured} {
    
        if {![file exists $topofile]} {
	    errormsg "Topology file doesn't exist!"
	    return
        }
        if {![file exists $bocofile]} {
	    errormsg "Boundary condition file doesn't exist!"
	    return
        }
	set domains [domain_select $file_name(domains_dir) "Select structured domains." struct 0]

    } else {
	set domains [domain_select $file_name(domains_dir) "Select unstructured domains." unstruct 1]
    }

    if {$domains == {}} {
        errormsg "No domains selected."
        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 "\"$flowlogic_output_path\" -dom_list domain_list \"$outfile\""
    if {$structured} {set command "$command -b \"$bocofile\" -t \"$topofile\" -f \"$ftopofile\"" }
    if {!$structured} {set command "$command -unstr"}
    
    runcom $command ""
    cmd_rm domain_list
}
