#!/usr/bin/ksh
#
# gen_gmag_missing_cdf_list.ksh
#
# This script will generate a file listing what gmag
# cdfs are missing


## 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
 # . ${THMSOC}/src/config/ground_mag.config
  . /home/thmsoc/astraea2_test/ground_mag_test.config

## Process sites
#
	currentdate=$(date -u '+%Y%m%d')
	oldmonth=NaN
	for site in $(cat ${CONFIGDIR}/lc_site_list.txt)
	do
		rm -f ${LOCAL}/gmag_missing_cdf_list_${site}.txt
		for date in $(cat ${CONFIGDIR}/date_list.txt)
		do
			if [[ $date = $currentdate ]]
			then
				mv -f ${LOCAL}/gmag_missing_cdf_list_${site}.txt ${FILELISTS}/gmag_missing_cdf_list_${site}.txt
				break 
			fi
			checkcdf=$(grep $date ${FILELISTS}/gmag_cdf_list_${site}.txt)
			checkraw=$(grep $date ${FILELISTS}/gmag_raw_*_${site}.txt)
			if [[ -z $checkcdf && -n $checkraw ]]
			then
				echo $date >> ${LOCAL}/gmag_missing_cdf_list_${site}.txt
			fi
		done
		mv -f ${LOCAL}/gmag_missing_cdf_list_${site}.txt ${FILELISTS}/gmag_missing_cdf_list_${site}.txt
	done

#
## Cleanup
#
	exit 0
