#! /bin/tcsh -ef

#
# segment_monkey
#
# REPLACE_WITH_ONE_LINE_SHORT_DESCRIPTION
#
# Original Author: REPLACE_WITH_FULL_NAME_OF_CREATING_AUTHOR
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2007/01/06 00:01:15 $
#    $Revision: 1.2 $
#
# 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 (-e $SUBJECTS_DIR/$1/tmp/control.dat == 0)  then
		echo ERROR: at least 1 control point must be selected
		exit 2
endif

if (-e $SUBJECTS_DIR/$1/scripts == 0)  mkdir $SUBJECTS_DIR/$1/scripts ; endif

if (-e $SUBJECTS_DIR/$1/scripts/brain.dat == 0)  \
	if (-e $SUBJECTS_DIR/scripts/brain.dat) \
		cp $SUBJECTS_DIR/scripts/brain.dat $SUBJECTS_DIR/$1/scripts ; \
	endif
endif

pushd $SUBJECTS_DIR/$1/scripts

foreach d (../tmp ../mri/T1 ../mri/wm ../mri/filled ../mri/brain ../surf)
    if (-e $d == 0)  mkdir $d ; endif
end




# this is just needed for diagnostic purposes
setenv DIAG 0x04048


rm -f ../mri/orig/COR-.info.bak
mv -f ../mri/orig/COR-.info ../mri/orig/COR-.info.bak
grep -v ^xform ../mri/orig/COR-.info.bak > ../mri/orig/COR-.info

# intensity normalize the data
mri_normalize -f ../tmp/control.dat -no1d ../mri/orig ../mri/T1
cp ../mri/T1/COR-.info ../mri/brain
cp ../mri/T1/COR-.info ../mri/wm


# label white matter
mri_segment $SUBJECTS_DIR/$1/mri/T1 $SUBJECTS_DIR/$1/mri/wm
inflate_subject $1

