#!/bin/tcsh -fe

set stat = 0
set sdir = $PWD

set demo = FAT_MVM_DEMO

goto PARSE
RET_PARSE:

if ( -d ./$demo) then
echo ""
echo "ERROR:"
echo "   Directory ./$demo exists already"
echo "   If you want to recreate it, remove it with:"
echo "\rm -rf ./$demo"
echo "   then run `basename $0` $argv[*] again."
echo ""
echo "Otherwise to run demos, see content of ./$demo/README.txt"
echo ""
goto END
   endif

which curl
if ($status) then
   wget http://afni.nimh.nih.gov/pub/dist/data/$demo.tgz
else
   curl -O http://afni.nimh.nih.gov/pub/dist/data/$demo.tgz
endif
tar xvzf $demo.tgz
cd $demo
   echo "********************************************************"
   echo "Follow the description and commandline examples"
   echo "   in ./$demo/FAT_MVM_README.txt"
   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 the demo archive for combining FATCAT output with 3dMVM"
   echo "statistical analysis."
   echo "After the archive is downloaded and unpacked, see the text file"
   echo "FAT_MVM_README.txt for details."
   goto END

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