#!/bin/csh -f # # is-surface # # 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 = 'is-surface dev'; if($#argv != 1) then echo "is-surface file" echo "" echo "Determines whether file is a volume-encoded surface file" echo "by looking at the number of columns and rows." echo "If there are more than 1000 columns and the number" echo "of rows is 1, then it is assumed to be a surface." echo "" echo "Prints 0 (is NOT surface) or 1 (IS surface) to stdout. " echo "" echo "If an error occurs, exists with 1" echo "" echo $VERSION exit 1; endif set fname = $argv[1]; shift; if(! -e $fname) then echo "ERROR: cannot find $fname" exit 1; endif set tmpfile = /tmp/is-surface.$$.tmp rm -f $tmpfile set tmpfile2 = /tmp/is-surface.$$.tmp2 rm -f $tmpfile2 set cmd = (mri_info --o $tmpfile --ncols $fname) $cmd >& $tmpfile2 if($status) then cat $tmpfile2 rm -f $tmpfile $tmpfile2 exit 1; endif @ ncols = `cat $tmpfile` set cmd = (mri_info --o $tmpfile --nrows $fname) $cmd >& $tmpfile2 if($status) then cat $tmpfile2 rm -f $tmpfile $tmpfile2 exit 1; endif @ nrows = `cat $tmpfile` # Assume it is a surface if there are more than 1000 columns # and the number of rows == 1 if($ncols > 1000 && $nrows == 1) then echo 1 else echo 0 endif rm -f $tmpfile $tmpfile2 exit 0