Index: /TOOLS/MOSAIX/CreateWeightsMask.bash
===================================================================
--- /TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3718)
+++ /TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3719)
@@ -1,9 +1,9 @@
 #!/bin/bash
-#MSUB -r WeightsMask        # nom de la requete
-#MSUB -o Out_WeightsMask    # nom du fichier de sortie
-#MSUB -e Out_WeightsMask    # nom du fichier de sortie
+#MSUB -r WeightsMask        # Job name
+#MSUB -o Out_WeightsMask    # Standard output
+#MSUB -e Out_WeightsMask    # Error output
 #MSUB -eo
-#MSUB -n 4              # Reservation des processeurs pour le job
-#MSUB -T 1800           # Limite temps (en secondes)
+#MSUB -n 4              # Number of processors
+#MSUB -T 1800           # Time limit (seconds)
 #MSUB -q standard
 #MSUB -Q test
@@ -12,5 +12,5 @@
 ### ===========================================================================
 ###
-### Creates interpolation weights between ORCA and atmospher grids.
+### Creates interpolation weights between ORCA and atmosphere grids.
 ### Interpolates ORCA mask to atmosphere grid.
 ### Weight files are at OASIS-MCT format.
@@ -58,5 +58,6 @@
 # ===========================
 ListOCEGRID="T U V"
-Listorder="1st" # " 2nd
+ListOrder="1st" # " 2nd
+ListNormalize="false true"
 
 ## ===========================================================================
@@ -99,5 +100,5 @@
 # Suffixes
 # ---------------------------------------------------------------------------
-Listocegrid=${ListOCEGRID~}
+Listocegrid=${ListOCEGRID,,}
 
 case ${OCE} in
@@ -135,5 +136,5 @@
 python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${atm_domain_type}
 python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name  -v maskutil_T
-python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_t${oce}_to_t${atm}_1storder
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_t${oce}_to_t${atm}_1storder_false
 python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]'       -t "${OCE} mask interpolated to ${ATM}"
 python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type}
@@ -142,8 +143,10 @@
 python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${oce_domain_type}
 python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${atm_domain_type}
-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_t${oce}_to_t${atm}_1storder.nc
+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_t${oce}_to_t${atm}_1storder_false.nc
 python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1
-
-cp iodef.xml iodef_t${oce}_to_t${atm}_1storder.xml
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t false
+python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k renormalize -v false
+
+cp iodef.xml iodef_t${oce}_to_t${atm}_1storder_false.xml
 
 time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=no
@@ -160,14 +163,14 @@
 where (OceFrac <  0.0 )  OceFrac=0.0 ; 
 EOF
-ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_1storder.nc tmp_dia_t${oce}_to_t${atm}_1storder.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder.nc dia_t${oce}_to_t${atm}_1storder.nc
-ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder.nc
+ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_1storder_false.nc tmp_dia_t${oce}_to_t${atm}_1storder_false.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_false.nc dia_t${oce}_to_t${atm}_1storder_false.nc
+ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder_false.nc
 
 ##
 ##  Creates mask on ATM grid
 ## ===========================================================================
-cp dia_t${oce}_to_t${atm}_1storder.nc  dia_t${oce}_to_t${atm}_1storder_mask.nc
-ncks --alphabetize --history --overwrite --variable OceFrac dia_t${oce}_to_t${atm}_1storder_mask.nc  ${ATM}_grid_maskFrom_${OCE}.nc
-ncks --alphabetize --history --append    --variable aire    atm_grid.nc                              ${ATM}_grid_maskFrom_${OCE}.nc
-[[ ${atm} = *ico* ]] && ncks --alphabetize --history --append --variable bounds_lon,bounds_lat atm_grid.nc                              ${ATM}_grid_maskFrom_${OCE}.nc
+cp dia_t${oce}_to_t${atm}_1storder_false.nc  dia_t${oce}_to_t${atm}_1storder_false_mask.nc
+ncks --alphabetize --history --overwrite --variable OceFrac dia_t${oce}_to_t${atm}_1storder_false_mask.nc  ${ATM}_grid_maskFrom_${OCE}.nc
+ncks --alphabetize --history --append    --variable aire    atm_grid.nc                                    ${ATM}_grid_maskFrom_${OCE}.nc
+[[ ${atm} = *ico* ]] && ncks --alphabetize --history --append --variable bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc
 
 cat <<EOF > creation_masque.nco
