#! /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: 2011/03/02 20:16:39 $
#    $Revision: 1.4 $
#
# Copyright © 2011 The General Hospital Corporation (Boston, MA) "MGH"
#
# Terms and conditions for use, reproduction, distribution and contribution
# are found in the 'FreeSurfer Software License Agreement' contained
# in the file 'LICENSE' found in the FreeSurfer distribution, and here:
#
# https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
#
# Reporting: freesurfer@nmr.mgh.harvard.edu
#
#

set VERSION = '$Id: fsr-checkxopts,v 1.4 2011/03/02 20:16:39 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
