#! /bin/csh -f
#
#  find, copy, and run nbx_share.csh
#    (nubeam_comp_exec)
#
  @ iarg = 0
  set slurm = "TRUE"
  while ( $iarg < $#argv )
     @ iarg++
     if ( "${argv[$iarg]}" == "qsub" || "${argv[$iarg]}" == "no_qsub" ) then
          echo " PBS (qsub) job requested."
	  set slurm = "FALSE"

     else if ( "${argv[$iarg]}" == "sbatch" || "${argv[$iarg]}" == "no_sbatch" ) then
          echo " SLURM (sbatch) job requested."
     endif
  end
  @ ifound = 0
  if ( $slurm == "TRUE" ) then  
    if ( -f nbx_share_slurm.csh ) then
	@ ifound++

    else if ( $?CODESYSDIR ) then
	set sname = $CODESYSDIR/source/nubeam_comp_exec/nbx_share_slurm.csh
	if ( -f $sname ) then
	@ ifound++
	cp $sname .
	endif
    endif

    if ( $ifound == 0 ) then
	if ( $?NTCC_ROOT ) then
	    set sname = $NTCC_ROOT/etc/nbx_share_slurm.csh
	    if ( -f $sname ) then
	    @ ifound++
	    cp $sname .
	    endif
	endif
    endif
    if ( $ifound == 0 ) then
	echo " ?nbx_driver: failed to locate nbx_share_slurm.csh -- is nubeam_comp_exec installed?"
	exit 1
    endif

# OK run it

    ./nbx_share_slurm.csh $argv
    exit $status
  else
    if ( -f nbx_share.csh ) then
	@ ifound++

    else if ( $?CODESYSDIR ) then
	set sname = $CODESYSDIR/source/nubeam_comp_exec/nbx_share.csh
	if ( -f $sname ) then
	@ ifound++
	cp $sname .
	endif
	
    else if ( $?NTCC_ROOT ) then
	set sname = $NTCC_ROOT/etc/nbx_share.csh
	if ( -f $sname ) then
	@ ifound++
	cp $sname .
	endif
    endif

    if ( $ifound == 0 ) then
	echo " ?nbx_driver: failed to locate nbx_share.csh -- is nubeam_comp_exec installed?"
	exit 1
    endif

# OK run it

    ./nbx_share.csh $argv
    exit $status
    
  endif

