BIN = ../cngf-pf
BIN2 = ../max_depth_simple_shear

PERMEABILITY = 2e-17
GRAIN_COMPRESSIBILITY = 1e-8
FLUID_PRESSURE_TOP = 100e3
#FLUID_PRESSURE_AMPL = 120e3
FLUID_PRESSURE_AMPL = 80e3
FLUID_PRESSURE_FREQ != echo "1.0/(3600*24)" | bc -l
NORMAL_STRESS_TOP = 200e3

timeseries.pdf: fig.gp timeseries.txt
	sh -c '\
		out=$$($(BIN2) \
			-k $(PERMEABILITY) \
			-P $(GRAIN_COMPRESSIBILITY) \
			-O $(FLUID_PRESSURE_TOP) \
			-a $(FLUID_PRESSURE_AMPL) \
			-q $(FLUID_PRESSURE_FREQ) \
			); \
		echo $$out; \
		max_def_depth=$$(echo $$out | cut -d" " -f1); \
		skin_depth=$$(echo $$out | cut -d" " -f2); \
		gnuplot -e "skin_depth=$$skin_depth; max_def_depth=$$max_def_depth" \
			fig.gp > $@'

timeseries.txt: sim.output00000.txt
	/bin/sh -c '\
	rm -f $@; \
	for f in sim.output*.txt; do \
		tail -n 1 "$$f" | cut -f2- >> $@; \
	done'

sim.output00000.txt: $(BIN)
	/bin/sh -c '\
	$(BIN) -L 8.0 \
	-n $(NORMAL_STRESS_TOP) \
	-f 0.40 \
	-F \
	-k $(PERMEABILITY) \
	-P $(GRAIN_COMPRESSIBILITY) \
	-O $(FLUID_PRESSURE_TOP) \
	-a $(FLUID_PRESSURE_AMPL) \
	-q $(FLUID_PRESSURE_FREQ) \
	-I $$( echo "60*10" | bc -l ) \
	-e $$( echo "3600*24*7" | bc -l ) sim'

clean:
	rm -f *.txt timeseries.pdf

.PHONY: clean
