Index: TOOLS/MOSAIX/CreateWeightsMask.bash
===================================================================
--- TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 4317)
+++ TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 4320)
@@ -41,6 +41,7 @@
 # CplModel=ORCA2.3xICO40
 # CplModel=eORCA1.2xICO40
+# CplModel=eORCA1.2xICO450
 # CplModel=eORCA1.2xLMD256256
-# CplModel=eORCA1.2xICO450
+# CplModel=eORCA025.1xLMD144142
 # CplModel=eORCA025.1xLMD256256
 #
@@ -64,8 +65,8 @@
 echo ${Titre}"Defines model"${Norm}
 # =================================
-#CplModel=ORCA2.3xLMD9695
+CplModel=ORCA2.3xLMD9695
 #CplModel=ORCA2.3xICO30
 #CplModel=ORCA2.3xICO40
-CplModel=eORCA1.2xLMD144142
+#CplModel=eORCA1.2xLMD144142
 #CplModel=eORCA1.2xLMD256256
 #CplModel=eORCA1.2xICO40
@@ -73,5 +74,5 @@
 #CplModel=eORCA025.1xLMD256256
 
-Version="v3" ; Comment="Preliminary attempt - Do not trust !"
+Version="v0" ; Comment="Fully tested in IPSLCM6 eORCA1.2 x LMD 144x142"
 
 # If available, get model name from job name
@@ -120,9 +121,9 @@
 ## Classic cases for IPSLCM6
 AtmOceFluxes="   Direction=a2o,Order=1st,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=HeatWaterFluxes" # Heat and water fluxes
-OceAtmTemp="     Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb" # Temperature, sea-ice fraction, albedo
-OceAtmTemp2nd="  Direction=o2a,Order=2nd,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb" # Temperature, sea-ice fraction, albedo
-AtmOceStressU="  Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=u,useArea=true,maskSrc=true,maskDst=true,Name=WindStress" # Wind stress to NEMO U point
-AtmOceStressV="  Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=v,useArea=true,maskSrc=true,maskDst=true,Name=WindStress" # Wind stress to NEMO V point
-AtmOceQuantity=" Direction=a2o,Order=1st,Quantity=true,Renormalize=false,atmGrid=t,oceGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=Quantity"   # e.g. runoff
+OceAtmTemp="     Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb"      # Temperature, sea-ice fraction, albedo
+OceAtmTemp2nd="  Direction=o2a,Order=2nd,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb"      # Temperature, sea-ice fraction, albedo
+AtmOceStressU="  Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=u,useArea=true,maskSrc=true,maskDst=true,Name=WindStress"      # Wind stress to NEMO U point
+AtmOceStressV="  Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=v,useArea=true,maskSrc=true,maskDst=true,Name=WindStress"      # Wind stress to NEMO V point
+AtmOceQuantity=" Direction=a2o,Order=1st,Quantity=true,Renormalize=false,atmGrid=t,oceGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=Quantity"        # e.g. runoff
 # For new parameterization
 AtmOceTemp="     Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=OceTemp" # e.g. T and S correction from DWL parametrization
@@ -148,4 +149,5 @@
 #CommandList=( ${AtmOceFluxes} Runoff Calving Grids )
 #CommandList=( ${AtmOceFluxes} ${OceAtmTemp} )
+#CommandList=( ${AtmOceFluxes} )
 #CommandList=( Runoff )
 #CommandList=( Runoff Calving Grids )
@@ -232,6 +234,4 @@
 if [[ $(hostname) = lsce*     ]] ; then arch=spip  ; center=spip ; fi
 
-PROGRAM=$(basename ${0})
-
 case ${arch} in
     ( irene )
@@ -241,5 +241,4 @@
     TMPDIR=${CCCWORKDIR}/TMP
     SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
-    PROGRAM=${BRIDGE_MSUB_REQNAME}
     MpiRun="time ccc_mprun"
     PyRun="time ccc_mprun -n 1" # Needed to force python to run on one process only
@@ -319,4 +318,6 @@
 setValues ${DefaultValues}
 
