# Last edited on 2011-06-01 23:46:47 by stolfilocal

TAGS := un1 un2 un3

SPECIAL_PLOT_NAMES := \
  ${addprefix out/ptmp-TCn-PCB-,un1} \
  ${addprefix out/ptmp-TCn-PCA-,un2 un3} \
  ${addprefix out/ptmp-TCb-PCB-,un1} \
  ${addprefix out/ptmp-TCb-PCA-,un2 un3} \
  ${addprefix out/pcor-PCB-PD-,un1} \
  ${addprefix out/pcor-PCA-PD-,un2 un3} \
  ${addprefix out/pcor-PD-PS-,un1 un2 un3} \


SPECIAL_FULL_PLOTS := \
  ${addsuffix -full.png, ${SPECIAL_PLOT_NAMES}} \
  ${addsuffix -full.png, ${SPECIAL_PLOT_NAMES}}

SPECIAL_ICON_PLOTS := ${subst -full,-icon,${SPECIAL_FULL_PLOTS}}

.PHONY: \
  all \
  special-plots \
  standard-plots \
  single-plot \
  merged-plot

all: standard-plots special-plots 

special-plots: \
  ${SPECIAL_FULL_PLOTS} \
  ${SPECIAL_ICON_PLOTS}
  
RIX_LIST := 1 2 3
SOURCE_LIST := t
TAG_LIST := I T X
# TAG_LIST := X
QUANT_LIST := pres heat cams wlev flow
  
standard-plots:
	for rix in ${RIX_LIST} ; do \
          for dataset in ${SOURCE_LIST} ; do \
            for tag in ${TAG_LIST} ; do \
              for which in ${QUANT_LIST} ; do \
                ${MAKE} RIX=$$rix SOURCE="$$dataset" TAG=$$tag QUANT=$$which single-plot ; \
              done ; \
              ${MAKE} RIX=$$rix SOURCE="$$dataset" TAG=$$tag merged-plot ; \
            done ; \
          done ; \
        done

ifneq "/${RIX}" "/"
ifneq "/${SOURCE}" "/"
ifneq "/${TAG}" "/"
########################################################################
# Section for recursive make. Client must define ${RIX}, ${SOURCE}, ${TAG}.

MERGED_FULL_PLOT := out/plot-un${RIX}-${SOURCE}-${TAG}-full.png
MERGED_ICON_PLOT := out/plot-un${RIX}-${SOURCE}-${TAG}-icon.png

# Define plot parameters according to ${TAG}
DO_PLOT := NO
ifeq "/${TAG}" "/I"
  WIDTH := 3000
  XMIN := 0
  XMAX := 719
  XTICS := daily
  DO_PLOT := YES
endif
ifeq "/${TAG}" "/T"
  WIDTH := 3000
  XMIN := 0
  XMAX := 1990
  XTICS := weekly
  DO_PLOT := YES
endif
ifeq "/${TAG}" "/X"
ifeq "/${RIX}" "/3"
  WIDTH := 1800
  XMIN := 210.5
  XMAX := 293.5
  XTICS := hourly
  DO_PLOT := YES
endif
endif

ifneq "/${QUANT}" "/"
########################################################################
# Section for recursive make. Client must define ${RIX}, ${SOURCE}, ${TAG}, ${QUANT}.

DATA_FILES := \
  ${QUANT}-un${RIX}-${SOURCE}.txt \
  boom-un${RIX}.txt

GNUPLOT_INCLUDES := \
  xtics-${XTICS}.gnuplot \
  plot-common.gnuplot

STANDARD_FULL_PLOT := out/plot-${QUANT}-un${RIX}-${SOURCE}-${TAG}-full.png
STANDARD_ICON_PLOT := out/plot-${QUANT}-un${RIX}-${SOURCE}-${TAG}-icon.png

ifeq "/${DO_PLOT}" "/YES"
  
single-plot: ${STANDARD_FULL_PLOT} ${STANDARD_ICON_PLOT}

${STANDARD_FULL_PLOT}: \
             plot-reactor-${QUANT}.sh \
             ${GNUPLOT_INCLUDES} \
             ${DATA_FILES} \
             Makefile
	-rm -f ${STANDARD_FULL_PLOT} ${STANDARD_ICON_PLOT}
	-rm -f ${MERGED_FULL_PLOT} ${MERGED_ICON_PLOT}
	./plot-reactor-${QUANT}.sh ${RIX} ${SOURCE} ${TAG} ${WIDTH} ${XMIN} ${XMAX} ${XTICS}

