#!/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 = 'DY120'
set cruise = dy120
set ctdloc = /mnt/discofs/Sensors_and_Moorings/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_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_raw/${cpre}_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 ${cpre}_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