#! /bin/csh
# getm4 - C Shell script to download data from OASIS mooring at M4
#	     and extract the data
#
# 05/1/00 - Entropy radio and scripts moved to Tsunami (KH)
# - Changed getoasis C-source and script to getrf9600
# - Changed name of serial port to match name created on Tsunami (/dev/m4r)
# - Changed file copy to reflect new path, now local on tsunami
# - added name to failmail list

set oasis = /oasis
set can = m4

cd $oasis/raw
set noclobber
set noglob
set datafilebase = `date +%Y%j`

# 05/11/00 (KH)
set failmail = "headley@mbari.org,zorba@mbari.org"
#,bahr@oc.nps.navy.mil"

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

# 05/11/00 (KH)
#$oasis/bin/getoasis -c $can >& $datafile
$oasis/bin/getrf9600 -c $can -p m4r >& $datafile 
set rtnsts = $status


if ( $rtnsts ) then
	/usr/bin/mailx -s "Failed OASIS Download" $failmail << !
Download failure of file $datafile 
Return code was $rtnsts
	0 = Success
	1 = Argument error (bad command line arguments)
	2 = Couldn't acquire TNC port (hung download or someone's using port)
	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

# 05/11/00 (KH)
#if ( (-e $datafile) && !(-z $datafile) ) then
#	rcp $datafile tsunami:$oasis/raw
#	remsh tsunami $oasis/bin/extractm4 $datafile
#	rcp tsunami:$oasis/raw/oasis.rcd oasis.rcd
#endif
if ( (-e $datafile) && !(-z $datafile) ) then
	$oasis/bin/extract $datafile
endif





