#!/bin/ksh -x
#
#
ENS_Member=${1}
typeset -Z6 FctIni FctEnd InitBC
FctIni=${2}
FctEnd=${3}


# VARIAVEIS
cd ${Eta_scr}

datasst=`echo ${Run_Date} | cut -c1-8`
hh=`echo ${Run_Date} | cut -c9-10`
FctCont6=${FctIni}
cont=0
StopOK="False"
First=1
idate1=${Run_Date}
typeset -Z6 FctCont6
typeset -Z4 FctCont4

if  [ "${TInitBC}" == "0" ] && [ "${FctCont6}" != "000000" ]  ; then 
   idate1=`${Eta_home1}/util/caldate.3.0 ${Run_Date} - ${HInitBC}hr 'yyyymmddhh'`
   First=0
   let FctCont4=${FctIni}+${HInitBC}
   let FctCont6=${FctIni}+${HInitBC}
else
   FctCont4=${FctIni}
   FctCont6=${FctIni}
fi


while [ "${StopOK}" != "True" ] ; do
     if ((${FctCont6}==000000)); then
       MDriver=`echo ${CInit}|awk '{print toupper($1)}'`
       MDriver_Lowercase=`echo ${CInit}|awk '{print tolower($1)}'`
     else
       MDriver=`echo ${BCond}|awk '{print toupper($1)}'`
       MDriver_Lowercase=`echo ${BCond}|awk '{print tolower($1)}'`
     fi
     dir_Global=/home/etamodel/CFS/${idate1}
     arqin=${dir_Global}/${MDriver}_${idate1}E.${FctCont4}
     
  if [ -s ${arqin} ] ; then
     echo "ARQ1"${Eta_run}/${MDriver_Lowercase}_${idate1}.${FctCont6} >> ${Eta_run}/cond$Run_Date  
     cp ${arqin} ${Eta_run}/${MDriver_Lowercase}_${idate1}.${FctCont6}
       
  fi
  
  if ((${cont}>=100)); then
    echo "cont1"=$cont
    exit 
  fi
  
  if [ -s ${arqin} ] ; then
    cont=0
    
    if [ "${FctCont6}" == "${FctEnd}" ] ; then
      StopOK="True"
      exit
    fi  
    let FctCont4=${FctIni}+${InitBC}
    let FctCont6=${FctIni}+${InitBC}
    let FctIni=${FctIni}+${InitBC}
  else
   sleep 15 
   let cont=$cont+1  
  fi
done
