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

proc flex_write_input {} {
    global confname file_name flex_output_path 
    global file_name

    get_boco_topo

    set outputfile $file_name(transfer_dir)/flex     
    set scale 0
    set x 1.0
    set y 1.0
    set z 1.0
    set binary 0
    set flagdouble 0

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

    if {![dialog .flex "FLEX" \
      "Please edit the following FLEX options." {
        {bocofile -type path -title "Boundary Condition file"}
        {outputfile -type path -title "Output 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"}
	{binary -opt {{ASCII 0} {Fortran-binary 1}} -title "Ouput format"}
	{flagdouble -opt {{Single 0} {Double 1}} -title "Precision"}
    }]} return

    if {![file exists $bocofile]} {
        errormsg "Bound. Cond. file $bocofile doesn't exist"
        return
    }

    set command "\"$flex_output_path\" -b \"$bocofile\" -dom \"$domain\" \"$outputfile\""
    if $scale {set command "$command -scale $x,$y,$z"}
    if $binary {set command "$command -bin"}
    if $flagdouble {set command "$command -double"}
    runxcom ICEM-CFD/FLEX-Interface $command "" 1 0
}
