#!/bin/bash
clear
echo “CDO routine to find seasonal anomalies”
echo “Today is “; date
echo “Please enter inputfile: ”
read infile
echo “Your file is: $infile”
echo “Please enter variable name: ”
read varn
echo “Your variable is: $varn”

echo “Please enter data set name:”
echo ” Eg. NCEP, ECMWF, etc”
read dset
echo “Your data set is: $dset”

echo “SELECT SEASON:”

echo “for DJF use 3,11,9”
echo “for MAM use 3,2,9”
echo “for JJA use 3,5,9”
echo “for SON use 3,8,9”
read seas

read -p “Enter to continue:”

echo “Please enter START date: ”
echo “Format YYYY-MM-DDThh:mm”
echo “eg 1979-01-01T00:00”
read tym1

echo “Please enter END date: ”
echo “Format YYYY-MM-DDThh:mm”
echo “Please note that, if your data set”
echo “ends in december, DJF mean of the”
echo “of the last year will have only”
echo “values of December, to discard”
echo “this enter any date < December”
echo “but >= January for the last year:”
echo “eg 1979-01-01T00:00”
read tym2

echo “Time range : $tym1 – $tym2”

read -p “Enter to continue:”

echo “Please enter outputfile for temporal anomalies: ”
read oufilet
echo “Your file is: $oufilet”
echo “Please enter outputfile for zonal anomalies: ”
read oufilez
echo “Your file is: $oufilez”

echo “Select region:”
echo “Enter start lat:”
read lat1
echo “Enter End lat:”
read lat2

echo “Enter start lon:”
read lon1
echo “Enter End lon:”
read lon2

echo “Latitude range : $lat1 – $lat2”
echo “Longitude range : $lon1 – $lon2”

read -p “Enter to continue:”

cdo seldate,$tym1,$tym2 $infile ttt1.nc
cdo sellonlatbox,$lon1,$lon2,$lat1,$lat2 ttt1.nc ttt2.nc
rm -f ttt1.nc

cdo timselmean,$seas ttt2.nc ttt3.nc

rm -f ttt2.nc
cdo seldate,$tym1,$tym2 ttt3.nc ttt4.nc
rm -f ttt3.nc
cdo yseasmean ttt4.nc ttt5.nc
cdo zonmean ttt4.nc tttzm.nc
cdo enlarge,ttt4.nc tttzm.nc tttzme.nc
cdo sub ttt4.nc ttt5.nc $oufilet
rm -f ttt5.nc
cdo sub ttt4.nc tttzme.nc $oufilez
rm -f ttt*.nc
#—————-Edit this section for changing attributes and variable names———————–
ncatted -O -h -a title,global,o,c,”$varn zonal anomalies derived from $dset” $oufilez
ncatted -O -h -a title,global,o,c,”$varn temporal anomalies derived from $dset” $oufilet
ncatted -O -a long_name,$varn,o,c,”$varn anomalies ” $oufilet
ncatted -O -a long_name,$varn,o,c,”$varn zonal anomalies ” $oufilez
ncrename -h -O -v $varn,$varn”ano” $oufilet
ncrename -h -O -v $varn,$varn”zano” $oufilez
#——————————–END—————————————————————–
