#!/bin/ksh
# $Id$
##############################################################
# 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  DET/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   2  ZOO/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   3  PHY/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   4  NO3/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   5  NH4/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}
       awk '/MEAN NO   6  DOM/ { print $3, $4, $7, $8, $9, $10, $11, $12 }' ${zpath}/${zfilein} >> ${zfile[${ind}]}

       let ind=${ind}+1
done
