#!/bin/csh -f

echo "Parameter 1: variable"
echo "Parameter 2: weight src -> dst"
echo "Parameter 3: grid dst"
echo "Parameter 4: input file name"
echo "Parameter 5: output file name"


set var = $1
set weightfile = $2
set gridfile = $3
set infile = $4
set oufile = $5

rm temp*.nc
ncrename -v X29_205,LON -v Y25_370,LAT $4 tmp1.nc

ncks -O -v $1 tmp1.nc tmp2.nc
ncrename -d X29_205,lon -d Y25_370,lat tmp2.nc

ncremap -m $2 tmp2.nc $5
rm tmp*.nc

cp $3 tmp3.nc
ncrename -d lon,x -d lat,y $5 tmp4.nc
ncks -A -v $1 tmp4.nc tmp3.nc
mv tmp3.nc $5
rm tmp*.nc
