#!/bin/bash



# ncap2 --overwrite --script-file build.nco ORCA2_coordinates.nc ORCA2_coordinates_mask.nc

cp ORCA2_coordinates.nc ORCA2.3_coordinates_mask.nc 

ncks --overwrite -v maskper /ccc/work/cont003/dsm/p86mart/GRAF/DATA/orca2.3.nc ORCA2_maskutil.nc
ncrename -v maskper,maskutil_T ORCA2_maskutil.nc
ncrename -d x,x_grid_T ORCA2_maskutil.nc
ncrename -d y,y_grid_T ORCA2_maskutil.nc

ncks --append ORCA2_maskutil.nc ORCA2.3_coordinates_mask.nc



ncatted -a cell_measures,maskutil_T,c,c,"area: area_grid_T"            ORCA2.3_coordinates_mask.nc
ncatted -a coordinates,maskutil_T,c,c,"nav_lat_grid_T nav_lon_grid_T"  ORCA2.3_coordinates_mask.nc


cat <<EOF > build.nco 
mask_T = mask_T == 1 || maskutil_T == 1  ;
EOF

ncap2 --script-file build.nco --overwrite ORCA2.3_coordinates_mask.nc ORCA2.3_coordinates_mask_tmp.nc
mv ORCA2.3_coordinates_mask_tmp.nc ORCA2.3_coordinates_mask.nc
