MATRIX_DIR = ../matrix
CXXFLAGS += -std=c++23 -Wall -Wextra -I$(MATRIX_DIR)
LDLIBS += -lstdc++ -lm

all: Out.osc.png Out.lotka.png Out.test-order.png

Out.osc.png: out.txt Makefile
	echo '\
	set term png ;\
	set out "$@" ;\
	set tics out ;\
	set xlabel "{/:Italic t}" ;\
	set key bottom ;\
	set grid ;\
	set ytics 2 ;\
	set title "oscillator example from scipy.integrate.odeint" ;\
	plot [][-4:4]\
 	"$<" index 0 using 1:2 with linespoints pt 5 pointsize 0.5 title "{/:Italic θ(t)}"\
	,"$<" index 0 using 1:3 with linespoints pt 5 pointsize 0.5 title "{/:Italic ω(t)}"\
	'| tee log.gpi |gnuplot

Out.lotka.png: out.txt Makefile
	echo '\
	set term png ;\
	set out "$@" ;\
	set tics out ;\
	set xlabel "{/:Italic t}" ;\
	set key top left ;\
	set grid ;\
	set ytics 2 ;\
	set termoption enhanced ;\
	set title "Lotka-Volterra example from scipy.integrate.solve\\\_ivp" ;\
	plot [-1:][]\
 	"$<" index 1 using 1:2 with linespoints pt 5 pointsize 0.5 title "{/:Italic x}"\
	,"$<" index 1 using 1:3 with linespoints pt 5 pointsize 0.5 title "{/:Italic y}"\
	'| tee log.gpi |gnuplot

Out.test-order.png: out.txt Makefile
	echo '\
	set term png ;\
	set out "$@" ;\
	set tics out ;\
	set xlabel "{/:Italic x}" ;\
	set key top left ;\
	set grid ;\
	set termoption enhanced ;\
	set title "d²u/dx²=2, u|_{x=-10}=100, du/dx|_{x=-10}=-20" ;\
	plot [][]\
 	"$<" index 2 using 1:2 with linespoints pt 5 pointsize 0.5 title "{/:Italic u}"\
 	,"$<" index 2 using 1:($$1*$$1) with lines smooth csplines title "{exact}"\
	,"$<" index 2 using 1:3 with linespoints pt 5 pointsize 0.5 title "{/:Italic ú}"\
	'| tee log.gpi |gnuplot

out.txt: main
	./$< > $@

main: main.o ode.o matrix.o
main.o ode.o: ode.h $(MATRIX_DIR)/matrix.h
matrix.o: $(MATRIX_DIR)/matrix.cc $(MATRIX_DIR)/matrix.h
	$(CXX) $(CXXFLAGS) -c -o $@ $<

clean:
	$(RM) main log* *.o [Oo]ut* *.png
