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

proc dtf_write_input {} {
    global confname file_name dtf_output_path icem_powermesh
    global file_name
    
#    set domains [domain_select $file_name(domains_dir) "You may either select a set of structured domains or an unstructured domain." mixed 1]    
    
#    if {$domains == {}} return
    
    get_boco_topo
    set ace_u 0
    set check_ori 0
    set fast_ind 0

    set outfile $file_name(transfer_dir)/dtf
    set unstrdom $file_name(domains_dir)/hex.uns
    
    if {![dialog .dtf "DTF" \
	    "Edit the following DTF options. " {
	{ace_u -opt {{"Structured" 0} \
		{"Unstructured" 1}} -title "Output Type" }
	{unstrdom -type path -title "Unstructured domain" \
		-active {$ace_u} -help "Domain file"}
	{topofile -type path -title "Topo file" \
		-active {!$ace_u} -help "Topology file"}
	{bocofile -type path -title "Boco file" \
		-help "Boundary condition file"}
	{single -opt {{Single 1} {Double 0}} -title Precision \
		-help "Precision"}
        {fast_ind -opt {{Yes 1} {No 0}} -active {!$ace_u} \
                  -title "Write largest block dimension as first direction?"}
	{outfile -type path -title "Output filename base" \
		-help "Output file"}
    }]} return	

# Option removed with revision 5.0.3
#       {check_ori -opt {{Yes 1} {No 0}}  -active {$ace_u} \
#       -title "For surface mesh: Verify element orientation?" }


    if {![file exists $bocofile]} {
	errormsg "Boundary condition file doesn't exist!"
	return
    }
    if {$ace_u} {
	if {![file exists $unstrdom]} {
	    errormsg "File $unstrdom doesn't exist"
	    return
	}
    }
    
    if {!$ace_u} {
	
	if {![file exists $topofile]} {
	    errormsg "File $topofile doesn't exist"
	    return
	}

	set domains [domain_select $file_name(domains_dir) "Select structured domains." struct 0]    
	
	if {$domains == {}} 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 "\"$dtf_output_path\" -b \"$bocofile\""
    if {$ace_u} {set command "$command -unstr \"$unstrdom\""}
    if {!$ace_u} {set command "$command -t \"$topofile\" -f \"$ftopofile\" -dom_list domain_list"}
    if {!$single}  {set command "$command -d"}
    if {$fast_ind} {set command "$command -fast"}
#    if {$ace_u && !$check_ori} {set command "$command -fix"}    
    set command "$command \"$outfile\""
    
    runcom $command ""
    cmd_rm domain_list
}
