#! /bin/csh

# makeheaders - Shell script to automatically generate header files for
# mooring deployments. Templates are parsed for field tags, which are 
# replaced by this script.
# Mooring name and deployment date are required parameters:
# e.g., makeheaders M1 '12 April, 2001'
#

set nonomatch
set outDir = /oasis/cfg/template
set templateDir = /oasis/cfg/template
set srcDir = /oasis/src

if ($#argv < 2) then
  echo "\nUsage: $0 <mooring> <'deployment date'>\n"
  echo "       Edit $srcDir/makeheaders to change instrument names, add instruments, etc.\n"
  exit
endif

echo Creating Headers for $1, $2

# Instrument Names (must match up with files below)
set inames = ( ADCP CTD "Oasis Errors" Fluorometer "Ground Fault" GPS HS2 ISUS Metsys OASIS pCO2 "PRR Shutter" "PRR" "PRR Voltages" "Inductive Modem String")

#initialize
@ i = (1)

foreach file (adcp ctd error fluor gf gps hs2 isus metsys oasis pco2 shutter0 specprr specprr.volts tstring)
  echo $inames[$i]...
  cat $templateDir/$file.hdt|sed -e "s/<mooring>/$1/" >& $outDir/$file.hdr
  cat $outDir/$file.hdr|sed -e "s/<deployment_date>/$2/" >& $outDir/$file.hdr
  cat $outDir/$file.hdr|sed -e "s/<instrument>/$inames[$i]/" >& $outDir/$file.hdr

  @ i++

end
echo Processing Complete
