#!/bin/tcsh -f

set stat = 0
set sdir = $PWD


goto PARSE
RET_PARSE:

if ( -d ./AfniRetinoDemo) then
echo ""
echo "ERROR:"
echo "   Directory ./AfniRetinoDemo exists already"
echo "   If you want to download anew, remove it with:"
echo "\rm -rf ./AfniRetinoDemo"
echo "   then run `basename $0` $argv[*] again."
echo ""
echo "See ./AfniRetinoDemo/README.txt for further directions"
echo ""
goto END
   endif

which curl
if ($status) then
   wget http://afni.nimh.nih.gov/pub/dist/tgz/AfniRetinoDemo.tgz
else
   curl -O http://afni.nimh.nih.gov/pub/dist/tgz/AfniRetinoDemo.tgz
endif
tar xvzf AfniRetinoDemo.tgz

cd ./AfniRetinoDemo
   echo "********************************************************"
   echo "There are many processing options, only @Proc.All will"
   echo "be executed by this current command."
   echo "See ./AfniRetinoDemo/README.txt for details."
   echo "After @Proc.All is done processing, follow the suggested"
   echo "commands to check the results."
   echo "---------------------------------------------------------"
   tcsh ./@Proc.All |& tee p.all.log
   echo "********************************************************"
cd -
goto END

PARSE:
   set Narg = $#
   set cnt = 1
   while ($cnt <= $Narg)
		set donext = 1;
      if ($donext && "$argv[$cnt]" == "-echo") then
         set echo
         set donext = 0; goto NEXT		
      endif
      if ($donext && ("$argv[$cnt]" == "-h" || "$argv[$cnt]" == "-help")) then
         goto HELP
         set donext = 0;	 goto NEXT	
      endif
      if ($donext == 1) then
         echo "Error: Option or parameter '$argv[$cnt]' not understood"
         goto END
      endif
      
      NEXT:
		@ cnt ++
	end
   
goto RET_PARSE

HELP:
   echo "Installs and runs demo script for retinotopy pipeline demo."
   echo "After the archive is downloaded and unpacked, the default"
   echo "process is initiated. Follow the suggested commands at the"
   echo "end to check the results."
   echo "See the file ./AfniRetinoDemo/README.txt and output @RetinoProc -help "
   echo "for details."
   goto END

BEND:
   echo "Failed"
   set stat = 1
   goto END
   
END:
   exit $stat
