#!/usr/bin/ksh
#
# This script writes lists UAtha rmd files to database. It is intended to be used when for some 
# reason the automatic daily write of file names to the database has failed. 
#

## 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  
. $THMSOC/src/config/gbo_atha_rmd_mirror.config

#for year in 2008 2009 2010 2011
#do
year=2007
for school in vldr
do
  while read date
  do
    fileName=thg_l2_mag_vldr_${date}_v01.cdf

    #schName=$(echo $fileName |awk -F_ '{print substr($1,1,4)}')
    #year=$(echo $fileName | awk -F_ '{print "20"substr($1,5,2)}')
    #month=$(echo $fileName | awk -F_ '{print substr($1,7,2)}')
    #day=$(echo $fileName | awk -F_ '{print substr($1,9,2)}')
    #hr=$(echo $fileName | awk -F_ '{print $3}')
    #mn=$(echo $fileName | awk -F_ '{print substr($4,1,2)}')
    year=$(echo $date | awk -F_ '{print substr($1,1,4)}')
    month=$(echo $date | awk -F_ '{print substr($1,5,2)}')
    day=$(echo $date | awk -F_ '{print substr($1,7,2)}')
    dataTime="${year}-${month}-${day} 00:00:00" 
    mysql_table_name=gbo_VLDR_cdffiles
    fileSize=$(ls -l /disks/themisdata/thg/l2/mag/${school}/${year}/$fileName |awk '{print $5}')
    processTime=$(date -u '+%Y-%m-%d %T')
    processCode="HardDrive"
    echo "$mysql_table_name $dataTime $fileName $processTime $fileSize"
    ${PHP_SCRIPTS}/gmag_cdf.php $mysql_table_name $dataTime $fileName $processTime $fileSize
 done < /home/thmsoc/clrussells_stuff/filelists/gmag_cdf_list_${school}_${year}.txt
done
#done
exit 0