#!/bin/ksh -x
#
#

# VARIAVEIS

cd ${Eta_scr}
hh=`echo ${Run_Date} | cut -c9-10`
FctCont=000000
FctCont2=0000
cont=0
GlobalOK="False"

typeset -Z6 Fct FctCont
typeset -Z4 FctCont2

while [ "${GlobalOK}" != "True" ] ; do

if [ "${FInitBC}" == "cpteta15" ] ; then
dir_cpteta15=${data_grib}/${Run_Date}
arqin=`${Eta_home1}/util/caldate.3.0 ${Run_Date} + ${FctCont}h ${dir_cpteta15}/'eta_15km_YYYYMMDDHH+yyyymmddhh.grb'`

elif [ "${FInitBC}" == "cpteta40" ] ; then
dir_cpteta40=${data_grib}/${Run_Date} 
#arqin=`${Eta_home1}/util/caldate.3.0 ${Run_Date} + ${FctCont}h ${dir_cpteta40}/'eta_40km_CNTRL_YYYYMMDDHH+yyyymmddhh.grb'`
arqin=`${Eta_home1}/util/caldate.3.0 ${Run_Date} + ${FctCont}h ${dir_cpteta40}/'cptetaYYYYMMDDHH.pgrbf'${FctCont2}'.grb'`
fi
   
  if [ -s ${arqin} ] ; then
     echo "ARQ1"$arqin >> ${Eta_run}/cond$Run_Date  
     cp ${arqin} ${Eta_run}/${FInitBC}_${Run_Date}.${FctCont}
  fi
  
  if ((${cont}>=100)); then
    echo "cont1"=$cont
    exit 
  fi
  
  if [ -s ${arqin} ] ; then
    cont=0
    
    if [ "${FctCont}" == "${Fct}" ] ; then
      GlobalOK="True"
      exit
    fi  
    let FctCont=${FctCont}+${InitBC}
    let FctCont2=${FctCont2}+${InitBC}
  else
   sleep 15
   
   let cont=$cont+1  
  fi
done

