Caldtg='/data/public/HYCOM/shian/Caldtg.ksh'

tmpdtg=`date -d "-5 days" +%Y%m%d`12
tmpdtg2=`date -d "-2 days" +%Y%m%d`12
yy=`echo ${tmpdtg2} | cut -c 1-4`
dd=`echo ${tmpdtg2} | cut -c 5-6`
opath=/data/public/HYCOM/shian/${yy}/${dd}

while [ ${tmpdtg} -le ${tmpdtg2} ]
do  
file=${opath}/US058GCOM-OPSnce.espc-d-031-hycom_fcst_glby008_${tmpdtg}_t0036
panosize=`ls -l ${file}_t3z.nc |cut -d ' ' -f 5`
if [[ ! -f ${file}_t3z.nc ]] || [[ ${panosize} -le 1500000000 ]];then
   echo "rm and download"
   y4=`echo ${tmpdtg} | cut -c1-4`
   rm -rf ${file}_t3z.nc
   wget -P ${opath}/ ftp://ftp.hycom.org/datasets/ESPC-D-V02/data/forecasts/US058GCOM-OPSnce.espc-d-031-hycom_fcst_glby008_${tmpdtg}_t0036_t3z.nc
else
   echo "t t036 ok"
fi

panosize=`ls -l ${file}_s3z.nc |cut -d ' ' -f 5`
if [[ ! -f ${file}_s3z.nc ]] || [[ ${panosize} -le 1500000000 ]];then
   echo "rm and download"
   y4=`echo ${tmpdtg} | cut -c1-4`
   rm -rf ${file}_s3z.nc
   wget -P ${opath}/ ftp://ftp.hycom.org/datasets/ESPC-D-V02/data/forecasts/US058GCOM-OPSnce.espc-d-031-hycom_fcst_glby008_${tmpdtg}_t0036_s3z.nc
else
   echo "s t036 ok"
fi


panosize=`ls -l ${file}_u3z.nc |cut -d ' ' -f 5`
if [[ ! -f ${file}_u3z.nc ]] || [[ ${panosize} -le 1500000000 ]];then
   echo "rm and download"
   y4=`echo ${tmpdtg} | cut -c1-4`
   rm -rf ${file}_u3z.nc
   wget -P ${opath}/ ftp://ftp.hycom.org/datasets/ESPC-D-V02/data/forecasts/US058GCOM-OPSnce.espc-d-031-hycom_fcst_glby008_${tmpdtg}_t0036_u3z.nc
else
   echo "u t036 ok"
fi

panosize=`ls -l ${file}_v3z.nc |cut -d ' ' -f 5`
if [[ ! -f ${file}_v3z.nc ]] || [[ ${panosize} -le 1500000000 ]];then
   echo "rm and download"
   y4=`echo ${tmpdtg} | cut -c1-4`
   rm -rf ${file}_v3z.nc
   wget -P ${opath}/ ftp://ftp.hycom.org/datasets/ESPC-D-V02/data/forecasts/US058GCOM-OPSnce.espc-d-031-hycom_fcst_glby008_${tmpdtg}_t0036_v3z.nc
else
   echo "v t036 ok"
fi

panosize=`ls -l ${file}_ssh.nc |cut -d ' ' -f 5`
if [[ ! -f ${file}_ssh.nc ]] || [[ ${panosize} -le 38000000 ]];then
   echo "rm and download"
   y4=`echo ${tmpdtg} | cut -c1-4`
   rm -rf ${file}_ssh.nc
   wget -P ${opath}/ ftp://ftp.hycom.org/datasets/ESPC-D-V02/data/forecasts/US058GCOM-OPSnce.espc-d-031-hycom_fcst_glby008_${tmpdtg}_t0036_ssh.nc
else
   echo "h t036 ok"
fi


  tmpdtg=`${Caldtg} ${tmpdtg} 24`
done


