#! /bin/csh -f

#
# subject-sess
#
# Original Author: Doug Greve
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2007/01/09 22:41:19 $
#    $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 VERSION    = '$Id: subject-sess,v 1.2 2007/01/09 22:41:19 nicks Exp $'

if($#argv == 0) then
  goto usage_exit;
  exit 1;
endif

set PWDCMD = `getpwdcmd`;

set n = `echo $argv | grep version | wc -l` 
if($n != 0) then
  echo $VERSION
  exit 0;
endif

set SessList = `getsesspath $argv`;
if($status || $#SessList == 0) then
  echo $SessList
  exit 1;
endif

## go through each session ##
foreach sess ($SessList)
 
  set snf = $sess/subjectname
  if(-e $snf) then
    set subject = `cat $snf`;
    echo $sess $subject
  else
    echo $sess no subjectname file
  endif
end

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

############--------------##################
usage_exit:
  echo "USAGE: subject-sess"
  echo "Options:";
  echo "   -sf sessidfile  ..."
  echo "   -df srchdirfile ..."
  echo "   -s  sessid      ..."
  echo "   -d  srchdir     ..."
  echo "   -version           : print version and exit"
  exit 1;
