#!/bin/sh
#############################################################################
#
# r.sun_year.sh
#
# SCRIPT:   	r.sun automation
# AUTHOR(S):	Paolo Zatelli - 2003/08/11
# PURPOSE:  	Automatically runs r.sun for an entire year
#   	    	
# COPYRIGHT:	2003 Paolo Zatelli
# LICENZE:	GPL 2.0 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.
#
#############################################################################
# r.sun_year.sh uses GRASS' module r.sun to evaluate the net solar radiation on
# the ground for each day of the year. A map for each day is created, named
# after the energy parameter by adding the number of the day.
# For example if energy='solar_energy' otuput maps are 'solar_energy_1',
# solar_energy_2', ..., 'solar_energy_365'.

if [ $# -ne 5 ] ; then
	echo "Usage: sh r.sun_year.sh dtm aspect slope energy latitude"
	echo "Where dtm is the name of the DTM map"
	echo "Where aspect is the name of the aspect map"
	echo "Where slope is the name of the slope map"
	echo "Where energy is the base name for the energy output map"
	echo "Where latitude is the value of the location latitude"
	exit
fi

START_DATE=`date`
echo "Start: "$START_DATE

for i in $(seq 1 365); do
	echo "Day: $i of 365"

	r.sun elevin=${1} aspin=${2} slopein=${3} energyout=${4}_$i latitude=${5} dej=$i
done

echo "Done!"
STOP_DATE=`date`
echo "Start: "$START_DATE
echo "Stop: "$STOP_DATE

