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

proc airflo3d_write_input {} {
    global confname file_name airflo3d_output_path env icem_powermesh
    global file_name
    
    set domains [domain_select $file_name(domains_dir) "Select structured domains." struct 0]
    if {$domains == {}} return
    get_boco_topo

    set outfile $file_name(transfer_dir)/airflo3d
    set unstr_dom $file_name(domains_dir)/hex.uns
    set structured 0
    set scale 0
    set conv_scale 1.0
    set gr_check 0
    set binary 1
    
    if {![dialog .airflo3d "Airflo 3d" \
	  "Please edit the following airflo3d options. \
 If you request a binary file, the suffix .bin \
 will be added to the output file; for an ASCII file the suffix .dat \
 will be used." {
	       {structured -opt {{Unstructured 0} {Structured 1}} \
		    -title "Domain type"}
	       {unstr_dom -type path -active !$structured \
		    -title "Unstructured domain" }
               {binary -opt {{Binary 1} {Ascii 0}} \
		   -title "Output type" -help "Output type"}
	       {topofile -type path -title "Topo file" -active {$structured} \
		   -help "Topology file"}
	       {bocofile -type path -title "Boco file" \
		   -help "Boundary condition file"}
	       {outfile -type path -title "Output file" -help "Output file"}
	       {gr_check -opt {{"Yes" 1} {"No" 0}} -title \
		       "Check grid"}
	       {conv_scale -type string -title "Convective Flux Scaling Factor"}
	       {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 !$structured {
	if {![file exists $unstr_dom]} {
	  set unstr_dom $file_name(domains_dir)/auto_domain.1
	  
          if {![file exists $unstr_dom]} {
	    errormsg "Domain file not found: $unstr_dom"
	    return
	  }
	}
      }

    set paramfile $file_name(transfer_dir)/airflow3d_data
      if {![file exists $paramfile]} {
	set sysparamfile $env(ICEM_ACN)/icemcfd/output-interfaces/airflow3d_data
	if {![file exists $sysparamfile]} {
	    errormsg "System param file not found: $sysparamfile"
	    return
	}
	cmd_cp $sysparamfile $paramfile
      }
  
      if {[query_question .query "Edit the default parameter file?"] != "*cancel*"} {
	run_editor $paramfile
      }
    
    if $structured {
      if {![file exists $topofile]} {
	errormsg "File $topofile doesn't exist"
	return
      }
    }
    
    if {![file exists $bocofile]} {
	errormsg "File $bocofile doesn't exist"
	return
    }

    cmd_rm domain_list
    set text ""
    foreach d $domains { append text "$d\n" }
    ic_write_file domain_list $text
    
    set command "\"$airflo3d_output_path\" -b \"$bocofile\""
    set command "$command -cfscl $conv_scale"
    if $gr_check {set command "$command -g_check"}
    if $structured {
        set command "$command -dom_list domain_list -t \"$topofile\" -f \"$ftopofile\" -ifile \"$paramfile\"" 
	if {$binary} then {
	    set command "$command \"$outfile.bin\" -bin"
        } else {
            set command "$command \"$outfile.dat\""
        }
    } else {
        set command "$command -unstr \"$unstr_dom\" -ifile \"$paramfile\""
        if {$binary} then {
	    set command "$command \"$outfile.bin\" -bin"
        } else {
            set command "$command \"$outfile.dat\""
        }
    }
    if $scale {set command "$command -scl $x,$y,$z"}
    
    runxcom ICEM-CFD/AIRFLO3D-Interface $command "" 1 0
}







