# ---------------------------------------------------------------------
# EEProbe - The Max Planck Institute of Cognitive Neuroscience EEP tools
#
# a demo how to use the "make" utility to maintain
# a couple of frequently used EEP commands
# (store this file as "Makefile" in your EEP cfg directory and adapt
#  to your own project)
#
# examples:
#
# to perform the rejection and averaging step for subject 04
#   make S=04 reject average
#
# to calc and show a new version of the grand averages
#   make grand
#   make view
# or
#   make grand view


# ---------------------------------------------------------------------
# definitions
#
# derive/store frequently used file/directory names


# the subject is expected from the command line ( S=<code> )
# this default should tell the user that she forget it...
S  =  __NO_SUBJECT__

# this means an "average version" - not used in this demo but you could
# define TRG, REJ, AVR_CFG, AVR_DIR etc. with the $(VERSION) 
# variable and maintain multiple independent ERP datasets this way
V  =  __NO_VERSION__

# rename for better readability
SUBJECT=$(S)
VERSION=$(V)

# the arguments needed for the EEP commands below, adapt this to your
# personal file naming scheme
# (it is good common practice to define nearly everything in a variable -
#  this allows to reuse it and you see all your definitions together)

CNT          =  ../fi$(SUBJECT)/fi$(SUBJECT).cnt
TRG          =  ../fi$(SUBJECT)/fi$(SUBJECT).trg
REJ          =  ../fi$(SUBJECT)/fi$(SUBJECT).rej

REJ_CFG      =  cntreject.cfg
AVR_CFG      =  cntaverage.cfg
AVR_DIR      =  ../fi$(SUBJECT)/auto
GRAND_CFG    =  avraverage.cfg
GRAND_DIR    =  ../grand
XAVR_DAT     =  think.dat
XAVR_CFG     =  xavr.cfg


# ---------------------------------------------------------------------
# rules
#
# (several commands stored under a simple name which are constructed 
#  using the variables above)
#
# IMPORTANT NOTE: commands are intended with a TAB, not with spaces!!!

reject:
	cntreject $(CNT) $(REJ_CFG) $(TRG) $(REJ)

scan:
	xcnt $(CNT) $(TRG) $(REJ)

average:
	cntaverage $(CNT) $(AVR_CFG) $(TRG) $(REJ) -p $(AVR_DIR)/

grand:
	avraverage $(GRAND_CFG) $(GRAND_DIR)

# this is more tricky; it finds present subjects/conditions by scanning 
# the project directory and calcs the grand average from all files found
grand_auto:
	avrretrieve --cfg -P .. -S 4 -F $(V) grand_tmp.cfg
	avraverage grand_tmp.cfg $(GRAND_DIR) $(V)

view:
	xavr $(XAVR_CFG) -D $(XAVR_DAT) -p $(GRAND_DIR)
