#Simple script accumulating hours
# Used in Masterthesis by Aina Johannessen 2018: NOT VALIDATED 
# Validtime in these genereated netcdf files are not correct, see generate6hTimecorrection_from_WGS84.bash for timecorrection. 
#
#-----------

#ls ../PREC1h_gridded_senorge2/201609/P
#seNorge_v2_0_PREC1h_grid_2016092011_2016092011.nc
#the timestamp marks the end of the aggregation period, so it is from 1000 UTC to 1100UTC.

path="/Users/ainajohannessen/Documents/Aina/skole/master/precipitation/input_data/senorge/PREC1h_gridded_senorge2/201712/"
traj_times_Walpurga=(2016092706 2016092712 2016092718 2016092800 2016092806 2016092812 2016092818 2016092900 2016092906 2016092912 2016092918 2016093000 2016093006)
traj_times_Aina=(2017120506 2017120512 2017120518 2017120600 2017120606 2017120612 2017120618 2017120700 2017120706 2017120712 2017120718 2017120800 2017120806)
#traj_times_Birk=(2017122206 2017122212 2017122218 2017122300 2017122306 2017122312 2017122318 2017122400 2017122406)

for wt in ${traj_times_Aina[@]}; do
	obs_date=$@
	y_wt=${wt:0:4}
	m_wt=${wt:4:2}
	d_wt=${wt:6:2}
	t_wt=${wt:8:2}
	
	if [ $t_wt -eq 00 ]
	then
		d_start=$((d_wt-1))
		t_start=$((24-6))
	else 
		d_start=$((d_wt))
		t_start=$((t_wt-6))
	fi
	
	for dt in $(seq 1 6); do
		t_next=$((t_start+dt))
		t_next=$(printf %02d $t_next)
		
		if [ $t_next -eq 24 ]
		then
			t_next=00
			d_start=$((d_start+1))
		fi
		d_start=$(printf %02d $d_start)
		obs="$y_wt$m_wt$d_start$t_next"
		obs=$path"seNorge_v2_0_PREC1h_grid_$obs""_$obs.nc"
  	 	echo ${obs}
		
		obs_date+=($obs)
	 done
	 acc6h="cdo enssum ${obs_date[@]} ./6hacc_"$wt".nc"
	 echo $acc6h
	 
	 $acc6h
	 #echo "./6hacc_$wt.nc"
	 #for senorge_date in ${obs_date[@]};do
		 #cdo 
	 
	 
done

#times=(2016092700 2016092701 2016092702 2016092703 2016092704 2016092705 2016092706)
#times=(2017122206 2017122207 2017122702 2017122703 2017092704 2017122705 2017122706)


#cdo sum 
