#!/bin/sh

set -ax

### QUICK AND DIRTY SCRIPT FOR MAKING MEANS ###
### EDIT AS YOU LIKE  
### MAKING MONTHLY MEANS ####

region=sa
ensemble=l01

#month=03
#shour=6
#ehour=744

#month=04
#shour=750
#ehour=1464

month=05
shour=1470
ehour=2208

set -ax

### CREATE A LIST OF FILES FOR AVERAGE

day=1
hour=$shour
while [ $hour -le $ehour ]; do

     if [ $hour -lt 10 ]; then hour=0$hour; fi
     if [ $day -lt 10 ]; then day=0$day; fi

     rm prate.list

     countn=1

     while [ $countn -le 4 ]; do

     ls /home/nfs1/smr1934/post/prate/prate.ft$hour >> prate.list

     hour=`expr $hour + 6`
     countn=`expr $countn + 1`

	done

#/afs/ictp/home/a/anunes/RSM/ecpc_exp/libs/etc/grmap /scratch/RSM/rruns/SouthAmerical01/2008/r_pgb.ft06

### RUN GRMEAN and CREATE MEAN

/afs/ictp/home/a/anunes/RSM/ecpc_exp/libs/etc/grmean -s prate.list -o ${region}_${ensemble}_prate_2008${month}${day}.grib

### SET THE TIME TO 2008 03 01 00
/afs/ictp/home/a/anunes/RSM/ecpc_exp/libs/etc/force_grib_date_mon ${region}_${ensemble}_prate_2008${month}${day}.grib 2008${month}${day}00

#### CREAE CTL FILE FOR GRADS
#/afs/ictp/home/a/anunes/RSM/ecpc_exp/libs/etc/grmap -g0 sa_l01_prate_20080301.grib

     day=`expr $day + 1`
done
