# Generic make-include file for all applications
# For inclusion in an application-specific Make_test
# Not intended to be used as a standalone.
# C.D. 8/25/06

# For making the test output.  Results are put in out.test.diff.${PROJ}

# Instructions...
# 1.  Copy the Makefile from the top level directory to the application 
#     directory and edit it  for the options and architecture you desire
# 2.  Select the appropriate job launch command below by uncommenting
#     the appropriate set or creating one.
# 3.  Go to the application directory
# 4.  There should already be sample input and output files constructed from
#     code that you trust and the corresponding error tolerance files.
#     The sample files are called in.sample.TARGET out.sample.TARGET
#     and out.errtol.TARGET where TARGET is built from "make TARGET".
#     The test output file is called out.test.TARGET.
#     To create an error tolerance file, see instructions in seterrfile.pl.
# 5.  In the application directory, run the command
#        make -f Make_test check > & maketest.log
# 6.  Results are reported in files called out.test.diff.*
#     These files show differences between the sample and test output files.
#     using the error tolerance file to determine compliance.
#     Results are also reported to stderr so should appear in maketest.log
#     Look for lines with "Error" and "NOT OK".
# 7.  The variable CUSTOM is normally undefined in the master
#     Make_test file.  With this choice the test consists of comparing
#     stdout from a test run with the corresponding sample output file.
#     The rule for making this file is supplied here.
#     Changing CUSTOM to another name and supplying a rule in the master 
#     Make_test file for the file out.test${CUSTOM}.${PROJ} allows a custom 
#     test - for example a test comparing output other than stdout.
#     A corresponding out.sample${CUSTOM}.${PROJ} must be supplied.
# 8.  The variable PRECLIST lists precisions to test.
# 9.  The variable ADDMACRO is available to add further compiler macros to
#     the compilation.
#
# For the "heavy" application, follow instructions in heavy/Make_test

# Provisions for architecture-dependent job launching
# Change to suit...

# The job is launched with the commad
# ${LAUNCH} ./${PROJ} ${LAUNCH2} < in.sample.${PROJ} > out.test.${PROJ}

# SGI Origin
#LAUNCH = mpirun -np 4
#LAUNCH2 = 

# Linux MPI
#LAUNCH = /uufs/icebox/sys/pkg/mpich/1.2.1/bin/mpirun -np 4 -machinefile $$PBS_NODEFILE  # icebox
#LAUNCH = /usr/local/bin/vmi-launch -ncpus 8 --  #  VMI
#LAUNCH2 = 

# Linux QMP
#LAUNCH = mpirun.ch_gm -np 8
#LAUNCH2 = 

# Compaq Alpha cluster (tcsini)
#LAUNCH = prun -N $$RMS_NODES -n $$RMS_PROCS # (tcsini)
#LAUNCH = prun -p test -B 1 -N 1 -n 4  (CHPC sierra cluster - private node sierra1)
#LAUNCH2 =

# SP
#LAUNCH = poe 
#LAUNCH2 = -nodes 1 -tasks_per_node 4 -rmpool 1 -euilib ip -euidevice en0

# Scalar machine
LAUNCH =
LAUNCH2 = 

out.test.${PROJ}.${PREC}: ${PROJ}.${PREC} in.sample.${PROJ}.${PREC}
	${LAUNCH} ./${PROJ}.${PREC} ${LAUNCH2} < \
	  in.sample.${PROJ}.${PREC} > \
	  out.test.${PROJ}.${PREC}

out.test.diff.${PROJ}.${PREC}: out.test${CUSTOM}.${PROJ}.${PREC} \
	out.sample${CUSTOM}.${PROJ}.${PREC}
	perl ../headtail.pl ${PATTERNS} < \
	   out.test${CUSTOM}.${PROJ}.${PREC} > \
	   out.test.${PROJ}.${PREC}.tmp
	perl ../headtail.pl ${PATTERNS} < \
	   out.sample${CUSTOM}.${PROJ}.${PREC} > \
	   out.sample.${PROJ}.${PREC}.tmp
	perl ../diffn3.pl out.test.${PROJ}.${PREC}.tmp \
	   out.sample.${PROJ}.${PREC}.tmp \
	   out.errtol${CUSTOM}.${PROJ}.${PREC} > \
	   out.test.diff.${PROJ}.${PREC}
#	   /bin/rm -f out.test.${PROJ}.${PREC}.tmp \
#	   out.sample.${PROJ}.${PREC}.tmp

.PHONY: test
test:
	for prec in ${PRECLIST};\
	do\
	   for proj in ${PROJS};\
	   do\
	        ${MAKE} clean;\
	        ${MAKE} $$proj.$$prec "PRECISION=$$prec" ${ADDMACRO};\
	        ${MAKE} -f Make_test "PROJ=$$proj" "PREC=$$prec" out.test.diff.$$proj.$$prec;\
	        /bin/rm -f $$proj;\
	        /bin/rm -f localmake*;\
	   done;\
	done

.PHONY: buildonly
buildonly:
	for prec in ${PRECLIST};\
	do\
	   for proj in ${PROJS};\
	   do\
	        ${MAKE} $$proj.$$prec "PRECISION=$$prec" ${ADDMACRO};\
	   done;\
	done

.PHONY: runonly
runonly:
	for prec in ${PRECLIST};\
	do\
	   for proj in ${PROJS};\
	   do\
	        ${MAKE} -f Make_test "PROJ=$$proj" "PREC=$$prec" out.test.diff.$$proj.$$prec;\
	   done;\
	done

test_clean:
	for prec in ${PRECLIST};\
	do\
	   for proj in ${PROJS};\
	   do\
	     /bin/rm -f out.test.$$proj.$$prec.tmp out.sample.$$proj.$$prec.tmp;\
	     /bin/rm -f out.test.diff.$$proj.$$prec out.test.$$proj.$$prec; \
	   done;\
	done

