#!/usr/bin/ksh

## list_gmag_epojpgs.ksh
## 
## This script will make lists of what EPO JPGs have been 
## collected and converted 
##

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

## Check for lock file
#
  if [[ -a /var/tmp/list_gmag_epojpgs_lock ]] ; then
    exit 0
  fi
  echo $$ > /var/tmp/list_gmag_epojpgs_lock

## Set the environment variables
#
  os=$(uname -s)
  if [[ $os = "SunOS" ]]
  then
		varawk=nawk
	else
		varawk=awk
	fi

## Move to the directory containing the EPO data
#
cd $EPO_HOME

## Set a counter (n) and then set a variable to the
## first school name in the SCHOOL array which was
## defined in the config file above
#
n=0
school=${SCHOOL[$n]}

# Now lets start looping through the schools
#
while [[ -n $school ]]
do
	lcschool=$(echo $school | $varawk '{print tolower($1)}')
	rm -f ${FILELISTS}/${school}_*_list.txt

  ##################################################
	## Make lists for x, y, and z time series plots ##
  ##################################################
	#
	find $lcschool -name ${school}_TS1_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TS1_list.txt
	find $lcschool -name ${school}_TS2_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TS2_list.txt
	find $lcschool -name ${school}_TS3_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TS3_list.txt
	find $lcschool -name ${school}_TS123_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TS123_list.txt

  ##################################################
	## Make lists for B, D, and H time series plots ##
  ##################################################
	#
	find $lcschool -name ${school}_TSB_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TSB_list.txt
	find $lcschool -name ${school}_TSD_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TSD_list.txt
	find $lcschool -name ${school}_TSH_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TSH_list.txt
	find $lcschool -name ${school}_TSBDH_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TSBDH_list.txt

	#################################################
	## Make lists for x, y, and z day series plots ##
	#################################################
	#
	find $lcschool -name ${school}_DS1_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DS1_list.txt
	find $lcschool -name ${school}_DS2_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DS2_list.txt
	find $lcschool -name ${school}_DS3_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DS3_list.txt
	find $lcschool -name ${school}_DS123_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DS123_list.txt

	#############################################
	## Search for B, D, and H day series plots ##
	#############################################
	#
	find $lcschool -name ${school}_DSB_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DSB_list.txt
	find $lcschool -name ${school}_DSD_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DSD_list.txt
	find $lcschool -name ${school}_DSH_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DSH_list.txt
	find $lcschool -name ${school}_DSBDH_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DSBDH_list.txt

	#########################################
	## Make a list for Time Series Spectra ##
	#########################################
	#
	find $lcschool -name ${school}_TSpectra_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_TSpectra_list.txt

	#########################################
	## Make a list for Day Series Spectra  ##
	#########################################
	#
	find $lcschool -name ${school}_DSpectra_\* -exec /bin/basename {} \; > ${FILELISTS}/${school}_DSpectra_list.txt

  n=$(( n + 1 ))
  school=${SCHOOL[$n]}

done

	#
	## Cleanup
	#
  rm -f /var/tmp/list_gmag_epojpgs_lock

exit 0
