#!/bin/sh
#
# stocmip2.sh
# --------------------------------------------------------
# Bourne Shell Script to tar OCMIP-2 model output files
# --------------------------------------------------------
# J. Orr, IPSL/LSCE, 23 July 1998
# --------------------------------------------------------

#_ ---------------------------------------------------------------------
#_ RCS lines preceded by "#_ "
#_ ---------------------------------------------------------------------
#_
#_ $Source: /www/html/ipsl/OCMIP/phase2/simulations/CFC/distrib/RCS/stocmip2.sh,v $
#_ $Revision: 1.2 $
#_ $Date: 1998/09/10 09:06:38 $   ;  $State: Exp $
#_ $Author: jomce $ ;  $Locker:  $
#_
#_ ---------------------------------------------------------------------
#_ $Log: stocmip2.sh,v $
#_ Revision 1.2  1998/09/10 09:06:38  jomce
#_ Fixed name of output files for surface T & S for earlyfiles and latefiles
#_
#_ Revision 1.1  1998/09/10 08:21:18  jomce
#_ Initial revision
#_
#_ ---------------------------------------------------------------------
#_


models="AWI CSIRO IGCR IPSL LLNL MIT MPIM NCAR NERSC PIUB PRINCE SOC UL"

echo "Please enter your OCMIP-2 model CODE:"
echo "   -> AWI, CSIRO, IGCR, IPSL, LLNL, MIT, MPIM, " 
echo "     NCAR, NERSC, PIUB, PRINCE, SOC, or UL"

read mymod


# test to see if modeled entered is one of the official model codes for OCMIP-2
member=no
for model in $models
do
#  echo $mymod $model
  if [ "$mymod" = "$model" ] ; then
    member=yes
  fi
done

#echo member=..."$member"...

# Proceed only if model code entered is one of the standard codes listed above
if [ "$member" = "yes" ] ; then

# Categorize available standard output files
  earlyfiles=`ls "$mymod"_CFC_19[4-8]0.nc "$mymod"_SurfTS_19[4-8]0.nc`
  latefiles=`ls "$mymod"_CFC_198[2-9].nc "$mymod"_CFC_199[0-7].nc "$mymod"_SurfTS_198[2-9].nc "$mymod"_SurfTS_199[0-7].nc`
  transportfiles=`ls "$mymod"_CFC_transport_1990.nc`
  equilfiles=`ls "$mymod"_CFC_equil.nc`
  mabfiles=`ls "$mymod"_MaskAreaBathy.nc`

# If available, tar them together.
  if [  "$earlyfiles" ] ; then
    echo tar EARLY output:
    tar cvf "$mymod"_CFC_early.tar $earlyfiles
  fi
  if [ "$latefiles" ] ; then
    echo tar LATE output:
    tar cvf "$mymod"_CFC_late.tar $latefiles
  fi
  if [ "$transportfiles" ] ; then
    echo tar TRANSPORT output:
    tar cvf "$mymod"_CFC_transport.tar $transportfiles
  fi
  if [ "$equilfiles" ] ; then
    echo tar EQUILIBRIUM output:
    tar cvf "$mymod"_CFC_equil.tar $equilfiles
  fi
  if [ "$mabfiles" ] ; then
    echo tar MaskAreaBathy output:
    tar cvf "$mymod"_CFC_mab.tar $mabfiles
  fi
  exit 0

else

 echo "You entered '$mymod' as your model code, but that is not allowed"
 echo " -> Try again with your proper CODE (see list above)"
 exit 1

fi







