######################################################################
#    Copyright (C) 2004,2005 Kurt Schwehr
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2, or (at your option)
#    any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software Foundation,
#    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
######################################################################

# FIX: rewrite process-core in python PIL!


default:
	@echo
	@echo "Welcome to the BPSIO-04 data directory"
	@echo
	@echo "images           - create all the corrected core photos"
	@echo "bpsio04.db       - Build the sqlite database"
	@echo "designate-points - use g3data to pic out features"

# python code adds more on to the table
# FIX: migrate to all python... FASTER
bpsio04.db: bpsio04.k15 weights.dat build-db.py date-reformat.bash
	rm -f $@
	./build_db.py

#
# for building the *.xpd files
#
designate-points: 277994_02-13.png
	@echo "Pick the lower left, lower right, upper right, and upper left"
	@echo "  corners in that order"
	g3data -scroll -coords 0 2640 1618 0 277994_02-13.png -scale 4

# Runs 0..(width-1)
# 0 (height-1) (width-1) 0 for correct coords
designate-points-odp: ODP-893A1H.png
	@echo "Pick the lower left, lower right, upper right, and upper left"
	@echo "  corners in that order"
	g3data -scroll -coords 0 2699 1408 0 $< -scale 4


# Keep this out of the cvs repository.  Too big!
277994_02-13.png:
	wget http://schwehr.org/Gaviota/bpsio-Aug04/core-photos/277994_02-13.png
277994_02-13.pgm: 277994_02-13.png
	convert 277994_02-13.png 277994_02-13.pgm

ODP-893A1H.png:
	wget http://schwehr.org/Gaviota/bpsio-Aug04/core-photos/$@
ODP-893A1H.pgm: ODP-893A1H.png
	convert $< $@

IMAGES:= ruler-gray-total.pgm
IMAGES+= 1g-gray-total.pgm
IMAGES+= 2g-gray-total.pgm
IMAGES+= 3g-gray-total.pgm
IMAGES+= 4g-gray-total.pgm
IMAGES+= 5g-gray-total.pgm
IMAGES+= 6g-gray-total.pgm
IMAGES+= odp-gray-total.pgm

#ruler-gray-total.pgm: ruler.xpd 277994_02-13.pgm
#	~/x/src/photo-giv/processCore 277994_02-13.pgm ruler.xpd ruler

odp-gray-total.pgm: odp.xpd ODP-893A1H.pgm
	foo=$< && ~/x/src/photo-giv/processCore ODP-893A1H.pgm  $< $${foo%%.xpd}-gray
	foo=$@ && convert $@ $${foo%%.pgm}.png

# Use a quick bash trick to drop the .xpd from the last arg
%-gray-total.pgm: %.xpd 277994_02-13.pgm
	foo=$^ && ~/x/src/photo-giv/processCore 277994_02-13.pgm $< $${foo%%.xpd}-gray
	foo=$@ && convert $@ $${foo%%.pgm}.png



images: ${IMAGES}

clean:
	rm -f [1-6]g-gray-*.{pgm,dat,png}
	rm -f ruler-gray-*.{pgm,dat,png}
	rm -f [1-6]g-{scale,sec,hist,ave}*.{dat,pgm}
	rm -f *~ tmp.dat *.html


real-clean: clean
	rm -f bpsio04.db 277994_02-13.pgm 277994_02-13.png
	rm -f *.pyc

#PYTHON_FILES=ams.py build_db.py list_missing.py
PYTHON_FILES=${wildcard *.py}
PYTHON_MODS=${PYTHON_FILES:.py=}
PYTHON_MOD_DOCS=${PYTHON_FILES:.py=.html}

docs: 
	echo ${PYTHON_MODS}
	pydoc -w ${PYTHON_MODS}
	code2html Makefile > Makefile-bpsio-data.html

docs-install: docs
	scp ${PYTHON_MOD_DOCS}  Makefile-bpsio-data.html kds:www/Gaviota/bpsio-Aug04/docs
	open http://schwehr.org/Gaviota/bpsio-Aug04/docs

help:
	open http://sourceforge.net/project/pysqlite
#open http://pysqlite.org


syntax highlighted by Code2HTML, v. 0.9.1