#!/usr/bin/ksh
##!/usr/bin/ksh -x

########        called by postproc.ksh, use date.info########

FileName='date2.info'

InitialM=`sed -n '1p' $FileName`
inidate=`sed -n '2p' $FileName`
ee=`sed -n '3p' $FileName`
yearstart=`sed -n '4p' $FileName`
yearend=`sed -n '5p' $FileName`
InitialMN=`sed -n '6p' $FileName`
TP=`sed -n '11p' $FileName`
inDATE=`sed -n '7p' $FileName`
inDATE2=`sed -n '12p' $FileName`

#export ee1=$((ee - 1))
ee1=10
##-----------------------------
if [ $InitialMN -lt 10 ]; then
normalini1=4
normalini2=11
fi
if [ $InitialMN -eq 10 ]; then
normalini1=5
normalini2=11
fi
if [ $InitialMN -eq 11 ]; then
normalini1=5
normalini2=12
fi
if [ $InitialMN -eq 12 ]; then
normalini1=4
normalini2=11
fi

if [ $yearstart -eq 1980 ];then
year1=$((yearstart + 1))
year2=$((yearend + 1))
fi
if [ $yearstart -eq 1981 ];then
year1=$yearstart
year2=$yearend
fi
if [ $yearstart -eq 2011 ];then
year1=$yearstart
year2=$yearend
fi
if [ $yearstart -eq 2012 ];then
year1=$yearstart
year2=$yearend
fi

set -A VARS precip sst slp at olr t850 u850 v850 z500 u200 v200
set -A DATE $(echo ${inDATE[*]})
set -A DATE2 $(echo ${inDATE2[*]})
ind_var=0
while [ ${ind_var} -le 10 ] ; do
year=${year1}
while [ $year -le ${year2} ] ; do
if [ $InitialMN -eq 1 ];then
year3=$((year +1))
fi

mv jun30${year}_144x73_${VARS[${ind_var}]}_ens11.nc jun30${year}_144x73_${VARS[${ind_var}]}_ens10.nc

year=$((year+1))
done
ind_var=$((ind_var+1))
done

chmod 744 changename.ksh
chmod 744 date2.info

