#! /bin/csh -f

#
# getnslices
#
# Original Author: Doug Greve
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2007/01/09 22:41:17 $
#    $Revision: 1.2 $
#
# Copyright (C) 2002-2007,
# The General Hospital Corporation (Boston, MA). 
# All rights reserved.
#
# Distribution, usage and copying of this software is covered under the
# terms found in the License Agreement file named 'COPYING' found in the
# FreeSurfer source code root directory, and duplicated here:
# https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferOpenSourceLicense
#
# General inquiries: freesurfer@nmr.mgh.harvard.edu
# Bug reports: analysis-bugs@nmr.mgh.harvard.edu
#


if($#argv != 1 && $#argv != 2) then
  echo "USAGE: getnslices stem <firstslice>"
  echo '$Id: getnslices,v 1.2 2007/01/09 22:41:17 nicks Exp $';
  exit 1;
endif

set stem = $argv[1];
if($#argv == 2) then
  set firstslice = $argv[2];
else
  set firstslice = `getfirstsliceno $stem`
  set st = $status;
  if($st) then
    echo "ERROR: cannot find any files with $stem";
    exit 1;
  endif
endif

set lastslice = `getlastsliceno $stem`;
set st = $status;
if($st) then
  echo "ERROR: too many slices for  $stem";
  exit 1;
endif

@ nslices = 1 + $lastslice - $firstslice;
echo $nslices;

exit 0;
##########################################