+OutFileName=${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}
+
 cp iodef_oce_to_atm.xml   iodef.xml
 
@@ -331,5 +332,5 @@
 python3 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
 python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' -k name  -v area_grid_T
-python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}
+python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_${OutFileName}
 python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]'       -t "${SRC} mask interpolated to ${DST}"
 python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${srcDomainType}
@@ -338,5 +339,5 @@
 python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]'                    -k type  -v ${srcDomainType}
 python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                    -k type  -v ${dstDomainType}
-python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}.nc
+python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_${OutFileName}.nc
 python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k order -v 1
 python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t false
@@ -347,9 +348,21 @@
 python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k use_area    -v false
 
-cp iodef.xml iodef_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}.xml
+cp iodef.xml iodef_${OutFileName}.xml
 ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
 ln -fs ${ATM}_grid.nc              atm_grid.nc
 
 ${MpiRun} ./interpol.exe --mask_src=${maskSrc} --mask_dst=${maskDst} --use_area=${useArea}
+
+ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  rmp_${OutFileName}.nc
+ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  dia_${OutFileName}.nc
+
+ncatted --history --attribute normalization,global,o,c,"false"  rmp_${OutFileName}.nc
+ncatted --history --attribute normalization,global,o,c,"false"  dia_${OutFileName}.nc
+
+ncatted --history --attribute Quantity,global,o,c,"false"  rmp_${OutFileName}.nc
+ncatted --history --attribute Quantity,global,o,c,"false"  dia_${OutFileName}.nc
+
+ncatted --history --attribute UseArea,global,o,c,"false"  rmp_${OutFileName}.nc
+ncatted --history --attribute UseArea,global,o,c,"false"  dia_${OutFileName}.nc
 
 ##
@@ -419,8 +432,9 @@
 fi
 
-ncks --history --alphabetize  --append --variable aire atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc
+ncks --history --alphabetize --append --variable aire atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc
 ncatted  --history --attribute units,aire,m,c,"m^2" ${ATM}_grid_maskFrom_${OCE}.nc
 
 [[ ${atm} = *ico* ]] && ncks --alphabetize --history --append --variable bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc
+
 
 
@@ -481,4 +495,6 @@
 	;;
     esac
+
+    OutFileName=${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}
     
     python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]'                     -k type  -v ${dstDomainType}
@@ -488,5 +504,5 @@
     python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]'                      -k type  -v ${dstDomainType}
     
-    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k weight_filename -v rmp_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}.nc
+    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k weight_filename -v rmp_${OutFileName}.nc
     python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k order       -v ${numOrder}
     python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k quantity    -v ${Quantity}
@@ -494,5 +510,5 @@
     python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain'   -k use_area    -v ${useArea}
     
-    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                                 -k name -v dia_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}
+    python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                                 -k name -v dia_${OutFileName}
     python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]'         -t "${SRC} mask interpolated to ${DST}"
     python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]'     -t ${dstDomainType}
@@ -503,6 +519,27 @@
     python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="use_area"]'      -t ${useArea}
     
-    cp iodef.xml iodef_${srcGrid}${src}_to_${dstGrid}${dst}_${FullName}.xml
+    cp iodef.xml iodef_${OutFileName}.xml
     ${MpiRun} ./interpol.exe --mask_src=${maskSrc} --mask_dst=${maskDst} --use_area=${useArea}
+
+    case ${numOrder} in
+	( 1 )
+	ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  rmp_${OutFileName}.nc
+	ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  dia_${OutFileName}.nc
+	;;
+	( 2 )
+	ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  rmp_${OutFileName}.nc
+	ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  dia_${OutFileName}.nc
+	;;
+    esac
+
+    ncatted --history --attribute normalization,global,o,c,"${Renormalize}"  rmp_${OutFileName}.nc
+    ncatted --history --attribute normalization,global,o,c,"${Renormalize}"  dia_${OutFileName}.nc
+
+    ncatted --history --attribute Quantity,global,o,c,"${Quantity}"  rmp_${OutFileName}.nc
+    ncatted --history --attribute Quantity,global,o,c,"${Quantity}"  dia_${OutFileName}.nc
+
+    ncatted --history --attribute UseArea,global,o,c,"${useArea}"  rmp_${OutFileName}.nc
+    ncatted --history --attribute UseArea,global,o,c,"${useArea}"  dia_${OutFileName}.nc
+    
 done
 
