#!/bin/ksh

ano=$1
data=`echo ${ano} | cut -c1-6`
#cam=/stornext/online7/pnc/MCGA/cc_forEta/${data}/kuo/persistida
#####cam=/stornext/online1/eta/etaclim/felipe/scripts/Chou/AVN_CFS_teste
cam=/stornext/oper/clima/MCGA/cc_forEta/${data}/kuo/persistida
#cam=/scratchout/oper/clima/MCGA/pos/dataout/T062L28/
#cam=/scratchout/grupos/eta/home/etaclim/sazonal/worketa/data/T062L28
cam2=/scratchout/grupos/eta/home/etaclim/sazonal/worketa/eta/227X351X38_oper_kieee/${ano}Etasa40km
######cp ${cam}/* ${cam2}

typeset -Z4 tempo
#echo $ano
#exit
Run_Date=${1}
IntFct=6
Fct=0000
ldm=`echo ${Run_Date} | cut -c7-8`
mes_sst=`echo ${Run_Date} | cut -c5-6`

ldm1=`../../../util/caldate.3.0 ${Run_Date} + 0d   "ld"`
ldm2=`../../../util/caldate.3.0 ${Run_Date} + 30d  "ld"`
ldm3=`../../../util/caldate.3.0 ${Run_Date} + 60d  "ld"`
ldm4=`../../../util/caldate.3.0 ${Run_Date} + 90d  "ld"`
ldm5=`../../../util/caldate.3.0 ${Run_Date} + 120d "ld"`

let diai=${ldm1}-${ldm}
let Ndias=${diai}+${ldm2}+${ldm3}+${ldm4}+${ldm5}
let Nfct=${Ndias}*24
NFct=${Nfct}
#NFct=6
tempo=0
while (($tempo <= ${NFct} )) ; do

idate1=`../../../util/caldate.3.0 ${ano} + ${tempo}hr 'yyyymmddhh'`

if [ -s ${cam}/GPOSNMC${Run_Date}${idate1}C.icn.T062L28 ] ; then

echo "copiando o arquivo de analise da hora ${tempo} ${idate1}"
#GLOBAL cp ${cam}/GPOSETA${ano}${idate1}E.icn.TQ0213L042 ${cam2}/wbin.${tempo}
#RECORTEcp ${cam}/TQ0213_to_Eta${ano}${idate1}.bin ${cam2}/wbin.${tempo}
#cp ${cam}/GPOSNMC${Run_Date}${idate1}C.icn.T062L28 ${cam2}/wbin.${tempo}
ln -sf ${cam}/GPOSNMC${Run_Date}${idate1}C.icn.T062L28 ${cam2}/T062L028_${Run_Date}E.${tempo}
#cp ${cam}/GPOSNMC${Run_Date}${idate1}C.icn.T062L28 ${cam2}/T062L028_${Run_Date}E.${tempo}
   else

echo "copiando o arquivo de previsao da hora ${tempo} ${idate1}"
#cp ${cam}/GPOSNMC${Run_Date}${idate1}C.fct.T062L28 ${cam2}/wbin.${tempo}
ln -sf ${cam}/GPOSNMC${Run_Date}${idate1}C.fct.T062L28 ${cam2}/T062L028_${Run_Date}E.${tempo}
#cp ${cam}/GPOSNMC${Run_Date}${idate1}C.fct.T062L28 ${cam2}/T062L028_${Run_Date}E.${tempo}
fi


let tempo=$tempo+6
done

exit
