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

proc usm3d_write_input {} {
    global confname file_name usm3d_output_path icem_powermesh
    global file_name env

    get_boco_topo
    set fortran_unit 1
    set env(F_UFMTENDIAN) $fortran_unit

#   set domain [domain_select $file_name(domains_dir) "Select an unstructured domain." \
#       unstruct 0]
#   if {$domain == {}} return
#    set outfile $file_name(transfer_dir)/usm3d
    set outfile  [file rootname $file_name(settings)]
    set domainfile $file_name(domain)
    set viscous_flag 1

    if {![dialog .usm3d "USM3D" \
          "Please edit the following USM3D options." {
        {viscous_flag -opt {{Viscous 1} {Inviscid 0}} -title "Grid type"}
	{bocofile -type path -title "Boco file" -help "Boundary condition file"}
        {domainfile -type path -title "Domain file" -help "Domain file"}
	{outfile -type path -title "Output file" -help "Output file"}
    }]} return

    if {![file exists $domainfile]} {
	errormsg "Domain file doesn't exist!"
	return
    }	

    if {![file exists $bocofile]} {
	errormsg "Boundary condition file doesn't exist!"
	return
    }
    
    set command "\"$usm3d_output_path\" -b \"$bocofile\""
    if $viscous_flag {set command "$command -viscous"}
    set command "$command -d \"$domainfile\" -o \"$outfile\""

    runcom $command ""
}
















