#!/bin/csh -f
#
#Script by BAK on cruise jc032 to create symbolic links.
#Modified by BGW for cruise di346
#Modified by CPA to import oxygen files from /Drobo 
#The assumption is that the raw files are named
#in a way that identifies the instrument, eg
# ctd_jc032_001_ctm.cnv
#
#
# The initial foreach command will need to be modified for each cruise.
#cd data
#cd ctd
# modded bak di368
# bak jc069 for cfc file names like JC069ST72.csv. I wonder what they'll do when they get to station 100 !
cd
cd cruise/data
cd ctd
cd BOTTLE_CFC
# jc069, cfc csv files copid in from mac mini using rsync on mac mini
#####foreach i (`ls discofs/D368*csv`)
#####set copyfile = `echo $i | awk '{print substr($1,9,22)}'`
######echo $copyfile
#####if (! -e $copyfile) then
#####   echo Copying file $i
#####   cp -p  $i .
#####endif
#####
#####end


#foreach i (`ls JC069ST??.csv`)

# 2 digit station numbers
foreach i (`ls JR302_station_??.csv`)
#echo $i
set num = `echo $i | awk '{print substr($1,15,2)}'`
set num = 0$num # 2 digit nums require an extra zero

set cruise = 'jr302'
#echo $num

set linkfile = cfc_${cruise}_${num}_raw.csv 
#echo $linkfile

if (! -e $linkfile) then
  echo Making link $linkfile for raw file $i
  ln -s $i $linkfile
endif
end

# 3 digit station numbers
foreach i (`ls JR302_station_???.csv`)
#echo $i
set num = `echo $i | awk '{print substr($1,15,3)}'`
set num = $num # 2 digit nums require an extra zero

set cruise = 'jr302'
#echo $num

set linkfile = cfc_${cruise}_${num}_raw.csv 
#echo $linkfile

if (! -e $linkfile) then
  echo Making link $linkfile for raw file $i
  ln -s $i $linkfile
endif
end