#! /bin/csh -f

#
# getsliceno -- gets XXX portion of stem_XXX.bxxxx
#
# 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
#


set VER = '$Id: getsliceno,v 1.2 2007/01/09 22:41:17 nicks Exp $';

if($#argv != 1) then
  echo "USAGE getsliceno bfilename"
  echo "  version: $VER"
  exit 1;
endif

set splt = `splitstr $argv[1]`;

@ n = $#splt
while($n > 0)
  if($splt[$n] == "_") break;
  @ n = $n - 1;
end

if($n == 0) then
  echo "ERROR: could not find an underscore"
  exit 1;
endif

@ a = $n + 1;
@ b = $n + 2;
@ c = $n + 3;

if($c > $#splt) then
  echo "ERROR: not enough characters past underscore"
  exit 1;
endif

printf %c%c%c $splt[$a] $splt[$b] $splt[$c]

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