# Last edited on 2005-01-16 16:16:23 by stolfi

PROG := ../frb_analyze

BAND := 001
CASES := \
  s2:0.84677 \
  f2:0.00000

all: 
	for cs in ${CASES}; do \
          ${MAKE} CASEARGS=$$cs single-set; \
        done

all-ab-shapes: 
	for cs in ${CASES}; do \
          ${MAKE} CASEARGS=$$cs single-set-ab-shapes; \
        done

all-ab-curves: 
	for cs in ${CASES}; do \
          ${MAKE} CASEARGS=$$cs single-set-ab-curves; \
        done

CURVE_DIR := curves-${BAND}
CANDS_DIR := cands-${BAND}

######################################################################
# Recursive make = caller must define ${CASEARGS}

CASEARGS := CASEARGS.IS.UNDEFINED

ifneq "/${CASEARGS}" "/CASEARGS.IS.UNDEFINED"

CASEFIELDS :=  ${subst :, ,${CASEARGS}}
SET :=         ${word 1,${CASEFIELDS}}
MAX_SHIFT :=   ${word 2,${CASEFIELDS}}

RAW_CANDS_DIR := ${CANDS_DIR}/${SET}/raw
REF_CANDS_DIR := ${CANDS_DIR}/${SET}/ref

RAW_CANDS_FILE := ${RAW_CANDS_DIR}/sample
REF_CANDS_FILE := ${REF_CANDS_DIR}/sample

ICB_FILE := ${REF_CANDS_DIR}/sample.icb
IFR_FILE := ${REF_CANDS_DIR}/sample.ifr
IFC_FILE := ${REF_CANDS_DIR}/sample.ifc

single-set: ${ICB_FILE} 

${PROG}: ..
	cd .. && make all

${ICB_FILE}: ${PROG} ${RAW_CANDS_FILE}.can
	${PROG} \
          -rawCandSet ${RAW_CANDS_FILE} \
          -rawCandDir ${RAW_CANDS_DIR} \
          -curveDir ${CURVE_DIR} -curveName f${BAND} \
          -band ${BAND} \
          -curveScale 0.084667 -origStep 0.021167 \
          -maxShift ${MAX_SHIFT} \
          -sampleErr 0.0016933 \
          -nSamples 513 \
          -refCandSet ${REF_CANDS_FILE} \
          -refCandDir ${REF_CANDS_DIR}
          
# 0.0016933 mm = 0.02 pixel
# 0.0042333 mm = 0.05 pixel
# 0.0084667 mm = 0.10 pixel
# 0.0127000 mm = 0.15 pixel

#          -posFormula \
#          -cosWindow \
#          \

single-set-ab-shapes: 
	for cand in ${shell cd ${REF_CANDS_DIR} && ls -d 000???} ; do \
          ${MAKE} SET=${SET} CAND=$$cand plot-ab-shapes ; \
        done

single-set-ab-curves: 
	for cand in ${shell cd ${REF_CANDS_DIR} && ls -d 000???} ; do \
          ${MAKE} SET=${SET} CAND=$$cand plot-ab-curves ; \
        done

######################################################################
# Recursive make - caller must defined ${CAND}

CAND := CAND.IS.UNDEFINED

ifneq "/${CAND}" "/CAND.IS.UNDEFINED"

CAND_DIR := ${REF_CANDS_DIR}/${CAND}

# Show A,B shape functions:

AB_SHAPES_EPS := ${CAND_DIR}/ab.eps

A_FSH := ${CAND_DIR}/a.fsh
B_FSH := ${CAND_DIR}/b.fsh

plot-ab-shapes: ${AB_SHAPES_EPS}

${AB_SHAPES_EPS}: plot-shapes ${A_FSH} ${B_FSH}
	plot-shapes 'a(t)' ${A_FSH} 'b(t)' ${B_FSH} > ${AB_SHAPES_EPS}
	ghostview ${AB_SHAPES_EPS}

# Show A,B curves:

AB_CURVES_EPS := ${CAND_DIR}/ab-cv.eps

A_FLC := ${CAND_DIR}/a.flc
B_FLC := ${CAND_DIR}/b.flc

plot-ab-curves: ${AB_CURVES_EPS}

${AB_CURVES_EPS}: plot-curves ${A_FLC} ${B_FLC}
	plot-curves 'a(t)' ${A_FLC} 'b(t)' ${B_FLC} > ${AB_CURVES_EPS}
	ghostview ${AB_CURVES_EPS}

# Show M,D shape functions:

M_FSH := ${CAND_DIR}/m.fsh
D_FSH := ${CAND_DIR}/d.fsh

MD_SHAPES_EPS := ${CAND_DIR}/md.eps

plot-md-shapes: ${MD_SHAPES_EPS}

${MD_SHAPES_EPS}: plot-shapes ${M_FSH} ${D_FSH}
	plot-shapes 'm(t)' ${M_FSH} 'd(t)' ${D_FSH} > ${MD_SHAPES_EPS}
	ghostview ${MD_SHAPES_EPS}

# Show Fourier transforms:

FOURIERS_EPS := ${CAND_DIR}/fouriers.eps

FOURIER_A_FFT := ${CAND_DIR}/a.fft
FOURIER_B_FFT := ${CAND_DIR}/b.fft
FOURIER_M_FFT := ${CAND_DIR}/m.fft
FOURIER_D_FFT := ${CAND_DIR}/d.fft

plot-one-fouriers: ${FOURIERS_EPS}

show-one-fouriers: ${FOURIERS_EPS}
	ghostview ${FOURIERS_EPS}

${FOURIERS_EPS}: plot-fouriers ${FOURIER_M_FFT} ${FOURIER_D_FFT}
	plot-fouriers ${FOURIER_M_FFT} ${FOURIER_D_FFT} > ${FOURIERS_EPS}

endif
# end make ${CAND}
######################################################################

endif
# end make ${SET}
######################################################################