#! /bin/csh -f

### help
if ($#argv != 1) then
  echo ""
  echo "use: briklinks [doit]"
  echo ""
  echo "  make links to funct HEAD/BRIK's in 'afnilinks' subdir in scriptsdir"
  echo "  (so AFNI can compare scans)"
  echo "  only runs inside 'scripts' subdir inside of 'image' functscan dir"
  echo ""
  exit
endif

### args, check
set scriptsdir = $cwd
set scriptstail = $scriptsdir:t
set imagedir = $cwd:h
set imagetail = $imagedir:t
if ($scriptstail != "scripts") then
  echo "briklinks: ### only runs in inside an 'scripts' subdir"
  exit
endif
if ($imagetail != "image") then
  echo ": ### only runs in inside 'scripts' inside 'image' dir"
  exit
endif

### go
echo "briklinks: making links to BRIKs for AFNI in afnilinks dir"
if (! -e afnilinks) mkdir afnilinks
cd afnilinks; echo "cd afnilinks"
set i = 0
foreach file ( ../../*/*.BRIK ../../*/*.HEAD)
  set link = $file:t
  if (! -e $link) then
    ln -s $file $link
    @ i++
  endif
end
echo "briklinks: made $i new links"
