# Library functions for the scripting library (scrib)
#
# File: scrib/lib/queue.tcl
#
# $Revision$ on $Date$
# 
# Copyright (c) 1993-2003 ICEM CFD Engineering
#
#--------------------------------------------------------------------
#

##

proc scrib_lib_queue_medbatch_submit {bqs script args {logfile ""}} {
    global env
    
    set stat 0
    set outscript "current_med_script.tcl"
    set script [scrib_lib_exec_build_medscript $script $outscript]
    
    set envname ""
    
    catch {scrib_lib_exec_medbatch_progpath} prog
    
    if { ( !$interactive ) && ( ![scrib_lib_utils_iswin] ) } {
	append icemcfd_args "-batch "
    }
    append icemcfd_args "-script $script "
    if {"" != $args} {
	append icemcfd_args "-- $args "
    }
    
    if {"" == $logfile} { set logfile [scrib_lib_utils_logfile "." "queue_medlog_"] }
    
    set cmdfile ""
    set cmd "$prog $icemcfd_args > $logfile"
    set cmdfile [scrib_lib_exec_medbatch_shellscript $cmdfile $cmd]
    
    if [catch {batch_queue_submit_job $bqs "-script $shell_script"} jobid] {
	mess "FIXME: scrib_lib_queue_medbatch_submit\n" red
    }
    
    batch_queue_generic_message $bqs $jobid "Job logfifile is $logfile"
    
    return $stat
}


##

proc scrib_lib_queue_kill_job {job_token} {
    
    batch_queue_delete_job "pbs" $job_token
}



##

proc scrib_lib_exec_command_queue {command args} {
        
    set files ""
    set wdir  ""
    set success_cmd ""
    
    set jobs ""
    foreach script $scripts {
	
	# queue up the jobs
	
	lappend jobs $jobid
    }
    
    # gather job info; summarize to user
    
    foreach job $jobs {
	
	# start jobs
    }
    
    while {1} {
	
	# check each job
	# report job status i
	
	after 1000 check_job_status
    }
    
}

