#!/bin/tcsh -fe

set stat = 0
set sdir = "$PWD"

# [ST: Jun 14, 2021] modified @Install_MACAQUE_DEMO for SurfLayers
# driver scripts
set demo = SURFLAYERS_DEMO1

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

echo "++ Going to fetch demo:  ${demo}"

if ($use_curl == -1) then
   which curl
   if ($status) then
      set use_curl = 0;
   else
      set use_curl = 1;
   endif
endif

if ($use_curl == 0) then
   wget https://afni.nimh.nih.gov/pub/dist/tgz/$demo.tgz
else
   curl -O https://afni.nimh.nih.gov/pub/dist/tgz/$demo.tgz
endif
tar xvzf $demo.tgz
cd $demo

echo "Follow examples in ./${demo}/README.txt "
echo "********************************************************"

cd -

goto END

PARSE:
   set Narg = $#
   set use_curl = -1
   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]" == "-curl") then
         set use_curl = 1
         set donext = 0; goto NEXT		
      endif
      if ($donext && "$argv[$cnt]" == "-wget") then
         set use_curl = 0
         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:
cat <<EOF
   
Overview ~1~

This script fetches 6 driver scripts for 3 datasets from the 2021
OHBM poster and demo video about SurfLayers by:
Torrisi, Lauren, Taylor, Park, Feinberg, Glen

The 6 driver scripts work with three different sets of data:

  A) AFNI example 3T FT data with audiovisual paradigm:

        01_drive_AFNISUMA_FT_both 
        02_drive_AFNISUMA_FT_patch

     Data used with these scripts are distributed in the AFNI Bootcamp 
     download, specifically in the following directories:

        AFNI_data6/FT_analysis/FT/SUMA/
            The output of FreeSurfer's recon-all and AFNI's 
            @SUMA_Make_Spec_FS.

        AFNI_data6/FT_analysis/FT_analysis/FT.results/
            The output of AFNI's afni_proc.py, specifically directory
            output by the s05* script in the
            AFNI_data6/FT_analysis/FT_analysis (but you could use any
            of the volumetric output dirs from afni_proc.py).

   
  B) 7T left-hand finger tapping task with accelerated GRASE data:
 
        03_drive_AFNISUMA_M1_hemiOne 
        04_drive_AFNISUMA_M1_hemiSpec

     Data used with these scripts are included in this demo.
  
  C) 7T retinotopic 'meridian mapping' also with accelerated GRASE:

        05_drive_AFNISUMA_V1_calcarine
        06_drive_AFNISUMA_V1_20surfs

     Data used with these scripts are included in this demo.
   
After the archive is downloaded and unpacked, see its README.txt
for details.

Options ~1~

   [-wget] : Use wget to download archive. Script chooses by default
             with preference for curl
   [-curl] : Use curl to download archive. Script chooses by default
             with preference for curl

Examples ~1~

1) Just get everything, default operation:

    @Install_SURFLAYERS_DEMO1

2) Get everything, specify download tool:

    @Install_SURFLAYERS_DEMO1 -wget


EOF

   goto END

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