#!/usr/bin/env bash

if [ "$1" == "" ]; then
	echo "Start year required. Exit."
	exit 1
elif [ "$2" == "" ]; then
	echo "End year required. Exit."
	exit 1
elif [ "$3" == "" ]; then
	echo "Observation required. Exit."
	exit 1
fi

syear=$1
eyear=$2
obs=$3

cd ..

for year in $(seq ${eyear} -1 ${syear})
do
	months=""
	for mon in {01..12}
	do
		if [ "$months" == "" ]; then
			months="${year}01"
		else
			months="$months,$year$mon"
		fi
	done
	echo -n "Calculating $year :: $months ... "
	if [ "$obs" == "aeronet" ]; then
		(time ipython preproc/nc2scores_${obs}.py all ${obs} $months &> ${year}.log)
	elif [ "$obs" == "modis" ]; then
            for mod in `cat ./conf/models.json | grep '": {' | awk -F: '{ printf $1 }' | sed 's/"//g'`
            do
		echo "Calculating $year for $mod ..."
		(time ipython preproc/nc2scores_${obs}.py ${mod} ${obs} $months &> ${year}_${mod}.log)
	    done
	fi
	echo "done.";
done
