#! /bin/csh
# getm2t - C Shell script to download data from M2 can under test
#	     and extract the data
#
set oasis = /oasis
set can = m2
set tncaddr = "2001M2"
set logfile = "dlinfo.log"

cd $oasis/test/raw
set noclobber
set noglob
set datafilebase = `date +%Y%j`
set failmail = "headley@mbari.org"

set i = 0
set datafile = $can.$datafilebase.00
while ( -e $datafile )
	@ i++
	set datafile = $can.$datafilebase.`printf "%02d" $i`
end

set starttime = `date +"%x %H:%M:%S"`

$oasis/bin/getoasis -a "$tncaddr" >& $datafile
set rtnsts = $status

set endtime = `date +"%x %H:%M:%S"`

set filesize = `ls -l $datafile|sed -f $oasis/bin/fs.sed`
unset noclobber
echo "$datafile,$starttime,$endtime,$filesize,$rtnsts" >> $logfile
set noclobber


if ( $rtnsts ) then
	/bin/mailx -s "Failed OASIS Download" $failmail << !
Download failure of file $datafile from can under test
Return code was $rtnsts
	0 = Success
	1 = Argument error (bad command line arguments)
	2 = Couldn't acquire TNC port (there's probably a hung download)
	3 = Couldn't connect to OASIS (it's not listening)
	4 = Download error (something broke after it connected)
	5 = Abort error (somebody killed the download)
`date`
!
endif

set errorfile = $oasis/test/m2/error/$datafile

if ( (-e $datafile) && !(-z $datafile) ) then
	$oasis/bin/extract -y1 -c $oasis/test/cfg/2001m2.cfg  $datafile >& $errorfile
endif

if ( -z $errorfile ) \
	rm -f $errorfile





