#!/bin/sh
#

if [ $# -eq 5 ]
then


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

raprad_path=/home/mace/anvil_s1/DOE/code/rap_rad/Kato_code_update/rt/rt.rapradL/scenarios/bbflux/Integrated_Column

#raprad_script=test_script.sh
raprad_script=cloudy_script.sh

if [ $site = 'sgp' ]
then

echo using sgp C1 definitions
data_path=/home/mace/sgp/sgp.average.5min
data_prefix=sgp.average.5min

ciret2_path=/home/mace/sgp/sgpmmcrC1ciret2Mace.c1
ciret2_prefix=sgpmmcrC1ciret2Mace.c1

cp $raprad_path/rt1d.brdf.selection.Kato.sgp $raprad_path/rt1d.brdf.selection

echo $site > site
echo $facility > facility

fi

incre=1


while [ $incre -le $num_days ]
do

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

ls "$data_path"/*"$data_prefix"*"$the_day".000000.cdf* > IntCol_files.dat


check=`cat IntCol_files.dat | wc -l`

if [ $check -ne 0 ]
then

../../code_linux/incre_day_2k $the_day -1
prev_day=`cat prev_day`

ls "$ciret2_path"/*"$ciret2_prefix"*"$prev_day"*.cdf* > ciret2_files.dat
ls "$ciret2_path"/*"$ciret2_prefix"*"$the_day"*.cdf* >> ciret2_files.dat

check_ciret2=`cat ciret2_files.dat | wc -l`

if [ $check_ciret2 -ne 0 ]
then


# now run the idl code to generate the optical property file and the appended 5 minute file

run_flux.sh $1 1 $3 $4 $5

fi # if [ $check_ciret2 -ne 0 ]

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
