#!/bin/csh -f
#
#foreach i (`ls rawdata/*JC32*`)

# overhaul on jr302 may 2014, to fit with new python codas
# may need modification on cook/discovery to handle os75 and os150
cd /local/users/pstar/cruise/data/vmadcp

echo "synchronising raw data"
rsync -av jcrfs_adcp75/* raw_os75
# jcrfs_adcp75 is link to raw data on jrlb
# raw_os75 is link to directory in codas_shared available in virtual box.
# raw_os75 -> codas_shared/vmdas_data/jr281_os75      so raw directory must already be configured in codas_shared

echo "making links in old codas directory"
foreach i (`ls raw_os75/*.*`) # list all *.* to avoid collecting N1R directory
#set num = `echo $i | awk -F'_' '{print substr($2,length($2)-2,3)}'`
# this extracts the file extension, e.g. for i = rawdata/D344os150001_000000.ENR, num is then set as ENR, ZBS 19.10.2009
set num = `echo $i | awk -F'.' '{print substr($1,length($1)-9,3)}'`
set fname = `echo $i | awk '{print substr($1,10,19)}'` # start at char 10 allows for removing raw_os75/ 

cd /local/users/pstar/cruise/data/vmadcp/v75

set linkdir = rawdata{$num}

if (! -e $linkdir) then
  echo making $linkdir
  mkdir $linkdir
endif


set rfile = ../../${i}
set lfile = ${linkdir}/${fname}
if (! -e ${lfile}) then
  echo linking ${lfile} to ${rfile}
  ln -s ${rfile} ${lfile}
endif

end