#/bin/csh -f

set stream  = $1
set infile = "../scs_raw/${stream}.ACO"
set otfile = "./${stream}.ACO"
echo infile $infile
echo otfile $otfile
echo $MACHTYPE

if ($MACHTYPE == 'x86_64-suse-linux') then
  set sedcom = "sed -u"
else if ($MACHTYPE == 'x86_64') then
  set sedcom = "sed -u"
else if ($MACHTYPE == 'i386') then
  set sedcom = "sed -l"
else
  set sedcom = "sed"
endif

echo $sedcom

pushd scs_sed

ps -ef | grep tail | grep ${stream} | sed 's/ /Q/' | sed 's/^.*Q//' | sed 's/^ *//' | sed 's/ .*$//' >! wk$$
foreach i (`cat wk$$`)
kill -9 ${i}
end
/bin/rm wk$$

if (-e ${otfile}) then
/bin/rm ${otfile}
endif

#tail -c 10000000000 -f ${infile} | ${sedcom}  's/, *,/,NaN,/g' | ${sedcom}  's/, *,/,NaN,/g' | ${sedcom}  's/://g' | ${sedcom} 's/,/ /g' >! ${otfile} &
# empty fields after the final comma will be lost, unless we add an extra comma at end of line.
# structure seems to be a c/r immediately before the newline recognised by sed as end of line. Repalce the cr by 'comma'
# take care of status variables with value 'A'
# take care of checksum on seatex-gll, value 'A*..'
# take care of glonass version CJ00


#tail -c 10000000000 -f ${infile} | ${sedcom} 's/\x0D//g' | ${sedcom} 's/$/,/' | ${sedcom} 's/,A,/,NaN,/g' | ${sedcom} 's/,A...,/,NaN,/g' | ${sedcom} 's/GJ00,$/NaN,/' | ${sedcom}  's/, *,/,NaN,/g' | ${sedcom}  's/, *,/,NaN,/g' | ${sedcom}  's/://g' | ${sedcom} 's/,/ /g' >! ${otfile} &


tail -c 10000000000 -f ${infile} | ${sedcom} -f /local/users/pstar/cruise/data/exec/jcr/sedscript >! ${otfile} &


popd