#
# makefile
#
# Written by Taiji Yamada <taiji@aihara.co.jp>
#
# usage:
#	% make
#	% make all clean
#	% make all distclean
#
CXXFLAGS=-O3 -W -Wall -std=c++17
EXES=\
recurrence-modified_bernoulli_map	\
recurrence-lorenz_attractor	\
recurrence-rossler_attractor	\

ALL=$(EXES)	\
$(EXES:%=v%.dat) $(EXES:%=v%.eps) $(EXES:%=v%.pdf) $(EXES:%=v%.svg)	\
$(EXES:%=p%.dat) $(EXES:%=p%.eps) $(EXES:%=p%.pdf) $(EXES:%=p%.svg)	\

all: $(ALL)

v%.dat: % makefile
	./$< -t 1000 -i 1000 | dd of=$@ 2> /dev/null

p%.dat: % makefile
	./$< -t 1000 -i 2000 -P | dd of=$@ 2> /dev/null

vrecurrence-lorenz_attractor.dat: recurrence-lorenz_attractor makefile
	./$< -t 1000 -i 1000 -d .032 -T 5 | dd of=$@ 2> /dev/null

precurrence-lorenz_attractor.dat: recurrence-lorenz_attractor makefile
	./$< -t 1000 -i 2000 -d .016 -T 5 -P | dd of=$@ 2> /dev/null

vrecurrence-rossler_attractor.dat: recurrence-rossler_attractor makefile
	./$< -t 1000 -i 1000 -d .1 -T 2 | dd of=$@ 2> /dev/null

precurrence-rossler_attractor.dat: recurrence-rossler_attractor makefile
	./$< -t 2000 -i 2000 -d .05 -T 2 -P | dd of=$@ 2> /dev/null

vrecurrence-modified_bernoulli_map.%: XYRANGE=[0:1000]
precurrence-modified_bernoulli_map.%: XYRANGE=[0:2000]

vrecurrence-lorenz_attractor.%: XYRANGE=[0:1000]
precurrence-lorenz_attractor.%: XYRANGE=[0:2000]

vrecurrence-rossler_attractor.%: XYRANGE=[0:1000]
precurrence-rossler_attractor.%: XYRANGE=[0:2000]

v%.eps p%.eps: SERIF=Times-Roman
v%.eps p%.eps: SLANT=Times-Italic

v%.pdf p%.pdf: SERIF="Times New Roman"
v%.pdf p%.pdf: SLANT=:Italic

v%.svg p%.svg: SERIF="Times New Roman"
v%.svg p%.svg: SLANT=:Italic

#
define VPLOT_EPS
set palette gray negative;
unset colorbox;
set xlabel '{/$(SERIF) time {/$(SLANT) i}}';
set ylabel '{/$(SERIF) time {/$(SLANT) j}}';
set size square;
set xrange $(XYRANGE);
set yrange $(XYRANGE);
set mono;
plot input with dots notitle;
endef
export VPLOT_EPS

v%.eps: v%.dat
	GNUTERM='postscript eps enhanced level3 fontscale 1' gnuplot -e "set output '$@'; input='$<'; $$VPLOT_EPS"
#	GNUTERM='epscairo enhanced fontscale 1' gnuplot -e "set output '$@'; input='$<'; $$VPLOT_EPS"
	perl -pe "s/\/Pnt {.*} def/\/Pnt {stroke gsave 0 setlinecap 5 setlinewidth M 5 0 V stroke grestore} def/" -i '$@'

#
define VPLOT_PDF
set palette gray negative;
unset colorbox;
set xlabel '{/$(SERIF) time {/$(SLANT) i}}';
set ylabel '{/$(SERIF) time {/$(SLANT) j}}';
set size square;
set xrange $(XYRANGE);
set yrange $(XYRANGE);
set mono;
plot input with dots notitle;
endef
export VPLOT_PDF

v%.pdf: v%.dat
	GNUTERM='pdf enhanced fontscale .425' gnuplot -e "set output '$@'; input='$<'; $$VPLOT_PDF"
