#! /bin/tcsh -f

#
# fsr-checkxopts
#
# USAGE: fsr-checkxopts xoptsfile
#
# Checks the xoptsfile to make sure that there are no errors in it.
#
# Original Author: Doug Greve
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2007/01/06 00:01:14 $
#    $Revision: 1.3 $
#
# 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: fsr-checkxopts,v 1.3 2007/01/06 00:01:14 nicks Exp $';

if($#argv < 1) exit 0;
set xoptsfile = $argv[1];

if(! -e $xoptsfile) then
  echo "ERROR: cannot find $xoptsfile"
  exit 1;
endif

# Get the number of commands in the xopts file
set n1 = `grep -v \# $xoptsfile | awk '{print $1}' | sort | wc -l`;

# Get the number of unique commands in the xopts file
set n2 = `grep -v \# $xoptsfile | awk '{print $1}' | sort | uniq | wc -l`;

# If they are not the same, then it means that there is a replication
if($n1 != $n2) then
  echo "ERROR: multiple occurrences of a command in expert options file $xoptsfile"
  exit 1;
endif

exit 0