@@ -175,11 +178,12 @@
 where (OceFrac <= 0.0 )  OceFrac=0 ;
 EOF
-ncap2 --history --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_1storder_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc dia_t${oce}_to_t${atm}_1storder_mask.nc
-ncrename --history --variable OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc
-
-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
+ncap2 --history --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_1storder_false_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_false_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_false_mask.nc dia_t${oce}_to_t${atm}_1storder_false_mask.nc
+ncrename --history --variable OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_false_mask.nc
+
+ncks --alphabetize --history --append --variable OceMask dia_t${oce}_to_t${atm}_1storder_false_mask.nc   ${ATM}_grid_maskFrom_${OCE}.nc
+#rm dia_t${oce}_to_t${atm}_1storder_false_mask.nc
+
+##
+## Creates mask of coastal ATM point
 ## ===========================================================================
 cat <<EOF > coastal.nco
@@ -194,35 +198,39 @@
 ## NEMO, other case, towards ATM 
 ## ===========================================================================
-for order in ${Listorder} ; do
+for order in ${ListOrder} ; do
     case ${order} in
 	( 1st ) num_order=1 ;;
 	( 2nd ) num_order=2 ;;
     esac
-    
-    for OCEGRID in ${ListOCEGRID} ; do
-	ocegrid=${OCEGRID~}
-
-	if [[ !( ${order} = 1st && ${OCEGRID} = T ) ]] ; then
-
-	    echo ${Green}"${OCE} ${OCEGRID} toward ${ATM} - ${order}order"${Norm}
-
-	    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 maskutil_${OCEGRID}
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                   -k type  -v ${oce_domain_type}
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                   -k type  -v ${atm_domain_type}
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name  -v maskutil_${OCEGRID}
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_${ocegrid}${oce}_to_t${atm}_${order}order
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]'       -t "${OCE} mask interpolated to ${ATM}"
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type}
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'   -t ${atm_domain_type}
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t ${num_order}
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${oce_domain_type}
-	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${atm_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 ${num_order}
-	    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_${ocegrid}${oce}_to_t${atm}_${order}order.nc
-	    cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order.xml
+    for normalize in ${ListNormalize} ; do
+	for OCEGRID in ${ListOCEGRID} ; do
+	    ocegrid=${OCEGRID,,}
 	    
-	    time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes
-	fi
-	
+	    if [[ ! -f rmp_${ocegrid}${oce}_to_t${atm}_${order}order_${normalize}.nc ]] ; then
+		
+		echo ${Green}"${OCE} ${OCEGRID} toward ${ATM} - ${order}order - normalize: ${normalize}"${Norm}
+		
+		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 maskutil_${OCEGRID}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]'                     -k type  -v ${oce_domain_type}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                     -k type  -v ${atm_domain_type}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]'   -k name  -v maskutil_${OCEGRID}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                                 -k name  -v dia_${ocegrid}${oce}_to_t${atm}_${order}order_${normalize}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]'         -t "${OCE} mask interpolated to ${ATM}"
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]'   -t ${oce_domain_type}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'     -t ${atm_domain_type}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'         -t ${num_order}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                      -k type  -v ${oce_domain_type}
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                      -k type  -v ${atm_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 ${num_order}
+		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_${ocegrid}${oce}_to_t${atm}_${order}order_${normalize}.nc
+		python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize     -v ${normalize}
+		
+		cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order_${normalize}.xml
+		
+		time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes
+	    fi
+	    
+	done
     done
 done
@@ -241,49 +249,56 @@
 python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${oce_domain_type}
 	    
-for order in ${Listorder} ; do
+for order in ${ListOrder} ; do
     case ${order} in
 	( 1st ) num_order=1 ;;
 	( 2nd ) num_order=2 ;;
     esac
-    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v ${num_order}
-    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'       -t ${num_order}   
+    for normalize in ${ListNormalize} ; do
+	python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k order -v ${num_order}
+	python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]'         -t ${num_order}   
+    	python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize}
+	python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k renormalize     -v ${normalize}
+	
+	for OCEGRID in ${ListOCEGRID} ; do
+	    ocegrid=${OCEGRID,,}
+	    
+	    echo ${Green}"${ATM} toward ${OCE} ${OCEGRID} - ${order}order - normalize: ${normalize}"${Norm}
+	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]'   -k name  -v mask_${OCEGRID}
+	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]'   -k name  -v mask_${OCEGRID}
+	    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize}
+	    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_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize}.nc
+	    cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize}.xml
+	    
+	    time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes
+	    
+	done
+    done
+done
+
+##
+## ATM towards NEMO points - runoff
+## ===========================================================================
+cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml           iodef.xml
+for normalize in ${ListNormalize} ; do
+    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_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${normalize}
+    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_${normalize}
+    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_${normalize}.nc
+    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize     -v ${normalize}
     
