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

proc cmg_stars_write_input {} {
    global confname file_name cmg_stars_output_path icem_powermesh
    global file_name

    set file [file tail [pwd]]_c3d.mesh.Info
    set infofile $file_name(transfer_dir)/$file
    set outgrid $file_name(transfer_dir)/grid_file.dat
    set outwell $file_name(transfer_dir)/wells_file.dat
    set shellfile $file_name(transfer_dir)/history.shell
    set permfile $file_name(transfer_dir)/kfile
    set famfile $file_name(transfer_dir)/[file tail [pwd]]_c3d.fam
    set trans 1.0E+05
    set sgm_option 1
    set perm_option 0
    
    if {![dialog .cmg_stars "CMG_STARS" \
          "Please edit the following CMG_STARS options." {
	{infofile -type path -title "CART3D .Info file"}
	{perm_option -opt {{"Compute K-file" 0} {"Use existing K-File" 1}} \
	    -title "Compute or use existing K-File?" }
	{permfile -type path -title "Specify the name of the permeability factors file"}
        {famfile -type path -title "CART3D .fam file"}
        {sgm_option -opt {{"Original or Lite" 0} {"SGM" 1}} \
	    -title "Select grid type option" }
	{outgrid -type path -title "Output grid file"}
	{outwell -type path -title "Output well file"}
        {trans -type string -title "TRANS factor"}
    }]} return
	
    if {![file exists $infofile]} {
	errormsg "CART3D .Info file doesn't exist!"
	return
    }
    if {![file exists $shellfile]} {
	errormsg "history.shell file doesn't exist!"
	return
    }
    if {$perm_option} {
      if {![file exists $permfile]} {
        errormsg "Permeability factors file doesn't exist!"
	return
      }
    }
    if {![file exists $famfile]} {
        errormsg "Family file doesn't exist!"
        return
    }
    
    set command "\"$cmg_stars_output_path\" -i \"$infofile\" -s \"$shellfile\" -f \"$famfile\" -out_grid \"$outgrid\" -out_well \"$outwell\" -trans $trans -k \"$permfile\""
    if $perm_option {set command "$command -readK"}
    if $sgm_option {set command "$command -sgm"}
    
    runcom $command ""
}
