#!/bin/bash

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

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

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 FGM data from CAA"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   year Mode "
   echo "    ex: $appli 2009 SPIN"
   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
Mode=$2

# Mode test
# ---------

if ((test $Mode != SPIN ) && (test $Mode != 5VPS) && (test $Mode != FULL))
   then
     echo "Mode must be only SPIN, 5VPS or FULL"
     echo "$appli36 : *** ERROR ! Command aborted." >&2
     exit 2
fi


echo " /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/"
echo " RPC_download_data_oneyear_CLUFGM : download $year of CLUSTER/FGM $Mode"
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_CLUFGM $year $month $Mode
    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 " /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/"


