How to prepare GrADS's .ctl file to convert grd file into .nc file in batch mode?
After some trial n error I figured it out using the following shell script

#!/bin/bash

day_number () {
year=$1
leap="false"

if [ $((year % 4)) -ne 0 ] ; then
   :
elif [ $((year % 400)) -eq 0 ] ; then
     leap="true"
elif [ $((year % 100)) -eq 0 ] ; then
   : 
else

   leap="true"
fi
if [ "$leap" == "true" ];
then
   echo 366
else
   echo 365
 fi
}

for j in {1901..2015};
do
days=$(day_number j)
echo "DSET /home/amit/climate_data/rf/year${j}_rfp25.grd
TITLE Gridded rainfall
UNDEF -999.0
XDEF  135  LINEAR  66.5 0.25
YDEF  129  LINEAR  6.5 0.25
ZDEF   1 linear 1 1 
* CHANGE TDEF TO 366 FOR LEAP YEARS
TDEF ${days}  LINEAR 1jan${j} 1DY 
VARS  1
rf 0 99 GRIDDED RAINFALL
ENDVARS"&gt;year${j}_rfp25.ctl
done