-    for OCEGRID in ${ListOCEGRID} ; do
-	ocegrid=${OCEGRID~}
-
-	echo ${Green}"${ATM} toward ${OCE} ${OCEGRID} - ${order}order"${Norm}
-	python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]'   -k name  -v mask_${OCEGRID}
-	python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]'   -k name  -v mask_${OCEGRID}
-	python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_t${atm}_to_${ocegrid}${oce}_${order}order
-	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_t${atm}_to_${ocegrid}${oce}_${order}order.nc
-	cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order.xml
-	
-	time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes
-	
-    done
-done
-
-##
-## 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
-
+    cp iodef.xml iodef_c${atm}_to_t${oce}_1storder_${normalize}.xml
+    
+    time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes
+done
 ##
 ## Change all NetCDF files to NetCDF 3 format (needed for OASIS)
@@ -298,33 +313,40 @@
 ## (needed if files need to be read by XIOS)
 ## ===========================================================================
+#ncatted --history -a coordinates,aire,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc
+ncap2 --overwrite --history --script 'defdim("time_counter",1) ;' ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+
 if [[ ${atm} = ico ]] ; then
     cat <<EOF > add_time.nco
-defdim("time_counter",1) ;
-OceFrac [time_counter,cell] = OceFrac (:) ;
-OceMask [time_counter,cell] = OceMask (:) ;
-EOF
-    ncap2 --overwrite --history --script-file add_time.nco   ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
-    ncks --alphabetize --overwrite --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+OceFrac    [time_counter,cell] = OceFrac    (:) ;
+OceMask    [time_counter,cell] = OceMask    (:) ;
+AtmCoastal [time_counter,cell] = AtmCoastal (:) ;
+EOF
+    ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
     ncatted --history \
-	    -a coordinates,OceFrac,c,c,"time_counter cell" \
-            -a coordinates,OceMask,c,c,"time_counter cell" \
-            -a coordinates,aire,c,c,"time_counter cell"    ${ATM}_grid_maskFrom_${OCE}.nc
+	    -a coordinates,OceFrac,c,c,"time_counter cell"    \
+            -a coordinates,OceMask,c,c,"time_counter cell"    \
+            -a coordinates,AtmCoastal,c,c,"time_counter cell" \
+	    -a coordinates,aire,c,c,"cell" \
+            ${ATM}_grid_maskFrom_${OCE}.nc
 fi
 if [[ ${atm} = lmd ]] ; then
     cat <<EOF > add_time.nco
