#!/bin/bash

years=$(seq 1993 2020)

for yy in $years; do

# jatame alles okt-mai ja kustutame 29 veb. Loikame Gor piirkonna
cdo -sellonlatbox,22,25,56.5,59 -del29feb -selmonth,10,11,12,1,2,3,4,5 data/ice_daymean_$yy.nc period/daymean_$yy.nc

# votame valja konsetratsioonid ja tapsustame gor piirkonna
cdo -setctomiss,100 -setclonlatbox,100,22,22.2,58,58.3 -setclonlatbox,100,22,24,58.575,59 -setclonlatbox,100,22,23,58.4,59 -selvar,siconc period/daymean_$yy.nc period/icefrac_$yy.nc

cdo -gec,0.15 period/icefrac_$yy.nc period/ice_mask_$yy.nc

cdo mul period/icefrac_$yy.nc period/ice_mask_$yy.nc period/ice_$yy.nc

# arvutame pindalad km^2
cdo -divc,1e6 -mul period/ice_$yy.nc gor/grid.nc period/area_$yy.nc
#pindala m^2
#cdo -mul period/ice_$yy.nc gor/grid.nc period/area_m2_$yy.nc
# pindala kokku
cdo fldsum period/area_$yy.nc period/fsum_area_$yy.nc

#--------RUUMALA---------------
# votame valja paksuse ja teeme m->k
cdo -divc,1e3 -setctomiss,-100 -setclonlatbox,-100,22,22.2,58,58.3 -setclonlatbox,-100,22,24,58.575,59 -setclonlatbox,-100,22,23,58.4,59 -selvar,sithick period/daymean_$yy.nc period/icethick_$yy.nc
# korrutame paksusse ja pindala
cdo mul period/icethick_$yy.nc period/area_$yy.nc period/icevol_$yy.nc
#ruumala fsum
cdo fldsum period/icevol_$yy.nc period/fsum_icevol_$yy.nc
done
#-----------------------------------------------------------------
# pindala ja ruumala perioodi andmed
cdo mergetime period/area* period/pindala.nc
cdo mergetime period/icevol_* period/ruumala.nc
#-------------------------------------------------
# jaa kaart
cdo mergetime period/ice_mask* period/mask_merged.nc
cdo timsum period/mask_merged.nc period/days.nc
#2702 on kogu jaa perioodi pikkus
cdo divc,6804 period/days.nc period/prob.nc


rm period/ice*
rm period/daymean*
rm period/area*