else

single-plot:
	@echo "!! ${STANDARD_FULL_PLOT} not needed, skipped"
endif

# End of ${RIX}, ${SOURCE}, ${TAG}, ${QUANT} section.
########################################################################
endif

PARTIAL_FULL_PLOTS := \
  ${addprefix out/plot-, ${addsuffix -un${RIX}-${SOURCE}-${TAG}-full.png, ${QUANT_LIST}}}

ifeq "/${DO_PLOT}" "/YES"
  
merged-plot: ${MERGED_FULL_PLOT} ${MERGED_ICON_PLOT}

${MERGED_FULL_PLOT}: ${PARTIAL_FULL_PLOTS}
	convert ${PARTIAL_FULL_PLOTS} -append ${MERGED_FULL_PLOT}
	display ${MERGED_FULL_PLOT}

else

merged-plot:
	@echo "!! ${MERGED_FULL_PLOT} not needed, skipped"
endif


# End of ${RIX}, ${SOURCE}, ${TAG} section.
########################################################################
endif
endif
endif

# ----------------------------------------------------------------------
# Core/drywell and drywell/torus pressure-tracking plots:

UNIT1_EPOCHS := \
  140 242 290 320

out/pcor-PCB-PD-un1-full.png: pres-un1-t.txt plot-pressure-tracking.sh Makefile
	./plot-pressure-tracking.sh 1  1 2  'X' '1.56*(X - 85)' ${UNIT1_EPOCHS}

out/pcor-PD-PS-un1-full.png: pres-un1-t.txt plot-pressure-tracking.sh Makefile
	./plot-pressure-tracking.sh 1  2 3  'X' 'X - 20'        ${UNIT1_EPOCHS}

out/ptmp-TCn-PCB-un1-full.png: pres-un1-t.txt heat-un1-t.txt plot-pressure-temp.sh Makefile
	./plot-pressure-temp.sh 1  0 1  ${UNIT1_EPOCHS}

out/ptmp-TCb-PCB-un1-full.png: pres-un1-t.txt heat-un1-t.txt plot-pressure-temp.sh Makefile
	./plot-pressure-temp.sh 1  1 1  ${UNIT1_EPOCHS}


UNIT2_EPOCHS := \
  135 230 242 260

out/pcor-PCA-PD-un2-full.png: pres-un2-t.txt plot-pressure-tracking.sh Makefile
	./plot-pressure-tracking.sh 2  0 2  'X' 'X + 60'        ${UNIT2_EPOCHS}

out/pcor-PD-PS-un2-full.png: pres-un2-t.txt plot-pressure-tracking.sh Makefile
	./plot-pressure-tracking.sh 2  2 3  'X' 'X'             ${UNIT2_EPOCHS}

out/ptmp-TCn-PCA-un2-full.png: pres-un2-t.txt heat-un2-t.txt plot-pressure-temp.sh Makefile
	./plot-pressure-temp.sh 2  0 0  ${UNIT2_EPOCHS}

out/ptmp-TCb-PCA-un2-full.png: pres-un2-t.txt heat-un2-t.txt plot-pressure-temp.sh Makefile
	./plot-pressure-temp.sh 2  1 0  ${UNIT2_EPOCHS}


UNIT3_EPOCHS := \
  62 208 242 260

out/pcor-PCA-PD-un3-full.png: pres-un3-t.txt plot-pressure-tracking.sh Makefile
	./plot-pressure-tracking.sh 3  0 2  'X + 70' 'X + 20'   ${UNIT3_EPOCHS}

out/pcor-PD-PS-un3-full.png: pres-un3-t.txt plot-pressure-tracking.sh Makefile
	./plot-pressure-tracking.sh 3  2 3  'X' 'X - 50'        ${UNIT3_EPOCHS}

out/ptmp-TCn-PCA-un3-full.png: pres-un3-t.txt heat-un3-t.txt plot-pressure-temp.sh Makefile
	./plot-pressure-temp.sh 3  0 0  ${UNIT3_EPOCHS}

out/ptmp-TCb-PCA-un3-full.png: pres-un3-t.txt heat-un3-t.txt plot-pressure-temp.sh Makefile
	./plot-pressure-temp.sh 3  1 0  ${UNIT3_EPOCHS}

# ----------------------------------------------------------------------
# Icons:
        
out/%-icon.png: out/%-full.png
	convert out/$*-full.png -resize '160x' out/$*-icon.png