-defdim("time_counter",1) ;
-OceFrac [time_counter,lat,lon] = OceFrac (:,:) ;
-OceMask [time_counter,lat,lon] = OceMask (:,:) ;
-EOF
-    ncap2 --overwrite --history --script-file add_time.nco   ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
-    ncks --alphabetize --overwrite --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+OceFrac    [time_counter,lat,lon] = OceFrac    (:,:) ;
+OceMask    [time_counter,lat,lon] = OceMask    (:,:) ;
+AtmCoastal [time_counter,lat,lon] = AtmCoastal (:,:) ;
+EOF
+    ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
     ncatted --history \
-	    -a coordinates,OceFrac,c,c,"time_counter lat lon" \
-            -a coordinates,OceMask,c,c,"time_counter lat lon" \
-            -a coordinates,aire,c,c,"time_counter lat lon"    ${ATM}_grid_maskFrom_${OCE}.nc
+	    -a coordinates,OceFrac,c,c,"time_counter lat lon"    \
+            -a coordinates,OceMask,c,c,"time_counter lat lon"    \
+            -a coordinates,AtmCoastal,c,c,"time_counter lat lon" \
+            -a coordinates,aire,c,c,"lat lon" \
+            ${ATM}_grid_maskFrom_${OCE}.nc
 fi
-
-##
-## Add some information in file headers
+ncks --alphabetize --overwrite --mk_rec time_counter   ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+
+
+##
+## Add some metadata in file headers
 ## ===========================================================================
 
@@ -378,20 +400,24 @@
 EOF
 
-for file in rmp_*${oce}_to_*${atm}_*.nc rmp_*${atm}_to_*${oce}_*.nc ; do
-    mv ${file} xios_${file}
-    ncap2 --fl_fmt=${FL_FMT} --history --script-file add_dim.nco xios_${file} ${file}
+for rmpFile in rmp_*.nc ; do
+    mv ${rmpFile} xios_${rmpFile}
+    ncap2 --fl_fmt=${FL_FMT} --history --script-file add_dim.nco xios_${rmpFile} ${rmpFile}
     
