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

proc chad_write_input {} {
    global confname file_name chad_output_path s2u_path icem_fluent icem_powermesh
    global file_name

    get_boco_topo

    set outfile $file_name(transfer_dir)/chad
    set matnoe 0
    set bnd 0
    set scale 0
    set x 1.0
    set y 1.0
    set z 1.0

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

    if {![dialog .chad "CHAD" \
          "Please edit the following CHAD options." {
               {bocofile -type path -title "Boco file" \
                   -help "Boundary condition file"}
               {outfile -type path -title "Output file" -help "Output file"}
	       {matnoe -opt {{Yes 1} {No 0}} \
                        -title "Write array MATNOE in CHAD file?"}
	       {bnd -opt {{Yes 1} {No 0}} \
		        -title "Write boundary file?"}
	       {scale -opt {{"Yes" 1} {"No" 0}} -title "Scaling"}
               {x -type string -active {$scale} -title "x scaling factor" }
               {y -type string -active {$scale} -title "y scaling factor" }
               {z -type string -active {$scale} -title "z scaling factor" }
           }]} return

    if {![file exists $bocofile]} {
        errormsg "Bound. Cond. file $bocofile doesn't exist"
        return
    }
    if {[file exists $outfile] && \
         [query_question .query "Overwrite $outfile?"] != "*okay*"} return

    set command "\"$chad_output_path\" -b \"$bocofile\" -dom \"$domain\" \"$outfile\" -log"
    if $matnoe   {set command "$command -matnoe"}
    if $bnd 	 {set command "$command -bnd"}
    if $scale   {set command "$command -scale $x,$y,$z"}
    runxcom ICEM-CFD/CHAD-Interface $command "" 1 0
}
