#! /bin/csh -f

#
# countncond -- counts the number of non-null conditions in a 
# list of paradigm files.
#
# Original Author: Doug Greve
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2007/01/09 22:41:16 $
#    $Revision: 1.4 $
#
# 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 == 0) then
  echo "USAGE: countncond parfile1 <parfile2 ...>"
  exit 1;
endif

set parfilelist = ($argv);

set partmp = /tmp/par.$$
set condlist = ();
foreach par ($parfilelist)
  if(! -e $par) then
    echo "ERROR: cannot find $par"
    exit 1; 
  endif
  cp $par $partmp
  pushd /tmp > /dev/null
  dos2unix par.$$ >& /dev/null
  popd > /dev/null
  set tmp = `cat $partmp | awk '{if($2 != "") print $2}' | sort | uniq `
  set condlist = ($condlist $tmp);
end

set TF = /tmp/countncond.$$
rm -f $TF
#echo $TF

foreach c ($condlist)
  if("$c" == "0") continue;
  #echo "--$c--"
  echo $c >> $TF
end

set ucondlist = `cat $TF | sort | uniq`;
echo $#ucondlist

rm -f $TF
rm -f $partmp


exit 0;