@@ -529,5 +566,5 @@
 	    --attribute description,global,o,c,"Fields needed by OASIS-MCT"       \
 	    --attribute title,global,o,c,"${InFile}.nc"                           \
-	    --attribute Program,global,o,c,"Generated by ${PROGRAM}"              \
+	    --attribute Program,global,o,c,"Generated by CreateWeightsMask"       \
 	    --attribute timeStamp,global,o,c,"$(date)"                            \
 	    --attribute HOSTNAME,global,o,c,"$(hostname)"                         \
@@ -545,4 +582,9 @@
 	    ${InFile}
 done
+
+# Duplicate with no global attribute to avoid erasing attributes in other files
+cp ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_noglobal.nc
+ncatted --history --attribute ,global,d,c, ${ATM}_grid_maskFrom_${OCE}_noglobal.nc
+
 ##
 echo ${Titre}"Update and complete weight files to fit OASIS requested format"${Norm}
@@ -561,16 +603,6 @@
     ncrename --history --variable  dst_idx,dst_address  ${rmpFile}
     ncrename --history --variable  weight,remap_matrix  ${rmpFile}
-    case ${rmpFile} in
-	( *1storder* ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  ${rmpFile} ;;
-	( *2ndorder* ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  ${rmpFile} ;;
-    esac
-    case ${rmpFile} in
-	( *_Normalized*   ) ncatted --history --attribute map_method,global,o,c,"Normalization: true"  ${rmpFile} ;;
-	( *_UnNormalized* ) ncatted --history --attribute map_method,global,o,c,"Normalization: false" ${rmpFile} ;;
-    esac
-    case ${rmpFile} in
-	( *Integrated*   ) ncatted --history --attribute map_method,global,o,c,"Quantity: true"  ${rmpFile} ;;
-	( *Surfacic*     ) ncatted --history --attribute map_method,global,o,c,"Quantity: false" ${rmpFile} ;;
-    esac
+
+  
     ncatted --history --attribute conventions,global,o,c,"SCRIP"   ${rmpFile}
     ncatted --history --attribute normalization,global,o,c,"none"  ${rmpFile}
@@ -674,5 +706,5 @@
 	cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco
 	if [[ ${o_to_a} = true ]] ; then
-	    ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco ${ATM}_grid_maskFrom_${OCE}_noglobal.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}
@@ -682,5 +714,6 @@
 	cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco
 	if [[ ${a_to_o} = true ]] ; then
-	    ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco ${ATM}_grid_maskFrom_${OCE}_noglobal.nc ${rmpFile}
+	    exit
 	    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}
@@ -718,5 +751,5 @@
 	cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco
 	if [[ ${o_to_a} = true ]] ; then
-	    ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco ${ATM}_grid_maskFrom_${OCE}_noglobal.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}
@@ -726,5 +759,5 @@
 	cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco
 	if [[ ${a_to_o} = true ]] ; then
-	    ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    ncap2 --history --append --script-file add_varatm_$(basename ${rmpFile} .nc)_a_to_o.nco ${ATM}_grid_maskFrom_${OCE}_noglobal.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}
@@ -733,5 +766,4 @@
 done
 ls -al ${OCE}_coordinates_mask.nc
-
 ##
 ## ============================================================================
@@ -882,5 +914,5 @@
 
 for file in $(ls dia_*.nc rmp_*.nc ${ATM}_grid_maskFrom_${OCE}*.nc areas_${OCE}x${ATM}*.nc grids_${OCE}x${ATM}*.nc masks_${OCE}x${ATM}*.nc 2> /dev/null ) ; do
-    ncatted --attribute uuid,global,o,c,"${UUID}" ${file}
+    ncatted --history --attribute uuid,global,o,c,"${UUID}" ${file}
     echo "$(shasum ${file})" >> README.txt
 done
