#!/bin/csh 

set yyyy = 2025
set mm = 07
set dd = 10
set yy = `echo $yyyy | cut -c3-`

set UnitID_atm1 = '300025010712790'
set UnitID_atm2 = '300025010534820'
set finaldir = /data/datasets/Buoys/E1/download
set downloaddir = /data/datasets/Buoys/E1/download/ODAS51

set grepstr = ${dd}${mm}${yy}
echo $grepstr

pushd $downloaddir
foreach file (`grep -l $grepstr *.sbd`)
    /bin/scp $file $finaldir/${yyyy}${mm}${dd}
end
popd

pushd $finaldir/${yyyy}${mm}${dd}
/bin/rm ${yyyy}${mm}${dd}A.txt

set fs_atm = `ls ${UnitID_atm1}_*.sbd ${UnitID_atm2}_*.sbd`
foreach f_atm($fs_atm)
   dos2unix -q $f_atm
   #cat $f_atm | tr '\n' ',' | tr -s "\*" "," >> ${yyyy}${mm}${dd}A.txt
   cat $f_atm | tr '\n' ',' >> ${yyyy}${mm}${dd}A.txt
   echo "" >> ${yyyy}${mm}${dd}A.txt
end 
popd

exit(0)