-    ncrename --history --dimension n_weight,num_links   ${file}
-    ncrename --history --variable  src_idx,src_address  ${file}
-    ncrename --history --variable  dst_idx,dst_address  ${file}
-    ncrename --history --variable  weight,remap_matrix  ${file}
-    case ${file} in
-	( *1storder.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  ${file} ;;
-	( *2ndorder.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  ${file} ;;
+    ncrename --history --dimension n_weight,num_links   ${rmpFile}
+    ncrename --history --variable  src_idx,src_address  ${rmpFile}
+    ncrename --history --variable  dst_idx,dst_address  ${rmpFile}
+    ncrename --history --variable  weight,remap_matrix  ${rmpFile}
+    case ${rmpFile} in
+	( *_1storder_*.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  ${rmpFile} ;;
+	( *_2ndorder_*.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  ${rmpFile} ;;
     esac
-    ncatted --history --attribute conventions,global,o,c,"SCRIP"   ${file}
-    ncatted --history --attribute normalization,global,o,c,"none"  ${file}
+    case ${rmpFile} in
+	( *_true.nc  ) ncatted --history --attribute map_method,global,o,c,"Normalization: true"  ${rmpFile} ;;
+	( *_false.nc ) ncatted --history --attribute map_method,global,o,c,"Normalization: false" ${rmpFile} ;;
+    esac
+    ncatted --history --attribute conventions,global,o,c,"SCRIP"   ${rmpFile}
+    ncatted --history --attribute normalization,global,o,c,"none"  ${rmpFile}
     
-    case ${file} in
+    case ${rmpFile} in
 	( rmp_*${oce}_to_t${atm}_* )
 	ncatted --history \
@@ -399,5 +425,5 @@
 		--attribute source_grid,global,o,c,"${oce_domain_type}" \
 		--attribute dest_grid,global,o,c,"${atm_domain_type}"   \
-		${file}	
+		${rmpFile}	
 	;;
 	( rmp_*${atm}_to_*${oce}_* )
@@ -406,5 +432,5 @@
 		--attribute source_grid,global,o,c,"${atm_domain_type}" \
 		--attribute dest_grid,global,o,c,"${oce_domain_type}"   \
-		${file}
+		${rmpFile}
 	;;
     esac
@@ -414,14 +440,23 @@
 ## Add missing variables in rmp files
 ## ===========================================================================
-for OGRID in ${ListOCEGRID} ; do
-    for AGRID in T C ; do
-	for order in ${Listorder} ; do
-	    ogrid=${OGRID~}
-	    agrid=${AGRID~}
+for rmpFile in rmp_* ; do
+    a_to_o=false ; o_to_a=false
+    case ${rmpFile} in
+	(  rmp_?${oce}_to_?${atm}_*.nc ) o_to_a=true ;;
+	(  rmp_?${atm}_to_?${oce}_*.nc ) a_to_o=true ;;
+    esac
+
+    for Grid in t u v c ; do # Identify grids
+	case ${rmpFile} in
+	    (  rmp_${Grid}${oce}_to_?${atm}_*.nc ) ogrid=${Grid} ;;
+	    (  rmp_?${oce}_to_${Grid}${atm}_*.nc ) agrid=${Grid} ;;
+	    (  rmp_${Grid}${atm}_to_?${oce}_*.nc ) agrid=${Grid} ;;
+	    (  rmp_?${atm}_to_${Grid}${oce}_*.nc ) ogrid=${Grid} ;;
+	esac
+    done
+    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
+    cat <<EOF >add_varoce.nco
 defdim ("src_grid_size"   , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ;
 defdim ("src_grid_corners", 4) ;
@@ -448,10 +483,10 @@
 EOF
 
-	    [[ -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
+    [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${rmpFile}
+    sed --in-place "s/src_/dst_/g" add_varoce.nco
+    [[ ${a_to_o} = true ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${rmpFile}
+		
+    if [[ ${atm} = ico ]] ; then
+	cat <<EOF >add_varatm.nco
 defdim ("dst_grid_size"   , \$cell.size) ;
 defdim ("dst_grid_corners", 6) ;
@@ -477,19 +512,19 @@
 dst_grid_area  (:) = aire(:) ;
 EOF
-		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
+	if [[ ${o_to_a} = true ]] ; then
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    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 ${rmpFile} rmp_tmp.nc
+	    mv rmp_tmp.nc ${rmpFile}
+	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
+	sed --in-place "s/dst_/src_/g" add_varatm.nco
+	if [[ ${a_to_o} = true ]] ; then
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    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 ${rmpFile} rmp_tmp.nc
+	    mv rmp_tmp.nc ${rmpFile}
+	fi
+    fi
+    if [[ ${atm} = lmd ]] ; then
+	cat <<EOF >add_varatm.nco
 defdim ("dst_grid_size"   , \$lon.size*\$lat.size) ;
 defdim ("dst_grid_corners", 4) ;
@@ -518,19 +553,17 @@
 dst_grid_frac (:)  = OceFrac(0,:,:) ;
 EOF
-		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
+	if [[ ${o_to_a} = true ]] ; then
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    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 ${rmpFile} rmp_tmp.nc
+	    mv rmp_tmp.nc ${rmpFile}
+	fi
+	
+	sed --in-place "s/dst/src/g" add_varatm.nco
+	if [[ ${a_to_o} = true ]] ; then
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    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 ${rmpFile} rmp_tmp.nc
+	    mv rmp_tmp.nc ${rmpFile}
+	fi
+    fi
 done
 
@@ -539,17 +572,8 @@
 ## ===========================================================================
 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}
+for File in dia_*.nc rmp_*.nc
 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
-	cp dia_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/dia_t${ATM}_to_${grid}${OCE}_${order}order.nc
-    done
+    NewFile=$(echo ${File} | sed -e "s/${atm}/${ATM}/" -e "s/${oce}/${OCE}/" )
+    cp ${File} ${SUBMIT_DIR}/${NewFile}
 done
 
