set -xuve

reftime="2000-01-01,00:00:00,days"

rm -f tmp_*.nc

for year in 2014
do
    for f in SiB4v2_BioFluxes_v246_1x1_${year}??.nc
    do
	yyyy=${f:26:4}
	mm=${f:30:2}
	echo $f $yyyy $mm
	cdo -r -O -setreftime,${reftime} -settaxis,${yyyy}-${mm}-01,00:00:00,3hour $f tmp_${yyyy}${mm}.nc
    done
    
    cdo -O -f nc4c -z zip_2 mergetime tmp_??????.nc SiB4v2_BioFluxes_v246_1x1_2014_3hour.nc
    cdo -O settime,00:00:00 -daymean SiB4v2_BioFluxes_v246_1x1_2014_3hour.nc SiB4v2_BioFluxes_v246_1x1_2014_day.nc
done
