Index: TOOLS/MOSAIX/CreateWeightsMask.bash
===================================================================
--- TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3686)
+++ TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3718)
@@ -48,8 +48,8 @@
 #OCE=ORCA025
 
-ATM=ICO30
+#ATM=ICO30
 #ATM=ICO40
 #ATM=ICO450
-#ATM=LMD9695
+ATM=LMD9695
 #ATM=LMD144X142
 
@@ -180,4 +180,14 @@
 ncks --alphabetize --history --append --variable OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc   ${ATM}_grid_maskFrom_${OCE}.nc
 
+##
+## Create mask of coastal ATM point
+## ===========================================================================
+cat <<EOF > coastal.nco
+AtmCoastal = OceFrac * 0.0 ;
+where (OceFrac > 0.0 && OceFrac < 1.0 )  AtmCoastal = 1.0 ;
+EOF
+ncap2 --history --overwrite --script-file coastal.nco ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_coastal_maskFrom_${OCE}.nc
+ncks --history --append --variable AtmCoastal ${ATM}_coastal_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+rm ${ATM}_coastal_maskFrom_${OCE}.nc
 
 ##
@@ -255,11 +265,31 @@
 
 ##
+## ATM towards NEMO points - runoff
+## ===========================================================================
+cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml           iodef.xml
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${atm_domain_type}
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${oce_domain_type}
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]'       -t "${ATM} coastal mask interpolated to ${OCE}"
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${atm_domain_type}
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'   -t ${oce_domain_type}
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${atm_domain_type}
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${oce_domain_type}
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t 1
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]'                         -k name  -v ${ATM}_grid_maskFrom_${OCE}
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]'   -k name  -v AtmCoastal
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_c${atm}_to_t${oce}_1storder
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_c${atm}_to_t${oce}_1storder.nc
+
+cp iodef.xml iodef_c${atm}_to_t${oce}_1storder.xml
+
+time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes
+
+##
 ## Change all NetCDF files to NetCDF 3 format (needed for OASIS)
 ## ===========================================================================
 for InFile in *.nc ; do
-    if [[ $(ncdump -k ${InFile}) = *netCDF-4* ]] ; then
-	mv ${InFile} tmp_${InFile}
-	ncks --alphabetize --fl_fmt=${FL_FMT} --history  tmp_${InFile}  ${InFile}
-    fi
+    mv ${InFile} tmp_${InFile}
+    ncks --alphabetize --fl_fmt=${FL_FMT} --history  tmp_${InFile}  ${InFile}
 done
 
@@ -385,12 +415,13 @@
 ## ===========================================================================
 for OGRID in ${ListOCEGRID} ; do
-    for order in ${Listorder} ; do
-	ogrid=${OGRID~}
-	agrid=t
+    for AGRID in T C ; do
+	for order in ${Listorder} ; do
+	    ogrid=${OGRID~}
+	    agrid=${AGRID~}
 	
-	file_o_to_a=rmp_${ogrid}${oce}_to_${agrid}${atm}_${order}order.nc
-	file_a_to_o=rmp_${agrid}${atm}_to_${ogrid}${oce}_${order}order.nc
-	
-	cat <<EOF >add_varoce.nco
+	    file_o_to_a=rmp_${ogrid}${oce}_to_${agrid}${atm}_${order}order.nc
+	    file_a_to_o=rmp_${agrid}${atm}_to_${ogrid}${oce}_${order}order.nc
+	    
+	    cat <<EOF >add_varoce.nco
 defdim ("src_grid_size"   , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ;
 defdim ("src_grid_corners", 4) ;
@@ -417,10 +448,10 @@
 EOF
 
-	ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_o_to_a}
-	sed --in-place "s/src_/dst_/g" add_varoce.nco
-	ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_a_to_o}
-
-	if [[ ${atm} = ico ]] ; then
-	    cat <<EOF >add_varatm.nco
+	    [[ -f ${file_o_to_a} ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_o_to_a}
+	    sed --in-place "s/src_/dst_/g" add_varoce.nco
+	    [[ -f ${file_a_to_o} ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_a_to_o}
+	    
+	    if [[ ${atm} = ico ]] ; then
+		cat <<EOF >add_varatm.nco
 defdim ("dst_grid_size"   , \$cell.size) ;
 defdim ("dst_grid_corners", 6) ;
@@ -446,16 +477,19 @@
 dst_grid_area  (:) = aire(:) ;
 EOF
-	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a}
-	    sed --in-place "s/dst_/src_/g" add_varatm.nco
-	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o}
-	    
-	    ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_o_to_a} rmp_tmp.nc
-	    mv rmp_tmp.nc ${file_o_to_a}
-	    ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_a_to_o} rmp_tmp.nc
-	    mv rmp_tmp.nc ${file_a_to_o}
-
-	fi
-	if [[ ${atm} = lmd ]] ; then
-	    cat <<EOF >add_varatm.nco
+		if [[ -f ${file_o_to_a} ]] ; then
+		    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a}
+		    ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_o_to_a} rmp_tmp.nc
+		    mv rmp_tmp.nc ${file_o_to_a}
+		fi
+		    
+		sed --in-place "s/dst_/src_/g" add_varatm.nco
+		if [[ -f ${file_a_to_o} ]] ; then
+		    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o}
+		    ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_a_to_o} rmp_tmp.nc
+		    mv rmp_tmp.nc ${file_a_to_o}
+		fi
+	    fi
+	    if [[ ${atm} = lmd ]] ; then
+		cat <<EOF >add_varatm.nco
 defdim ("dst_grid_size"   , \$lon.size*\$lat.size) ;
 defdim ("dst_grid_corners", 4) ;
@@ -484,14 +518,18 @@
 dst_grid_frac (:)  = OceFrac(0,:,:) ;
 EOF
-	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a}
-	    sed --in-place "s/dst/src/g" add_varatm.nco
-	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o}
-
-	    ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_area,dst_grid_imask ${file_o_to_a} rmp_tmp.nc
-	    mv rmp_tmp.nc ${file_o_to_a}
-	    ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_a_to_o} rmp_tmp.nc
-	    mv rmp_tmp.nc ${file_a_to_o}
-
-	fi
+		if [[ -f ${file_o_to_a} ]] ; then
+		    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a}
+		    ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_area,dst_grid_imask ${file_o_to_a} rmp_tmp.nc
+		    mv rmp_tmp.nc ${file_o_to_a}
+		fi
+		
+		sed --in-place "s/dst/src/g" add_varatm.nco
+		if [[ -f ${file_a_to_o} ]] ; then
+		    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o}
+		    ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_a_to_o} rmp_tmp.nc
+		    mv rmp_tmp.nc ${file_a_to_o}
+		fi
+	    fi
+	done
     done
 done
@@ -501,8 +539,13 @@
 ## ===========================================================================
 cp ${ATM}_grid_maskFrom_${OCE}.nc ${SUBMIT_DIR}
+
+cp rmp_c${atm}_to_t${oce}_${order}order.nc ${SUBMIT_DIR}/rmp_c${ATM}_to_t${OCE}_1storder.nc
+cp dia_c${atm}_to_t${oce}_${order}order.nc ${SUBMIT_DIR}/dia_c${ATM}_to_t${OCE}_1storder.nc
+
 for order in ${Listorder}
 do
     cp dia_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/dia_t${OCE}_to_t${ATM}_${order}order.nc
     cp rmp_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/rmp_t${OCE}_to_t${ATM}_${order}order.nc
+  
     for grid in ${Listocegrid} ; do
 	cp rmp_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/rmp_t${ATM}_to_${grid}${OCE}_${order}order.nc
