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

proc laura_write_input {} {
    global confname file_name laura_output_path icem_fluent icem_powermesh
    global laura_params laura_param_table
    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)/laura
    
    set scale 0
    set x 1.0
    set y 1.0
    set z 1.0
    set double 0
    
    if {![dialog .laura "LAURA" \
	"Please edit the following LAURA options. " {
	{topofile -type path -title "Topo file" -help "Topology file"}
	{bocofile -type path -title "Boco file" -help "Boundary condition file"}
	{double -opt {{"single precision" 0} {"double precision" 1}} \
		-title "Grid binary format"}
	{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"}
	{outfile -type path -title "Output file" -help "Output file"}
    }]} return

    if {![file exists $topofile]} {
        errormsg "Topology file doesn't exist!"
        return
    }
    if {![file exists $bocofile]} {
        errormsg "Boundary condition file doesn't exist!"
        return
    }
    
    solver_params_load laura laura_params
    if ![solver_params "LAURA Solver Parameters" laura_params $laura_param_table] return
    set paramfile [solver_params_save laura laura_params]

    cmd_rm domain_list
#   set fp [open domain_list w]
#   foreach d $domains { puts $fp $d }
#   close $fp
    set text ""
    foreach d $domains { append text "$d\n" }
    ic_write_file domain_list $text

    set command "\"$laura_output_path\" -t \"$topofile\" -f \"$ftopofile\" -b \"$bocofile\""
    if $scale {set command "$command -scale $x,$y,$z"}
    if $double {set command "$command -dbl"}
    set command "$command -param \"$paramfile\" -dom_list domain_list \"$outfile\""
    
    runxcom ICEM-CFD/LAURA-Interface $command "" 1 0
    cmd_rm domain_list
}

set laura_param_table {
    newrow
    { title "title" "" "-columnspan 8" }
    newrow
    { ROOT "rootname for laura input files" "" "-columnspan 8" }
    newrow
    NEWJOB 
    igovern
    { vinfb "vinfb" "" "-columnspan 2" }
    { rinfb "rinfb" "" "-columnspan 2" }
    tinf
    attack
    newrow
    tempbc
    twall
    nplanet
    ngas
    icrv
    nturb
    iunit
    newrow
    { xcg "xcg" "" "-columnspan 2" }
    { zcg "zcg" "" "-columnspan 2" }
    { refarea "refarea" "" "-columnspan 2" }
    { reflen "reflen" "" "-columnspan 2" }
}
