#!/bin/sh
#

if [ $# -eq 4 ]
then


the_day=$1
num_days=$2
site=$3
facility=$4

if [ $site = 'sgp' ]
then

echo using sgp C1 definitions

fivemin_path=/home/mace/sgp/sgp.average.5min.ciret4
robust_path=/home/mace/sgp/sgpmmcrcalC1.a1

fi


incre=1



while [ $incre -le $num_days ]
do

# see if there is a five minute file for this day

gunzip -f "$fivemin_path"/*"$the_day"*.temp.cdf.gz 2>> /dev/null
echo ls "$fivemin_path"/*"$the_day"*.temp.cdf > fivemin_files.dat
ls "$fivemin_path"/*"$the_day"*.temp.cdf > fivemin_files.dat
ls "$fivemin_path"/*"$the_day"*.temp.cdf > fivemin_files.dat

gunzip -f "$robust_path"/*Robust*"$the_day"*.cdf.gz 2>> /dev/null
echo ls "$robust_path"/*Robust*"$the_day"*.cdf
ls "$robust_path"/*Robust*"$the_day"*.cdf
ls "$robust_path"/*Robust*"$the_day"*.cdf > Robust_files.dat

check=`cat fivemin_files.dat | wc -l`
check2=`cat Robust_files.dat | wc -l`

if [ $check2 -eq 0 ]
then

robust_path=/home/mace/sgp/sgpmmcrmomC1.b1
gunzip -f "$robust_path"/*Robust*"$the_day"*.cdf.gz 2>> /dev/null
echo ls "$robust_path"/*Robust*"$the_day"*.cdf
ls "$robust_path"/*Robust*"$the_day"*.cdf
ls "$robust_path"/*Robust*"$the_day"*.cdf > Robust_files.dat

check2=`cat Robust_files.dat | wc -l`

fi

if [ $check -ne 0 -a $check2 -ne 0 ]
then


/usr/local/idl/idl/bin/idl run_precip_idl_code	



fi	# if [ $check -ne 0 ]


		../../code_linux/incre_day_2k $the_day
		the_day=`cat next_day`




	incre=`expr $incre + 1`


done


else

	echo Supply argument YYYYMMDD, num, site, facility, and year where YYYY is the year, MM is the month
	echo numer and DD is the day of the month and num is the number of days to process.
	echo site is the ARM site and facility is C1 or C2.
fi
