#!/bin/bash

YYYY=2015

mod=IPSL
YYYY_MAX=2100



for sc in $(seq 4 4)
do

    start_year=2015
    YYYY_MAX=2100
    if [[ $sc -eq 1 ]]; then
      SCE='126'
    fi
    if [[ $sc -eq 2 ]]; then
      SCE='245'

    fi
    if [[ $sc -eq 3 ]]; then
      SCE='370'
    fi
    if [[ $sc -eq 4 ]]; then
      start_year=1981
      SCE='585'
    fi
    dir=/srv5_tmp1/jbrajkovic/Unbiasing/${mod}_${SCE}/
    cd ${dir}
    echo ${dir}




    for c in `seq 1 130`
    do
        echo ${YYYY}
	ncks -C -O -x -v __xarray_dataarray_variable__ Unbiased_${mod}_ssp${SCE}_${YYYY}.nc out.nc
	rm -rf Unbiased_${mod}_ssp${SCE}_${YYYY}.nc
	cdo -f nc4 -z zip_5 copy out.nc Unbiased_${mod}_ssp${SCE}_${YYYY}.nc
	rm -rf out.nc

        YYYY=$(( ${YYYY} + 1 ))

	if [ $YYYY -gt $YYYY_MAX ] ; then
		break
	fi
	
	
	

    done

done

