#!/usr/bin/ksh
#
# test_ksh.ksh
#
# just a script to test various commands

#	test="OK"
#	if [[ ! -s /home/thmsoc/lphilpotts_stuff/tmp/ts1_file_check || ! -s /home/thmsoc/lphilpotts_stuff/tmp/ts2_file_check || ! -s /home/thmsoc/lphilpotts_stuff/tmp/ts3_file_check || ! -s /home/thmsoc/lphilpotts_stuff/tmp/ts123_file_check ]]
#	then
#	   test="Check"
#	fi
#	print $test

if [[ -z $THMSOC ]]
  then
    THMSOC=/disks/socware/thmsoc_dp_current
    export THMSOC
  fi
  . ${THMSOC}/src/config/soc_it_to_me.config
	. /home/thmsoc/lphilpotts_stuff/ucalgary_wget_test/gbo_asi_rt_mirror_new.config
#	. ${THMSOC}/src/config/gbo_ualaska_mirror.config

#filenum=0
#RSYNC_LOGFILE=${RSLOGFILE}_pid$$_${filenum}_test
#echo "Testing Alaska rsync logfile" >> $RSYNC_LOGFILE
#REMOTE_SERVER_NAME="soc@themis-data.phys.ucalgary.ca:/data/themis/fluxgate/stream0"
#RSYNC_OPTIONS="-naz --port=8873 --log-format=\"%i|%n|%t|%l\" --stats" 
#/usr/local/bin/rsync $RSYNC_OPTIONS --rsh="ssh -i $HOME/.ssh/rsync_ucalgary_id_dsa -l soc" ${REMOTE_SERVER_NAME}/2011/09 . 
#/usr/local/bin/rsync -naz -v -e ssh $REMOTE_SERVER_NAME .

#/usr/local/bin/php /home/thmsoc/lphilpotts_stuff/test_php.php CCNV_TS123 2011-09-01 00:00:00 ./ccnv/2011/09/01/CCNV_TS123_09012011_000000.jpg >> /home/thmsoc/lphilpotts_stuff/test_php.log

#site=REDsR
#print $site
#if [[ $site = "LETH" || $site = "ROTH" || $site = "REDR" || $site = "LARG" ]];
#then
#    print "Yes"
#else
#    print "No"
#fi

#yyyymmdd=20110513
#mmddyyyy=$(echo $yyyymmdd |awk '{print substr($1,5,4) substr($1,1,4)}')
#print $mmddyyyy

#	if [[ ! -s /home/thmsoc/lphilpotts_stuff/tmp/ts1_file_check]]
#	then
#	   print "Check 1"
#	fi

#
#  	currentdate=$(date -u '+%Y%m%d')
#	school=test
#		## Now do Day Series file
#		#
#		printf '\n\t\t  >>>>> $school EPO GMAG JPG Availability - Day Series<<<<<\n\t\t\t\t%s\n\n' "`date`" >> /home/thmsoc/lphilpotts_stuff/${school}_gmag_epojpg_DSList_TMP.txt
#	
#		## Process sites
#		#
#		oldmonth=NaN
#		for date in $(cat ${CONFIGDIR}/date_list.txt)
#		do
#			yyyymmdd=$(echo $date |awk -F_ '{print $1}')
#			#print $yyyymmdd
#			## Set a start date - else 20050101 used
#			#
#			if (( $yyyymmdd < 20070101 ))
#			then
#				continue
#			fi
#			#
#			## Finish loop when current date reached
#			#
#			if [[ $yyyymmdd = $currentdate ]]
#			then
#				break
#			fi
#			#print $yyyymmdd
#			#
#			## Insert column headers every month
#			#
#			#mmddyyyy=$(echo $date |awk -F_ '{print $2}')
#			mmddyyyy=$(echo $yyyymmdd |awk '{print substr($1,5,4) substr($1,1,4)}')
#			#print $mmddyyyy
#			newmonth=$(echo $mmddyyyy | awk '{print substr($1,1,2)}')
#			if [[ $newmonth != $oldmonth ]]
#			then
#				printf "\n===============================================================================================\n" >> /home/thmsoc/lphilpotts_stuff/${school}_gmag_epojpg_DSList_TMP.txt
#				printf "YYYYMMDD|" >> /home/thmsoc/lphilpotts_stuff/${school}_gmag_epojpg_DSList_TMP.txt
#				for dtype in $(cat ${CONFIGDIR}/gmag_epojpg_dstype.txt)
#		                do
#					printf "%-8s|" $dtype >> /home/thmsoc/lphilpotts_stuff/${school}_gmag_epojpg_DSList_TMP.txt
#				done
#				printf "\n===============================================================================================\n" >> /home/thmsoc/lphilpotts_stuff/${school}_gmag_epojpg_DSList_TMP.txt
#				oldmonth=$newmonth
#			fi
#		done
				
			#
			## Now go through each date and datatype and 
			## see if a file is available
			#
		#	printf "%s|" $yyyymmdd >>${FILELISTS}/${school}_gmag_epojpg_DSList_TMP.txt 
		#	for dtype in $(cat ${CONFIGDIR}/gmag_epojpg_dstype.txt)
		#	do
		#		filename=${school}_${dtype}_${mmddyyyy}
		#		check=$(grep $filename ${FILELISTS}/${school}_${dtype}_list.txt)
		#		if [[ -z $check ]]
		#		then
		#			check=
		#		else
		#			check=X
		#		fi
		#		printf "%8s|" $check >> ${FILELISTS}/${school}_gmag_epojpg_DSList_TMP.txt 
		#	done
		#	printf "\n-----------------------------------------------------------------------------------------------\n" >> ${FILELISTS}/${school}_gmag_epojpg_DSList_TMP.txt
		#done


path=/home/thmsoc/lphilpotts_stuff/ucalgary_wget_test/thg/mirrors/asi/low_res_rsync/2011/10/19/whit_themis07/ut06/20111019_06_whit_themis07_vec1024.pgm.gz
#path=/disks/themisdata/thg/mirrors/asi/low_res_rsync/bad_files/20110815_07_kapu_themis21_vec1024.pgm.gz
isgzip=$(echo $path |grep .gz)
echo "isgzip $isgzip"
if [[ -n $isgzip ]]
then
    echo "yes"
fi
$(gunzip -t ${path} 2>&1)
gunziptest=$?	
if [[ $gunziptest -ne 0 ]]
then 
    echo "bad unzip"
    #mv ${path} $UCB_MIRROR_HOME/bad_files
fi
echo $gunziptest
gunziptest=$(gunzip -t ${path} 2>&1)
if [[ -n $gunziptest ]]
then
    echo "also bad"
    echo "gunziptest $gunziptest"
fi

exit 0
