#INPUT_DIR='../../agmet2017/30m/TMN_bts'
INPUT_DIR=$1

if [ -z ${INPUT_DIR} ]; then
	echo "INPUT_DIR is empty!"
	exit
fi

OUTPUT_DIR=$(basename ${INPUT_DIR})

if [ -z ${OUTPUT_DIR} ]; then
	echo "OUTPUT_DIR is empty!"
	exit
fi

echo "Input:" ${INPUT_DIR} ", Output:" ${OUTPUT_DIR}

mkdir -p ${OUTPUT_DIR}

for f in $(ls ${INPUT_DIR}); do
	echo " * File: " $f
	if [[ "${f}" != *.tiff ]]; then
		echo "   is not *.tiff"
		continue;
	fi

	basename=$(basename $f)

	gdalwarp -tap -co tiled=yes -co compress=deflate -t_srs EPSG:5179 -te 746100 1458750 1387980 2068470 -tr 30 30 ${INPUT_DIR}/${basename} ${OUTPUT_DIR}/${basename}
done

