# Set Path

set ROOT_path "C:\\Yeung\\Data\\DE_ERP\\"
set OAR_path "CNT\\OAR\\"
set EEG_path "EEG\\"
set AVG_path "AVG\\"
set EV2_path "EV2\\"

# Set Prefix and extentions

set prefix "DE2_"
set OAR_ext "_oar.cnt"
set ev2ext "_new.ev2"
set RL_ext "_RL"
set SL_ext "_SL"
set BC_ext "_BC"
set EEG_ext ".eeg"
set AVG_ext ".avg"

# Set Average names

set DC "_dim_correct"
set BC "_bright_correct"
set DE "_dim_error"
set BE "_bright_error"
set Bcomp "_bright_comp"
set Binc "_bright_inc"
set Dcomp "_dim_comp"
set Dinc "_dim_inc"

 

ENABLEOVERWRITEPROMPT F
set filelist {S01 S02 S03 }

foreach element $filelist {

# Set Filenames

set OAR_file $ROOT_path$OAR_path$prefix$element$OAR_ext
set RL_EEG_file $ROOT_path$EEG_path$prefix$element$RL_ext$EEG_ext
set SL_EEG_file $ROOT_path$EEG_path$prefix$element$SL_ext$EEG_ext
set RL_BC_EEG_file $ROOT_path$EEG_path$prefix$element$RL_ext$BC_ext$EEG_ext
set SL_BC_EEG_file $ROOT_path$EEG_path$prefix$element$SL_ext$BC_ext$EEG_ext

set RL_DC_file $ROOT_path$AVG_path$prefix$element$RL_ext$DC$AVG_ext
set RL_BC_file $ROOT_path$AVG_path$prefix$element$RL_ext$BC$AVG_ext
set RL_DE_file $ROOT_path$AVG_path$prefix$element$RL_ext$DE$AVG_ext
set RL_BE_file $ROOT_path$AVG_path$prefix$element$RL_ext$BE$AVG_ext
set RL_Dcomp_file $ROOT_path$AVG_path$prefix$element$RL_ext$Dcomp$AVG_ext
set RL_Dinc_file $ROOT_path$AVG_path$prefix$element$RL_ext$Dinc$AVG_ext
set RL_Bcomp_file $ROOT_path$AVG_path$prefix$element$RL_ext$Bcomp$AVG_ext
set RL_Binc_file $ROOT_path$AVG_path$prefix$element$RL_ext$Binc$AVG_ext

set SL_Dcomp_file $ROOT_path$AVG_path$prefix$element$SL_ext$Dcomp$AVG_ext
set SL_Dinc_file $ROOT_path$AVG_path$prefix$element$SL_ext$Dinc$AVG_ext
set SL_Bcomp_file $ROOT_path$AVG_path$prefix$element$SL_ext$Bcomp$AVG_ext
set SL_Binc_file $ROOT_path$AVG_path$prefix$element$SL_ext$Binc$AVG_ext

set eventfilename $ROOT_path$EV2_path$prefix$element$ev2ext

CREATESORT MySort_RL
MySort_RL -TypeEnabled YES
MySort_RL -TypeCriteria "21-39"


CREATESORT MySort_SL
MySort_SL -TypeEnabled YES
MySort_SL -TypeCriteria "11-18"
MySort_SL -CorrectEnabled YES
MySort_SL -CorrectCriteria BOTH

CREATESORT MySort_DC
MySort_DC -TypeEnabled YES
MySort_DC -TypeCriteria "21-24"

CREATESORT MySort_BC
MySort_BC -TypeEnabled YES
MySort_BC -TypeCriteria "25-28"

CREATESORT MySort_DE
MySort_DE -TypeEnabled YES
MySort_DE -TypeCriteria "31-34"

CREATESORT MySort_BE
MySort_BE -TypeEnabled YES
MySort_BE -TypeCriteria "35-38"

CREATESORT MySort_RL_Dcomp
MySort_RL_Dcomp -TypeEnabled YES
MySort_RL_Dcomp -TypeCriteria "21,22"

CREATESORT MySort_RL_Dinc
MySort_RL_Dinc -TypeEnabled YES
MySort_RL_Dinc -TypeCriteria "23,24"

CREATESORT MySort_RL_Bcomp
MySort_RL_Bcomp -TypeEnabled YES
MySort_RL_Bcomp -TypeCriteria "25,26"

CREATESORT MySort_RL_Binc
MySort_RL_Binc -TypeEnabled YES
MySort_RL_Binc -TypeCriteria "27,28"

CREATESORT MySort_SL_Binc
MySort_SL_Binc -TypeEnabled YES
MySort_SL_Binc -TypeCriteria "17,18"
MySort_SL_Binc -CorrectEnabled YES
MySort_SL_Binc -CorrectCriteria CORRECT

CREATESORT MySort_SL_Bcomp
MySort_SL_Bcomp -TypeEnabled YES
MySort_SL_Bcomp -TypeCriteria "15,16"
MySort_SL_Bcomp -CorrectEnabled YES
MySort_SL_Bcomp -CorrectCriteria CORRECT

CREATESORT MySort_SL_Dinc
MySort_SL_Dinc -TypeEnabled YES
MySort_SL_Dinc -TypeCriteria "13,14"
MySort_SL_Dinc -CorrectEnabled YES
MySort_SL_Dinc -CorrectCriteria CORRECT

CREATESORT MySort_SL_Dcomp
MySort_SL_Dcomp -TypeEnabled YES
MySort_SL_Dcomp -TypeCriteria "11,12"
MySort_SL_Dcomp -CorrectEnabled YES
MySort_SL_Dcomp -CorrectCriteria CORRECT

OPENFILE "$OAR_file"

# Epoch

EPOCH EVENTFILE $eventfilename -1000 1500 N Y Y N N MySort_RL $RL_EEG_file
EPOCH EVENTFILE $eventfilename -1000 1500 N Y Y N N MySort_SL $SL_EEG_file

CLOSEALL

# Baseline Correct

OPENFILE "$RL_EEG_file"
BASECOR USERDEFINED -100 0 N N $RL_BC_EEG_file
ARTREJ_EX REJCRITERIA N -500 800 Y -100 100 Y Y { FZ FCZ CZ CPZ PZ }
SAVEAS "$RL_BC_EEG_file"
CLOSEALL

OPENFILE "$SL_EEG_file"
BASECOR USERDEFINED -100 0 N N $SL_BC_EEG_file
ARTREJ_EX REJCRITERIA N -500 800 Y -100 100 Y Y { FZ FCZ CZ CPZ PZ }
SAVEAS "$SL_BC_EEG_file"
CLOSEALL

#AVG

OPENFILE "$RL_BC_EEG_file"


AVERAGE T N N "" 0 0 0 "MySort_DC" $RL_DC_file
AVERAGE T N N "" 0 0 0 "MySort_BC" $RL_BC_file
AVERAGE T N N "" 0 0 0 "MySort_DE" $RL_DE_file
AVERAGE T N N "" 0 0 0 "MySort_BE" $RL_BE_file
AVERAGE T N N "" 0 0 0 "MySort_RL_Bcomp" $RL_Bcomp_file
AVERAGE T N N "" 0 0 0 "MySort_RL_Dcomp" $RL_Dcomp_file
AVERAGE T N N "" 0 0 0 "MySort_RL_Binc" $RL_Binc_file
AVERAGE T N N "" 0 0 0 "MySort_RL_Dinc" $RL_Dinc_file

CLOSEALL

OPENFILE "$SL_BC_EEG_file"


AVERAGE T N N "" 0 0 0 "MySort_SL_Bcomp" $SL_Bcomp_file
AVERAGE T N N "" 0 0 0 "MySort_SL_Dcomp" $SL_Dcomp_file
AVERAGE T N N "" 0 0 0 "MySort_SL_Binc" $SL_Binc_file
AVERAGE T N N "" 0 0 0 "MySort_SL_Dinc" $SL_Dinc_file

CLOSEALL








DELETESORT MySort_DC
DELETESORT MySort_BC
DELETESORT MySort_BE
DELETESORT MySort_DE
DELETESORT MySort_RL_Bcomp
DELETESORT MySort_RL_Binc
DELETESORT MySort_RL_Dcomp
DELETESORT MySort_RL_Dinc
DELETESORT MySort_SL_Bcomp
DELETESORT MySort_SL_Binc
DELETESORT MySort_SL_Dcomp
DELETESORT MySort_SL_Dinc


CLOSEALL

}