#!/bin/bash

# ----------------------------------------------------------------------
# RPC Project :
# RPC_download_data_oneyear_CLUPOS : get POS data from CAA
#                           from CAA data base
#                           for one entire year and 4 S/C
#
# usage: RPC_download_data_oneyear_CLUPOS  year 
# ex   : RPC_download_data_oneyear_CLUPOS  2009 
#
# P. Robert, LPP, 2011-05-16
#
# ----------------------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=1

if( (test $# = 1 ) && (test $1 = -h ) ) ; then hh=1 ; else hh=0 ; fi

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : get entire year of POS data from CAA"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   year "
   echo "    ex: $appli 2009"
   echo ""
   if test $hh = 1 ; then exit 0 ; fi
   echo "$appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi

datim1=`date +%F'  '%H':'%M':'%S `
julsec1=`date +%s`

year=$1

echo " /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/"
echo " RPC_download_data_oneyear_CLUPOS : download $year of CLUSTER/POS "
echo "                           for the 12 month of the year"
echo "                           from CAA data base."
echo ""

# loop on the month

for month in 01 02 03 04 05 06 07 08 09 10 11 12
    do
    RPC_download_data_onemonth_CLUPOS $year $month 
    err=$?
    if test $err = 3 
            then
            echo "Manage your files & directories for all the year $year ..."
            echo "$appli36 : *** ERROR ! Command aborted." >&2
            exit 3
    fi  
done

# files clean up and computing time
# ---------------------------------

datim2=`date +%F'  '%H':'%M':'%S `
julsec2=`date +%s`
diff=`expr $julsec2 - $julsec1`
diffm=`echo "scale=2; $diff/60." | bc `

echo ""
echo " Starting time $appli : $datim1"
echo " Ending   time $appli : $datim2"
echo " Duration      $appli : $diff sec.  ($diffm mn.)"

echo " /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/"


