#! /bin/tcsh -f # # fsr-getxopts # # USAGE: fsr-getxopts cmd xoptsfile # # Parses expert options for freesurfer recon. # Looks in xoptsfile for a line with cmd as the first item, # then returns the rest of the items on that line. Ignores # all lines with # in them, regardless of where on the line # they occur. # # Eg, if the file expert.opts contains: # mri_em_register -p .5 # Then # fsr-getxopts mri_em_register expert.opts # will return # -p .5 # # Original Author: Doug Greve # # Copyright © 2021 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 = 'fsr-getxopts dev'; if($#argv < 2) then # Dont print out anything here otherwise mess up recon-all # fsr-getxopts cmd xoptsfile1 xoptsfile2 ... exit 0; endif set cmd = $argv[1]; shift set xoptsfilelist = ($argv) # Go thru the list of xopts files foreach xoptsfile ($xoptsfilelist) # If it is not there, then an error if(! -e $xoptsfile) then echo "ERROR: cannot find $xoptsfile" exit 1; endif # Search for the command in the xoptsflie set tmp = `grep $cmd $xoptsfile | wc -l`; # If it is not there, move on to the next xopts file if($tmp == 0) continue # If there are multiple instances of the command, error. It is # ok for the same command to be in multiple files (see below) # but not in the same file if($tmp > 1) then echo "ERROR: cmd $cmd represented more than once in $xoptsfile" exit 1; endif # If it gets here, there is only one instance, so extract the options set tmp = `grep -v \# $xoptsfile | grep $cmd `; echo "$tmp[2-$#tmp]" # Do not search through any remaining xopts file. If the same command # exists in multiple files precedence is given to the first file break; end exit 0