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

proc cmold_write_input {} {
    global confname file_name cmold_output_path icem_powermesh
    global file_name

    set domain [domain_select $file_name(domains_dir) "Select an unstructured domain." unstruct 0]
    if {$domain == {}} return

    get_boco_topo

    set outfile $file_name(transfer_dir)/cmold

    set second 0
    set third 0
    set domain2 $file_name(domains_dir)/struct_merge
    set domain3 $file_name(domains_dir)/struct_merge

    set bocofile2 $bocofile
    set bocofile3 $bocofile

    if {![dialog .cmold "C-MOLD" \
          "Please edit the following C-MOLD options." {
		{bocofile -type path -title "bocofile" \
                          -help "Boundary conditions file"}
		{outfile -type path -title "Output file" -help "Output file"}
		{second -opt {{"Yes" 1} {"No" 0}} \
			-title "Second unstruct. domain"}
		{bocofile2 -type path -active {$second} -title "bocofile2" \
			-help "Bound. cond. file for 2nd unstr. domain file"}
		{domain2 -type path -active {$second} -title "2nd unstr.dom." \
			-help "Name of second unstr. domain file"}
		{third -active {$second} -opt {{"Yes" 1} {"No" 0}} \
			-title "Third unstruct. domain"}
		{bocofile3 -type path -active {$third} -title "bocofile3" \
			-help "Bound. cond. file for 3rd unstr. domain file"}
		{domain3 -type path -active {$third} -title "3rd unstr.dom." \
			-help "Name of third unstr. domain file"}
           }]} return
  
    if {![file exists $domain]} {
        errormsg "Domain file $domain doesn't exist"
        return
    }
    if {![file exists $bocofile]} {
        errormsg "Domain file $bocofile doesn't exist"
        return
    }
    if $second {
        if {![file exists $domain2]} {
            errormsg "Domain file $domain2 doesn't exist"
            return
        }
        if {![file exists $bocofile2]} {
            errormsg "Domain file $bocofile2 doesn't exist"
            return
        }
    }
    if $third {
	if {![file exists $domain3]} {
            errormsg "Domain file $domain3 doesn't exist"
            return
        }
        if {![file exists $bocofile3]} {
            errormsg "Domain file $bocofile3 doesn't exist"
            return
        }
    }

    set command "\"$cmold_output_path\" -dom \"$domain\" -b \"$bocofile\"" 
    if $second {set command "$command -sec -dom2 \"$domain2\" -b2 \"$bocofile2\""}
    if $third {set command "$command -tri -dom3 \"$domain3\" -b3 \"$bocofile3\""}
    set command "$command \"$outfile\""

    runcom $command ""
}
