#!/bin/ksh
# $Id: BIO_sx8brodie.ksh 1301 2009-02-09 17:15:38Z ctlod $
##############################################################
# Original : C. Talandier for NEMO team
# Contact  : nemo_st@locean-ipsl.upmc.fr
#
# It is called by the assessment.ksh script for a 
# given configuration 
#
# INPUT ARGS: 2
#     - zfile1 : first tracer statistic file to output
#     - zfile2 : second tracer statistic file to output
#
# WORK: It aims to :
#
#      - Extract tracers statistics from ocean.output 
#        for mon, mpi & omp runs
#
##############################################################
#set -xv
##############################################################

# Initialization
zfile1=
zfile2=

# Get arguments
while getopts a:b:c: opt
do
  case "$opt" in
    a) zfile1="$OPTARG";;
    b) zfile2="$OPTARG";;
    c) zfile3="$OPTARG";;
  esac
done

zfile[0]=${zfile1}
zfile[1]=${zfile2}
zfilein=${zfile3}

ind=0

while [ ${ind} -le 1 ] ; do

       zpath=$( ( dirname ${zfile[${ind}]} ) )

       awk '/----TRACER STAT----/ { print $0 }' ${zpath}/${zfilein} > ${zfile[${ind}]}
       awk '/MEAN NO   1  DIC/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   2  Alkalini/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   3  O2/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   4  CaCO3/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   5  PO4/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   6  POC/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   7  Si/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   8  PHY/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   9  ZOO/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   10  DOC/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   11  PHY2/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   12  ZOO2/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   13  BSi/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   14  Fer/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   15  BFe/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   16  GOC/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   17  SFe/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   18  DFe/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   19  DSi/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   20  NFe/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   21  NCHL/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   22  DCHL/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   23  NO3/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   24  NH4/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}

       let ind=${ind}+1
done
