#!/bin/bash #if run stand alone # module load nco/4.6.9 #var=("t2m") var=("t2m" "swsn" "swsd" "lwsn" "lwsd" "smb" "latf" "senf" "gbot" "alb") casename=racmo23_GRN_monthly file_start_year=1958 start_year=1980 end_year=1999 hist_path=$obspath/$casename echo "$hist_path" lndpath=$hist_path/climos outseries=$hist_path/tseries #mask_file=RACMO23_masks_ZGRN11_latlon.nc mask_file=RACMO23_masks_ZGRN11.nc gris_pcnt_file=greenland_percent_coverage_latlon.nc for ivar in "${var[@]}" do echo "make RACMO23 climos for" $ivar filename=${ivar}.1958-2013.BN_1958_2013.MM.nc outfile=$casename.${ivar}.$start_year-$end_year tseries_file=$casename.${ivar}.ann_tseries mkdir -p "$outseries" mkdir -p "$lndpath" let "go=($start_year-$file_start_year)*12" let "stop=($end_year-$file_start_year)*12" month=("01" "02" "03" "04" "05" "06" "07" "8" "9" "10" "11" "12") for m in "${month[@]}" do # set the time to start averging to $go mon=$go # set the time to start averging for each month let mon="($go+$m)" ncra -O -h -F -d time,$mon,$stop,12 $hist_path/$filename $lndpath/$outfile.$m.nc # -F = fortran indexing (starts with 1) # -O # -h keep history # -d dimension done #stupid fix because bash bug with 07 08 and 09 sometimes mv -f $lndpath/$outfile.8.nc $lndpath/$outfile.08.nc mv -f $lndpath/$outfile.9.nc $lndpath/$outfile.09.nc if [ "$ivar" == "smb" ]; then echo "create DJF sum to get mmWE/season or year $ivar" ncra -O -y ttl -h -F $lndpath/$outfile.12.nc $lndpath/$outfile.01.nc $lndpath/$outfile.02.nc $lndpath/$outfile.DJF.nc echo "create JJA sum $ivar" ncra -O -y ttl -h -F $lndpath/$outfile.06.nc $lndpath/$outfile.07.nc $lndpath/$outfile.08.nc $lndpath/$outfile.JJA.nc echo "create ANN sum $ivar" ncra -O -y ttl -h -F $lndpath/$outfile.01.nc $lndpath/$outfile.02.nc $lndpath/$outfile.03.nc \ $lndpath/$outfile.04.nc $lndpath/$outfile.05.nc $lndpath/$outfile.06.nc \ $lndpath/$outfile.07.nc $lndpath/$outfile.08.nc $lndpath/$outfile.09.nc \ $lndpath/$outfile.10.nc $lndpath/$outfile.11.nc $lndpath/$outfile.12.nc \ $lndpath/$outfile.ANN.nc else # all others are monthly averaged echo "create DJF avg $ivar" ncra -O -h -F $lndpath/$outfile.12.nc $lndpath/$outfile.01.nc $lndpath/$outfile.02.nc $lndpath/$outfile.DJF.nc echo "create JJA avg $ivar" ncra -O -h -F $lndpath/$outfile.06.nc $lndpath/$outfile.07.nc $lndpath/$outfile.08.nc $lndpath/$outfile.JJA.nc echo "create ANN avg/month" ncra -O -h -F $lndpath/$outfile.01.nc $lndpath/$outfile.02.nc $lndpath/$outfile.03.nc \ $lndpath/$outfile.04.nc $lndpath/$outfile.05.nc $lndpath/$outfile.06.nc \ $lndpath/$outfile.07.nc $lndpath/$outfile.08.nc $lndpath/$outfile.09.nc \ $lndpath/$outfile.10.nc $lndpath/$outfile.11.nc $lndpath/$outfile.12.nc \ $lndpath/$outfile.ANN.nc fi wait echo "make annual time series for RACMO23 $ivar" #uses nco's --mro, multi-record output feature see nco documentation section 3.18, -h retains history of commands if [ "$ivar" == "smb" ]; then # make an annual sum not average for smb, since we want an integrated annual not avg flux ncra --mro -O -y ttl -h -d time,,,12,12 $hist_path/$filename $outseries/${tseries_file}.nc else # average other variables ncra --mro -O -h -d time,,,12,12 $hist_path/$filename $outseries/${tseries_file}.nc fi echo "add mask and area variables to time series of $ivar" ncks -A -v gridarea,GrIS_mask $hist_path/$mask_file -o $outseries/${tseries_file}.nc #if [ "$ivar" == "smb" ]; then #echo "average over ice sheet for $ivar without the percent of glacier" #ncwa -O -a lat,lon -w gridarea -B "GrIS_mask == 1" $outseries/${tseries_file}.nc $outseries/${tseries_file}_aavg.nc # #else echo "average over ice sheet for $ivar" without the percent of glacier ncwa -O -a lat,lon -w gridarea -B "GrIS_mask == 1" $outseries/${tseries_file}.nc $outseries/${tseries_file}_aavg.nc #fi if test -a $outseries/${tseries_file}_aavg.nc; then echo "Global avg annual time series of ${casename} made" else echo "Global avg annual time series of ${casename} NOT made" exit fi done