#!/bin/bash
# Before downloading; the nudging reference files it should be well prepared at ECMWF's c2a
# in the context of cfu's infrastructure (use "prepare_atm_nudging.cmd" over there first).
# nohup ./download_atm_nudging.sh T255L91 b0ir >& b0ir.log &
#
set -xuve
date

grd=$1
ver=$2

src=ec:/c3m/nudging/atmos/$grd/$ver
dst=/cfu/releases/nudging/atmos/$grd/$ver

mkdir -p $dst
list=atm-${grd}-${ver}

if [[ ! -a $list ]]; then
   ecaccess-file-dir $src > $list
fi

for l in $(cat $list); do
 ecaccess-file-get $src/$l $dst/$l
 if [[ $? -ne 0 ]]; then
    exit 1
 fi
 cat $list | sed -e '1d' > ${list}.tmp
 mv ${list}.tmp $list
done
cat $list; rm $list

date
