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

proc cfdpp_write_input {} {
    global confname file_name cfdpp_output_path 
    global file_name

    get_boco_topo

    set output_dir $file_name(transfer_dir)
    set paramfile $file_name(transfer_dir)/mcfd.param

    set cgrp 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 .cfd++ "CFD++" \
      "Please edit the following CFD++ options." {
        {bocofile -type path -title "Boco file" \
                -help "Boundary condition file"}
        {paramfile -type path -title "Parameter File (optional)"}
	{cgrp -opt {{"Yes" 1} {"No" 0}} -title "Option to output cell groups file"} \
        {scale -opt {{"Yes" 1} {"No" 0}} -title "Scaling" \
                -help "Scaling of coordinates (enter 3 values for x, y & z"}
        {x -type string -active {$scale} -title "x scaling factor" \
                -help "Enter x scaling factor"}
        {y -type string -active {$scale} -title "y scaling factor" \
                -help "Enter y scaling factor"}
        {z -type string -active {$scale} -title "z scaling factor" \
                -help "Enter z scaling factor"}
	{output_dir -type path -title "Directory for output files"}
    }]} return

    if {![file exists $bocofile]} {
        errormsg "Bound. Cond. file $bocofile doesn't exist"
        return
    }
    if {![file exists $output_dir]} {
        errormsg "Directory $output_dir doesn't exist.  Mesh NOT translated."
	return
    }
    set nodefile $output_dir/nodesin.bin
    set cellfile $output_dir/cellsin.bin
    set bcfile $output_dir/exbcsin.bin
    set inbcfile $output_dir/inbcsin.bin
    set mcfdfile $output_dir/mcfd.bc
    set solfile $output_dir/cdepsin.bin

    set command "\"$cfdpp_output_path\" -b \"$bocofile\" -dom \"$domain\" -nod \"$nodefile\" \
	    -sol \"$solfile\" -cel \"$cellfile\" -bc \"$bcfile\" -ibc \"$inbcfile\" \
	    -mcfd \"$mcfdfile\" -param \"$paramfile\""
    if $cgrp {set command "$command -cgrp"}
    if $scale {set command "$command -scale $x,$y,$z"}
    runxcom ICEM-CFD/CFD++Interface $command "" 1 0
}
