#!/bin/csh
#to get directly GIFA file form the spectro
#set verbose
if ($#argv == 7 || $#argv == 9 ) then
   set localpath=$1
   set spect=$2
   set user=$3
   set disk=$4
   set exp=$5
   set expno=$6
   set conv=$7
else if ($#argv == 0) then
  echo -n 'destination :'
  set localpath=$<
  echo -n 'spectrometer : '
  set spect=$<
  echo -n 'user-name :    '
  set user=$<
  echo -n 'disk :     '
  set disk=$<
  echo -n 'exp-name :     '
  set exp=$<
  echo -n 'exp-no :     '
  set expno=$<
  echo -n 'Do you want to convert to GIFA ?                (y/n) :'
  set conv=$<
else
  echo 'usage : ' $0 ' dest spectro user disk experiment expno conv-switch '
  exit
endif
if ($conv == 'y') then
  if ($#argv == 9) then
     set del=$8
     set trf=$9
  else
     echo -n 'Do you want to delete uxnmr data file after transfer? (y/n) :'
     set del=$<
     echo -n 'Do you want to realize the transfer? (n just converts) (y/n):'
     set trf=$<
  endif
else
  set del='n'
  set trf='y'
endif
if ($trf == 'y') then
   mkdir -p $localpath/$exp/$expno
   echo transfering /$disk/data/$user/nmr/$exp/$expno from guest@$spect
# REMARK !!!!
# this is SGI syntax !
# on certain machine, (eg HP) the following line sould be
#   rcp -r guest@$spect\:/$disk/data/$user/nmr/$exp/$expno $localpath/$exp/$expno
#
    if ("`uname`" != "IRIX") then
	echo WARNING Shell-Script might be buggy on non-SGI machines
    endif
    rcp -r guest@$spect\:/$disk/data/$user/nmr/$exp/$expno $localpath/$exp
endif
if ($conv == 'y') then
     set direc = $localpath/$exp/$expno
     echo converting $direc
     if  ( -e $direc/ser ) then
        set dim=2
     else if ( -e $direc/fid ) then
        set dim=1
     else
        echo "GETEXP : No data file found"
     endif

     ux2cach.sh $direc $direc/data $dim 1
     if ($del == 'y') then
       rm -rf $direc/ser $direc/fid $direc/pdata
     endif
endif
echo done
exit
