#! /bin/tcsh -f
#NOTE:
#	gammafit and gammaexp: these are parameters used to fit the hemodynamic response to a gamma function.  
#		For monkey fMRI data, *always* use the following:
#			BOLD data: -gammafit 0 1.25 –gammaexp 2
#			MION data: -gammafit 0 8 gammaexp 0.3

#USAGE: mkanalysis-sess (and mkanalysis-sess.new)
#Required Arguments
#	-analysis  analysisname : name of session-level functional analysis
#	-TR   TR                : TR value in seconds
#	-paradigm  parname      : name of paradigm file 2, 3, or 4 col
#	-designtype  type       : type of design. Legal values are: event-related, blocked, abblocked, retinotopy
#Optional Arguments
#	-fsd FSD               : functional subdirectory
#	-funcstem stem         : stem of functional data (default = f or fmc)
#	-motioncor             : use motion corrected data (see mc-sess) 
#	-runlistfile filename  : file with list of runs to include in analysis
#	-inorm                 : intensity normalize data
#	-rescale-target value  : inorm to value
#	-fwhm        FWHM      : Full-Width/Half-Max for in-plane smoothing (mm)
#	-nskip       N         : skip the first N time points in each run
#	-tpef      filename    : time-point exclude file name
#	-polyfit N             : fit trend with polynomial of order N
#	-extreg extregstem     : external regressor
#	-mcextreg              : use motion parameters as external regressors
#Event-Related and Blocked Arguments 
#	-nconditions Nc      : number of conditions (excluding fixation)
#	-timewindow  TW      : event time window (sec)
#	-prestim     PS      : event prestimulus window (sec)
#	-TER         TER     : temporal estimation resolution (sec)
#	-gammafit gfDelta gfTau : assume IRF is a gamma function
#	-gammaexp gfAlpha : gamma exponent (default is 2) 
#	-spmhrf nderiv    : assume SPM HRF with nderiv derivatives
#	-taumax      TauMax  : maximum lag for noise autocor and whitening (sec)
#	-timeoffset  toffset : time offset (sec) to add to each paradigm file
#	-mask  maskid : use masks/maskid to compute autocor and whitening
#	-acfbins nbins : spatially segment autocorrelation into nbins
#	-no-fix-acf    : do NOT compensate for resdualized ACF
#	-fix-acf       : DO compensate for resdualized ACF (default)
#	-autostimdur         : automatically compute stimulus duration
#	-noautostimdur       : do not automatically compute stimulus duration (default)
#	-fsv3-st2fir : generate design matrix like FreeSurfer Version 3 (and -no-)
#	-fsv3-whiten : perform whitening like FreeSurfer Version 3 (and -no-)
#	-fsv3 : set all fsv3 flags (FreeSurfer Version 3) (and -no-)
#	Retinotopy and AB Blocked Arguments (Required)
#	-ncycles     N       : number of cycles in each run
#Other Optional Arguments
#	-umask umask    : set unix file permission mask
#	-version        : print version and exit
#	-help           : my analysis has fallen, and it can't get up!
#	See also mkanalysis-sess.old
                                                                                                                                          

# go to where df and sf live
set calling_dir = `pwd`
cd ../mystudy

													    
# set some parameters
set paradigm = face_localizer_monkey.para
set TR = 2.0000
set TER_string = # "-TER $TR"	# in FS4 this is TR/20 by default...
set funcstem = fmcus2
set mask_stem = brain_fmcu
set analysis = a1u
set runlistfile = rlf1
# if tpef_string is empty do not exclude selected timepoints
set tpef_string = #"-tpef tpef"
# does not include condition 0!
set nconditions = 7

# get the right fitting parameters...
# taumax (temporal autocorrelation is higher foe MION than for BOLD)
set bold = 1	# if zero assume MION
set monkey = 1	# if zero assume human parameters

if ($monkey == 0) then
    echo "human bold"
    set gammafit = "2.25 1.25"
    set gammaexp = 2
    set taumax = 20
    set timewindow = 40
else
    if ($bold == 1) then
	echo "monkey bold"
	set gammafit = "0 1.25"
        set gammaexp = 2
	set taumax = 20
	set timewindow = 40
    else
	echo "monkey MION"
	set gammafit = "0 8"
	set gammaexp = 0.3
	set taumax = 40
	set timewindow = 80
    endif
endif

echo Processing analysis: ${analysis}
mkanalysis-sess \
    -fsd bold \
    -funcstem $funcstem \
    -analysis $analysis \
    -paradigm $paradigm \
    -dt blocked \
    -sf sf \
    -df df \
    -force $tpef_string \
    -inorm \
    -timewindow ${timewindow} \
    -polyfit 2 \
    -TR $TR ${TER_string}\
    -gammafit $gammafit \
    -gammaexp $gammaexp \
    -nconditions $nconditions \
    -runlistfile $runlistfile \
    -mask ${mask_stem} \
    -taumax $taumax \
    -acfbins 1 \
    -fix-acf \
    -noautostimdur \
    -motioncor -mcextreg