#	GNUTERM='pdfcairo enhanced fontscale 1' gnuplot -e "set output '$@'; input='$<'; $$VPLOT_PDF"

#
define VPLOT_SVG
set palette gray negative;
unset colorbox;
set xlabel '{/$(SERIF) time {/$(SLANT) i}}';
set ylabel '{/$(SERIF) time {/$(SLANT) j}}';
set size square;
set xrange $(XYRANGE);
set yrange $(XYRANGE);
set mono;
plot input with dots notitle;
endef
export VPLOT_SVG

v%.svg: v%.dat
	GNUTERM='svg enhanced fontscale 1' gnuplot -e "set output '$@'; input='$<'; $$VPLOT_SVG"
#	perl -pe "s/<circle id='gpDot' (.*)\/>/<circle id='gpDot' \1 fill='currentColor'\/>/" -i '$@'
	perl -pe "s/<circle id='gpDot' r='[^']*' (.*)\/>/<rect id='gpDot' width='$(shell printf '%g\n' $$(echo 530/1000 | bc -l))' height='$(shell printf '%g\n' $$(echo 530/1000 | bc -l))' \1 fill='currentColor'\/>/" -i '$@'

#
define PPLOT_EPS
set palette gray negative;
unset colorbox;
set xlabel '{/$(SERIF) time {/$(SLANT) i}}';
set ylabel '{/$(SERIF) time {/$(SLANT) j}}';
set size square;
set xrange $(XYRANGE);
set yrange $(XYRANGE);
set mono;
plot input with image notitle;
endef
export PPLOT_EPS

p%.eps: p%.dat
	GNUTERM='postscript eps enhanced level3 fontscale 1' gnuplot -e "set output '$@'; input='$<'; $$PPLOT_EPS"
#	GNUTERM='epscairo enhanced fontscale 1' gnuplot -e "set output '$@'; input='$<'; $$PPLOT_EPS"
	perl -pe "s/\/Pnt {.*} def/\/Pnt {stroke gsave 0 setlinecap 1 setlinewidth M 1 0 V stroke grestore} def/" -i '$@'

#
define PPLOT_PDF
set palette gray negative;
unset colorbox;
set xlabel '{/$(SERIF) time {/$(SLANT) i}}';
set ylabel '{/$(SERIF) time {/$(SLANT) j}}';
set size square;
set xrange $(XYRANGE);
set yrange $(XYRANGE);
set mono;
plot input with image notitle;
endef
export PPLOT_PDF

p%.pdf: p%.dat
	GNUTERM='pdf enhanced fontscale .425' gnuplot -e "set output '$@'; input='$<'; $$PPLOT_PDF"
#	GNUTERM='pdfcairo enhanced fontscale 1' gnuplot -e "set output '$@'; input='$<'; $$PPLOT_PDF"

#
define PPLOT_SVG
set palette gray negative;
unset colorbox;
set xlabel '{/$(SERIF) time {/$(SLANT) i}}';
set ylabel '{/$(SERIF) time {/$(SLANT) j}}';
set size square;
set xrange $(XYRANGE);
set yrange $(XYRANGE);
set mono;
plot input with image notitle;
endef
export PPLOT_SVG

p%.svg: p%.dat
	GNUTERM='svg enhanced fontscale 1' gnuplot -e "set output '$@'; input='$<'; $$PPLOT_SVG"
#	perl -pe "s/<circle id='gpDot' (.*)\/>/<circle id='gpDot' \1 fill='currentColor'\/>/" -i '$@'
	perl -pe "s/<circle id='gpDot' r='[^']*' (.*)\/>/<rect id='gpDot' width='1' height='1' \1 fill='currentColor'\/>/" -i '$@'

#
clean:
	rm -f $(EXES) $(EXES:%=v%.dat) $(EXES:%=p%.dat) .DS_Store

distclean: clean
	rm -f $(ALL)
