#!/usr/bin/ksh
#
# call_make_ae_index.ksh 
#
# This script calls make_ae_index.ksh which
# creates AE Index cdfs from the gmag cdfs
#
# Arguments:
#	
#		$1=n ; Number of days to create index, starting
#				 ; current date
#
#
#			Author: Tim Quinn
# 		Created: July 2009
#

#
## Set the environment variables
#
  if [[ -z $THMSOC ]]
  then
    THMSOC=/disks/socware/thmsoc_dp_current
    export THMSOC
  fi
#	. $THMSOC/src/config/soc_it_to_me.config
 . /home/thmsoc/astraea2_test/soc_it_to_me.config

	autoload pn_month
	FPATH=${THMSOC}/src/ksh/funcs

#
##
## Begin Work
##
#

#
## Check if LOCAL working directory exists
#

#
## Grab input variables
#
	integer ndays=$1
	integer counter=0

	if [[ -z $ndays ]]
	then
		integer ndays=5
	fi

	startDate=$(date -u '+%Y%m%d')
#start yesterday, 2009-12-11, jmm
        startDate=$(pn_day $startDate -1)
   
   #adding warning if big reprocessing is requested     
   if [[ $ndays -gt 7300 ]] #more than 20 years indicates a problem
   then
     echo " Your parameters indicate that more than 20 years of processing are requested."
     echo " Are you sure that you're calling this correctly?"
     echo " Exiting..."
     exit 1
   fi
     


#
## Start date loop
#

	while (( $counter < $ndays ))
	do
		make_ae_index_test.ksh $startDate
		startDate=$(pn_day $startDate -1)
		integer counter=$(( $counter + 1 ))
	done

#
## Cleanup
#
	exit 0
