CSC = mcs
RUN = mono

all:Psi.svg E0.rmax.svg E1.rmax.svg E0.dr.svg

E0.rmax.svg:out.E0.rmax.txt Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set title "Hydrogen, matrix, E_0 convergence with r_{max}";\
	set xlabel "r_{max}, Bohr radius";\
	set ylabel "E_{0}, Hartree";\
	plot [][-0.6:]\
	 "$<" using 1:3 with linespoints pointtype 5 title "calculated"\
	,-0.5 with lines title "exact"\
	'|gnuplot

E1.rmax.svg:out.E1.rmax.txt Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set title "Hydrogen, matrix, E_1 convergence with r_{max}";\
	set xlabel "r_{max}, Bohr radius";\
	set ylabel "E_{1}, Hartree";\
	plot []\
	 "$<" using 1:4 with linespoints pointtype 5 title "calculated"\
	,-0.125 with lines title "exact"\
	'|gnuplot

E0.dr.svg:out.E0.dr.txt Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set title "Hydrogen, matrix, E_0 convergence with dr";\
	set xlabel "dr, Bohr radius";\
	set ylabel "E_{0}, Hartree";\
	set key left;\
	plot []\
	 "$<" using 2:3 with linespoints pointtype 5 title "calculated"\
	,-0.5 with lines title "exact (-0.5 Hartree)"\
	'|gnuplot

out.E0.dr.txt:main.exe
	>$@
	for dr in 0.02 0.05 0.1 0.15 0.2 0.25 0.3; do \
	echo $$dr; mono main.exe -rmax:6 -dr:$$dr 1>/dev/null 2>>$@ \
	; done

out.E1.rmax.txt:main.exe
	>$@
	for R in 7 8 9 10 11 12 13; do \
	echo $$R; mono main.exe -rmax:$$R -dr:0.1 1>/dev/null 2>>$@ \
	; done

out.E0.rmax.txt:main.exe
	>$@
	for R in 2 3 4 5 6; do \
	mono main.exe -rmax:$$R -dr:0.1 1>/dev/null 2>>$@ \
	; done

Psi.svg:out.data.txt Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set xlabel "r, Bohr radius";\
	set ylabel "f(r), arb. u.";\
	set title "Hydrogen atom ground state radial wave-function";\
	plot\
	 "$<" index 1 using 1:2 with points pointtype 7 pointsize 0.5 title "calculated"\
	,"$<" index 1 using 1:3 with lines title "exact"\
	'| gnuplot

out.data.txt:main.exe
	$(RUN) $< > $@

main.exe:main.cs matlib.dll
	$(CSC) -reference:matlib.dll $<

matlib.dll: \
	../../matlib/matrix/vector.cs \
	../../matlib/matrix/matrix.cs \
	../../matlib/jacobi-eigenvalue/EVD.cs \
	../../matlib/jacobi-eigenvalue/jacobi.cs
	$(CSC) -target:library -out:./$@ $^

clean:
	$(RM) *.dll *.exe *.svg out*

#%.exe: %.cs
#	$(CSC) -t:exe $(addprefix -r:,$(filter %.dll,$^)) $(filter %.cs,$^)
#
#%.dll: %.cs
#	$(CSC) -t:library -out:./%.dll $(addprefix -r:,$(filter %.dll,$^)) $(filter %.cs,$^)
