#! /bin/csh
# process - C Shell script to remove processed OASIS data 
#		and reprocess it all

# Copyright (C) 2001 MBARI
# Author: Kent Headley
# MBARI provides this documentation and code "as is", with no warranty,
# express or implied, of its quality or consistency. It is provided without
# support and without obligation on the part of the Monterey Bay Aquarium
# Research Institute to assist in its use, correction, modification, or
# enhancement. This information should not be published or distributed to
# third parties without specific written permission from MBARI.
#

set oasis = /oasis
set cfg = $oasis/cfg
set bin = $oasis/bin
set tmp = $oasis/tmp
set TRUE = 1
set FALSE = 0
set doM1 = $FALSE
set doM2 = $FALSE
set nonomatch

@ i = 1

while ($i <= $#argv )

  if ( ($argv[$i] == "m1") || ($argv[$i] == "M1") ) then
    set doM1 = $TRUE
  endif

  if ( ($argv[$i] == "m2") || ($argv[$i] == "M2") ) then
    set doM2 = $TRUE
  endif
  @ i++
end 


if ($doM1 == $TRUE) then
set mooring = m1
cd $oasis/$mooring

foreach name (adcp emeter fluor gf gps hr1 hr2 hr3 hr4 hs2 isus metsys microcat oasis pco2 shutter0 specprr specprr.volts tstring )
	rm -f data/$name $tmp/$name.tmp
	cp $cfg/$mooring/$name.hdr data/$name
	foreach year ( 2002 2003 )
	    foreach file ($name/$year*)
		awk -f $bin/concat.awk -v year=$year $file >> $tmp/$name.tmp
	    end
	    sort $tmp/$name.tmp >> data/$name
	    rm -f $tmp/$name.tmp
	end
end
  cd $oasis/$mooring/data
  awk -f $bin/ctdmean.awk ctd > ctd.mean
endif

# Take everything but the comments and append it to the header
#foreach name (nitrate)
	#rm -f data/$name
	#cp $cfg/$mooring/$name.hdr data/$name
	#foreach file ($name/2000* $name/2001*)
		#grep -v \# $file >> data/$name
	#end
#end

if ($doM2 == $TRUE) then
set mooring = m2
cd $oasis/$mooring

foreach name (adcp emeter error fluor gf gps hs2 isus metsys microcat oasis pco2 shutter0 specprr specprr.volts tstring )
	rm -f data/$name $tmp/$name.tmp
	cp $cfg/$mooring/$name.hdr data/$name
	foreach year ( 2002 2003 )
	    foreach file ($name/$year*)
		awk -f $bin/concat.awk -v year=$year $file >> $tmp/$name.tmp
	    end
	    sort $tmp/$name.tmp >> data/$name
	    rm -f $tmp/$name.tmp
	end
end
  cd $oasis/$mooring/data
  awk -f $bin/ctdmean.awk ctd > ctd.mean

endif

#foreach mooring (m1 m2)
#	cd $oasis/$mooring/data
#	awk -f $bin/ctdmean.awk ctd > ctd.mean
#end




