#! /bin/tcsh
# 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.

# process - C Shell script to remove processed OASIS data 
#		and reprocess it all
#

set oasis = /oasisnt/oasis
set cfg = $oasis/cfg
set bin = $oasis/bin
set tmp = $oasis/tmp
set AWK = gawk
set TRUE = 1
set FALSE = 0
set doM2 = $FALSE
set doM1 = $FALSE
set doEP1 = $FALSE
set doEP2 = $FALSE
set nonomatch

@ i = 1

while ($i <= $#argv )
  if ( ($argv[$i] == "m2")) then
    set doM2 = $TRUE
  endif
  if ( ($argv[$i] == "m1")) then
    set doM1 = $TRUE
  endif
  if ( ($argv[$i] == "ep1")) then
    set doEP1 = $TRUE
  endif
  if ( ($argv[$i] == "ep2")) then
    set doEP2 = $TRUE
  endif

  @ i++
end 

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

foreach name ( adcp emeter error fluor gf gps hr1 hr2 hr3 hr4 hs2 isus metsys microcat oasis pco2 shutter0 specprr specprr.volts sshutter tstring )
	rm -f data/$name $tmp/$name.tmp
	cp $cfg/$mooring/$name.hdr data/$name
	foreach year (2002)
	    foreach file ($name/$year*)
	      $AWK -f $bin/concat.awk -v year=$year $file >> $tmp/$name.tmp
	    end
	    /bin/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


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)
	    foreach file ($name/$year*)
	      $AWK -f $bin/concat.awk -v year=$year $file >> $tmp/$name.tmp
	    end
	    /bin/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

if ($doEP1 == $TRUE) then
set mooring = ep1
cd $oasis/$mooring

foreach name ( error fluor hr1 hr2 hr3 hs2 microcat oasis pco2 shutter0 specprr specprr.volts )
        rm -f data/$name $tmp/$name.tmp
	cp $cfg/$mooring/$name.hdr data/$name
	foreach year (2003)
	    foreach file ($name/$year*)
	       $AWK -f $bin/concat.awk -v year=$year $file >> $tmp/$name.tmp
	    end
	    /bin/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

if ($doEP2 == $TRUE) then
set mooring = ep2
cd $oasis/$mooring

foreach name ( error fluor hs2 hr1 hr2 hr3 microcat oasis pco2 shutter0 specprr specprr.volts )
	rm -f data/$name $tmp/$name.tmp
	cp $cfg/$mooring/$name.hdr data/$name
	foreach year (2003)
	    foreach file ($name/$year*)
	      $AWK -f $bin/concat.awk -v year=$year $file >> $tmp/$name.tmp
	    end
	    /bin/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



