#!/bin/csh -f
#
#  ---------------------- rmosaic ------------------------------------
#  Name: ridl
#
#  Purpose:  run a remote idl job
#
#  Calling Sequence:
#     ridl job
#
#  Site Customization:
#     setenv SITE_RIDL_HOST <remote hostname>      (machine with fast idl)
#
#  Restrictions:
#     caller must have rsh priviledge on $SITE_RIDL_HOST 
#
#  11-apr-1995 (SLF) from rmosaic script
# -------------------------------------------------------------------
#
if $?DISPLAY then 
   if ($DISPLAY == ":0.0") then
      set rdisp="`hostname`"
   else
      set rdisp="`printenv DISPLAY`"
   endif
else
   set rdisp="`hostname`"
endif

set chk0=`echo $rdisp | grep :0`

if ("$chk0" =="") then
   set rdisp="$rdisp":0
endif

set rmcmd="setenv DISPLAY $rdisp"

set host=`hostname`

if ($host == $mosaic_host) then 
    eval "setenv DISPLAY $rdisp; setenv ys /ys; source /ys/gen/setup/idl_setup; $url "&
else 
#   check rsh priviledge
   if (-e /usr/bsd/rsh) then 
      set rpath=/usr/bsd
   else
      if (-e /usr/ucb/rsh) then
         set rpath=/usr/ucb
      else
         set chkrsh=`whereis rsh`
         if ($#chkrsh > 1) then
            set rpath=$chkrsh[2]:h
         else
            echo "Cannot find rsh on your machine..."
            exit
         endif
      endif
   endif
   set rtest="date | grep -i denied"
   set rcmd="$rpath/rsh $mosaic_host"
   set test="`$rcmd $rtest`" 

   if ("$test" != "") then
      echo "You do not have "RSH" priviledge to $mosaic_host..."
      exit
   endif
   echo "........ Spawning Remote IDL Job ..........."   
   echo " "
   set ridlh=`printenv SITE_RIDL_HOST`
   echo "$rpath/rsh $ridlh "'setenv DISPLAY '$rdisp'; setenv ys /ys; source /ys/gen/setup/idl_setup; idl '$1"&"
   $rpath/rsh $ridlh "'setenv DISPLAY '$rdisp'; setenv ys /ys; source /ys/gen/setup/idl_setup; /ys/gen/setup/run_idl '$1"&
endif

exit
