#!/bin/bash
readonly INPUT_DATE="$1"
readonly INPUT_HOUR="$2"
readonly INPUT_END_COUNT="$3"


export PATH=/data/anaconda3/bin:$PATH

cfsfpath="/data/public/jidi/"
cd $cfsfpath

downdays=5
ddays=`echo $downdays | awk '{print $1-1}'`
cfsd2=`date -d"$ddays days" +%Y%m%d`

d1=`date -d"-1 days" +%Y%m%d`
day=5
d11=`date -d"${d1:0:8} 0 hours" +%Y%m%d%H`

s3path="s3://noaa-cfs-pds/cfs.${d1}/00/6hrly_grib_01/"

mkdir -p ${d11}/origin
cd ${d11}/origin

incfiles=" "

for (( i = 0; i <= $day; i++));
do
#date
dd=`date -d"${d1:0:8} $i days  0 hours" +%Y%m%d`
ymdh=${d11:0:10}

afile1=" --include pgbf${dd}00.01.${ymdh}.grb2 --include pgbf${dd}06.01.${ymdh}.grb2 --include pgbf${dd}12.01.${ymdh}.grb2 --include pgbf${dd}18.01.${ymdh}.grb2"
afile2=" --include flxf${dd}00.01.${ymdh}.grb2 --include flxf${dd}06.01.${ymdh}.grb2 --include flxf${dd}12.01.${ymdh}.grb2 --include flxf${dd}18.01.${ymdh}.grb2"
afile3=" --include ocnf${dd}12.01.${ymdh}.grb2"
incfiles=`echo $incfiles $afile1 $afile2 $afile3`

done
date

aws s3 cp --no-sign-request $s3path . --recursive --exclude "*" $incfiles


