#! /bin/bash
#
# Bill Barrett
#
# March 2016
#
# Notes: 
#   Check the tle's to see if new information is available.
#   If so update the AIM_CIPS_SCIENCE..Orbits and AIM_CIPS_SCIENCE..Sofie tables
#   Following that start the dark image database update

# make sure that user is aimsds
userName=`whoami`
if [ ${userName}  != "aimpro" ]
    then
    echo
    echo "Must be logged in as aimpro"
    echo
    exit 1
fi

source /aim/sds/common/scripts/setup_science_data_system.sh

file_date=`date +%Y_%j`
logFile=/aim/logs/cips/cips_day_${file_date}_orbit_update.txt

# Try to update the orbit list,
# writing the relevant information to the logfile
idl -e 'run_cips_daily_orbit_update_cron' 2>&1 | \
  grep -v "Compiled module" | \
  grep -v "Installation number" | \
  grep -v "Licensed for use" | tee -a ${logFile}

# Verify that the daily orbit file has been created
ls -l /aim/data/cips/orbit_data/orbit_data.txt | tee -a ${logFile}

# Now start the the dark image database update
nohup /aim/sds/common/scripts/mail_script_output.sh -M \
  james.craft@lasp.colorado.edu,adrian.gehr@lasp.colorado.edu \
  -S "CIPS Dark Image Db Update Log" -G "Warning" -G "Execution halted" -G "Error" -G "Fatal error" \
  /aim/sds/common/scripts/run_aim_script_rel.csh /aim/sds/cips/scripts/run_cips_daily_dark_image_db_update_cron.sh &

exit 0
# Done
