LIFA = $(findstring lifa, $(shell hostname))
JS = $(if $(LIFA), /usr/users/fedorov/bin/js, js)
GRAPH = $(if $(LIFA), /usr/users/fedorov/bin/graph, graph)

files = main.js qspline.js pinterp.js cspline.js

all: plot.png plot.ps plot-cubic.png test.svg derivs.png akima-test.png

plot.png: points.dat makefile
	$(GRAPH) \
		--width 0.7 --height 0.7 \
		--output-format png -C\
		--x-label "x" --y-label "y" \
		--top-label "Polynomial vs. Quadratic Spline" \
		points.dat > plot.png

plot-cubic.png: points-cubic.dat makefile
	$(GRAPH) \
		--width 0.7 --height 0.7 \
		--output-format png -C\
		--x-label "x" --y-label "y" \
		--top-label "Polynomial vs. Cubic Spline" \
		points-cubic.dat > plot-cubic.png

plot.ps: points.dat makefile
	$(GRAPH) \
		--symbol 1 0.05 \
		--width 0.3 --height 0.2 \
		--output-format ps \
		--x-label "x" --y-label "y" \
		points.dat > plot.ps

derivs.png: derivs.dat makefile
	$(GRAPH) \
		--top-label "cspline w. 1st and 2nd derivs"\
		--symbol 1 0.05 \
		--width 0.7 --height 0.7 \
		--output-format png \
		--x-label "x" --y-label "y" \
		derivs.dat > derivs.png

points.dat: $(files)
	$(JS) main.js quad > points.dat

points-cubic.dat: $(files)
	$(JS) main.js cubic > points-cubic.dat

derivs.dat: $(files)
	$(JS) main.js derivs > derivs.dat

clean:
	rm -f *.dat *.png *.svg

akima-test.png: akima-test.dat makefile
	$(GRAPH) \
		--width 0.7 --height 0.5 \
		--output-format png \
		--x-label "x" --y-label "y" \
		--top-label "test-akima" \
		--y-limits -1.5 1.5\
		$< > $@
akima-test.dat: akima-test.js akima.js
	$(JS) $< > $@

test: test.svg
test.svg: test.dat makefile
	$(GRAPH) \
		--width 0.7 --height 0.5 \
		--output-format svg \
		--x-label "x" --y-label "y" \
		--top-label "test" \
		test.dat > test.svg

test.dat: test.js
	$(JS) test.js > test.dat
