#!/bin/csh -f
#
#copy the raw and SBE-processed CTD files from the ship machine
#then make links to the files to be ingested by mexec using the expected name format
cd /local/users/pstar/cruise/data
# May need to edit the following lines on a new cruise
#set cpre = 'CTD_JC192'
set cpre = 'JC192_CTD'
set cruise = jc192
set ctdloc = /local/users/pstar/mounts/mnt_cruise_data/Specific_Equipment/CTD/
#set ctdloc = /local/users/pstar/mounts/mnt_cruise_data/Specific_Equipment/CTD/CTD # jc191 CTD appears twice in the directory name
#bak jc191 we don't want all the cnvs with derived quantities, so explicitly pick up the raw and align_ctm
rsync -av ${ctdloc}/Processed\ data/${cpre}_???.cnv ctd/ASCII_FILES/
#rsync -av ${ctdloc}/Processed\ Data/${cpre}_???_Align.cnv ctd/ASCII_FILES/
rsync -av ${ctdloc}/Processed\ data/${cpre}_???_Align_CTM.cnv ctd/ASCII_FILES/
rsync -av ${ctdloc}/Raw\ data/*.bl ctd/ASCII_FILES/
rsync -av ${ctdloc}/Processed\ data/${cpre}*.ros ctd/ASCII_FILES/
rsync -av ${ctdloc}/Raw\ data/*.hex ctd/RAW_CTD_FILES/
rsync -av ${ctdloc}/Raw\ data/*.XMLCON ctd/RAW_CTD_FILES/
rsync -av ${ctdloc}/Raw\ data/*.hdr ctd/RAW_CTD_FILES/
rsync -av ${ctdloc}/Processed\ data/${cpre}*.btl ctd/ASCII_FILES/
rsync -av ${ctdloc}/SBE35\ data/SBE35_???.cap ctd/ASCII_FILES/SBE35
cd ctd/ASCII_FILES

foreach i (`ls ${cpre}_???_Align_CTM.cnv`)
   set num = `awk -v nm="$i" 'BEGIN {print substr(nm,index(nm,"_Align")-3,3)}'`
   set linkfile = ctd_${cruise}_${num}_ctm.cnv 
   #echo $linkfile
   if (! -e $linkfile) then
      echo Making link $linkfile for raw file $i
     ln -s $i $linkfile
   endif
end

foreach i (`ls ${cpre}_???.bl`)
   set num = `awk -v nm="$i" 'BEGIN {print substr(nm,index(nm,".bl")-3,3)}'`
   set linkfile = ctd_${cruise}_${num}.bl
   if (! -e $linkfile) then
      echo Making link $linkfile for raw file $i
      ln -s $i $linkfile
   endif
end

#below block could be commented out if your cruise doesn't have much of a problem with spikes
foreach i (`ls ${cpre}_???.cnv`)
   set num = `awk -v nm="$i" 'BEGIN {print substr(nm,index(nm,"cnv")-4,3)}'`
   set linkfile = ctd_${cruise}_${num}_noctm.cnv 
   #echo $linkfile
   if (! -e $linkfile) then
      echo Making link $linkfile for raw file $i
     ln -s $i $linkfile
   endif
end

cd SBE35
foreach i (`ls SBE35_???.cap`)
   set num = `awk -v nm="$i" 'BEGIN {print substr(nm,index(nm,".cap")-3,3)}'`
   set linkfile = sbe35_${cruise}_${num}.asc
  #echo $linkfile
   if (! -e $linkfile) then
      echo Making link $linkfile for raw file $i
     ln -s $i $linkfile
   endif
end