#!/usr/bin/ksh
#
# gbo_uc_rmd_mirror_batch.ksh - Calls the main mirror script
# for GBO mag data collected at UCalgary
#
#
# Creation Date:
#
#               22 April 2008 TimQuinn
#

#
## 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/gaia2_test/soc_it_to_me.config
#
## Determine dates to check
#
  thisYear=$(date -u '+%Y')
	thisMonth=$(date -u '+%m')
	integer ithisMonth=$thisMonth
	integer ilastMonth=$(( ithisMonth - 1 ))

	if (( $ilastMonth <= 0 ))
  then
    lastMonth=12
    lastYear=$(( $thisYear - 1 ))
  else
    lastYear=$thisYear
    lastMonth=$(echo $ilastMonth | awk '{printf("%02d",$1)}')
	fi

  thisYearMonth=${thisYear}_${thisMonth}
  lastYearMonth=${lastYear}_${lastMonth}

	for yearMonth in $thisYearMonth $lastYearMonth
	do
		year=$(echo $yearMonth | awk -F_ '{print $1}')
		month=$(echo $yearMonth | awk -F_ '{print $2}')
		/home/thmsoc/gaia2_test/gbo_uc_rmd_mirror_gaia.ksh $year $month
	done		

#
## Cleanup
#
  exit 0

