#!/bin/bash

cp  essai_grid.nc   essai1.nc

cat <<EOF > add_bound.nco
defdim ("nvertex_lmd", 4) ;
delta_x = alon(0,1) - alon(0,0) ;
delta_y = alat(1,0) - alat(0,0) ;
//
bounds_alon[nvertex_lmd,lat,lon] = 0.0 ;
bounds_alat[nvertex_lmd,lat,lon] = 0.0 ;
//
bounds_alon (0,:,:) = alon + delta_x*0.5 ;
bounds_alat (0,:,:) = alat + delta_y*0.5 ;
bounds_alon (1,:,:) = alon + delta_x*0.5 ;
bounds_alat (1,:,:) = alat - delta_y*0.5 ;
bounds_alon (2,:,:) = alon - delta_x*0.5 ;
bounds_alat (2,:,:) = alat - delta_y*0.5 ;
bounds_alon (3,:,:) = alon - delta_x*0.5 ;
bounds_alat (3,:,:) = alat + delta_y*0.5 ;
//
where (bounds_alat >  90.0 ) bounds_alat =  90.0 ;;
where (bounds_alat < -90.0 ) bounds_alat = -90.0 ;;
//
EOF
 
ncap2 -S add_bound.nco -O -h essai1.nc essai2.nc
