#!/bin/tcsh -fe

set stat = 0
set sdir = $PWD


goto PARSE
RET_PARSE:

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

which curl
if ($status) then
   wget https://afni.nimh.nih.gov/pub/dist/tgz/pkundu_meica_sample.tgz
else
   curl -O https://afni.nimh.nih.gov/pub/dist/tgz/pkundu_meica_sample.tgz
endif
tar xvzf pkundu_meica_sample.tgz
cd pkundu_meica_sample
   echo "********************************************************"
   echo "Follow examples in ./pkundu_meica_sample/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 Prantik Kundu MEICA denoising tools"
   echo "After the archive is downloaded and unpacked, see its README.txt"
   echo "for details."
   goto END

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