FFLAGS = -ffree-form -std=gnu -Ofast
LDLIBS = -lgfortran -lm
FC = gfortran

all:plot.svg

plot.svg: out.txt Makefile
	echo '\
	set term svg size 640,480 background rgb "white" font "times,14";\
	set out "$@";\
	set xlabel "x";\
	set ylabel "y";\
	set tics out;\
	set key bottom;\
	set title "Least-Squares fit of F_c(x)=c_1/x+c_2+c_3*x to some data" ;\
	plot "$<" index 0 with errorbars title "data"\
	,"$<" index 1 using 1:2 with lines title "F_c(x)"\
	,"$<" index 1 using 1:3 with lines title "F_c(x)_{c1-dc1}"\
	,"$<" index 1 using 1:4 with lines title "F_c(x)_{c2-dc2}"\
	,"$<" index 1 using 1:5 with lines title "F_c(x)_{c3+dc3}"\
	'|gnuplot

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

main: main.o ols.o qrgivens.o
main.o: ols.mod
ols.o: qrgivens.mod
qrgivens.o qrgivens.mod: ../qr.givens/qrgivens.f
	$(FC) $(FFLAGS) -c $<
%.o %.mod: %.f
	$(FC) $(FFLAGS) -c $<

clean:
	find . -type f -executable -delete
	rm -f *.o *.mod *.svg out*
