Index: TOOLS/MOSAIX/CreateWeightsMask.bash
===================================================================
--- TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3734)
+++ TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3901)
@@ -36,4 +36,11 @@
 #  $Id$
 #  $HeadURL$
+export Bold=$(tput bold)  
+export Unde=$(tput smul) ; export OffUnde=$(tput rmul)
+export Stou=$(tput smso) ; export OffStou=$(tput rmso)
+export Reve=$(tput rev ) 
+couleurs=( "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" )
+for i in $(seq 0 7 ) ; do eval "export ${couleurs[$i]}=$(tput setf $i)" ; done
+export Norm=$(tput sgr0 )
 
 ##
@@ -58,5 +65,5 @@
 # ===========================
 ListOCEGRID="T U V"
-ListOrder="1st" # " 2nd
+ListOrder="1st" # 2nd"
 ListNormalize="false true"
 
@@ -71,6 +78,6 @@
 # Defines computer
 # ================
-if [[ $(hostname) = curie* ]]    ; then arch=curie ; center=tgcc ; fi
-if [[ $(hostname) = irene* ]]    ; then arch=irene ; center=tgcc ; fi
+if [[ $(hostname) = curie*    ]] ; then arch=curie ; center=tgcc ; fi
+if [[ $(hostname) = irene*    ]] ; then arch=irene ; center=tgcc ; fi
 if [[ $(hostname) = lsce3005* ]] ; then arch=spip  ; center=spip ; fi
 
@@ -95,7 +102,5 @@
     MPIRUN=/opt/local/bin/mpirun-openmpi-gcc49 -n 2
     ;; 
-    ( * )
-    exit -1
-    ;;
+    ( * ) exit -1 ;;
 esac
 
@@ -127,5 +132,6 @@
 # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
 # ---------------------------------------------------------------------------
-FL_FMT=64bit
+FMT_OASIS=64bit
+FMT_XIOS=netcdf4
 
 
@@ -133,13 +139,38 @@
 cp ${SUBMIT_DIR}/*.py                .
 
-##
-## NEMO T point towards ATM - 1st order
-## ===========================================================================
+
 cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc  .
 cp ${R_IN}/ATM/GRID/${ATM}_grid.nc .
 
-ln -s ${OCE}_coordinates_mask.nc  oce_grid.nc
-ln -s ${ATM}_grid.nc              atm_grid.nc
-
+ncks --overwrite --fl_fmt=${FMT_OASIS} --history ${OCE}_coordinates_mask.nc ${OCE}_coordinates_mask_${FMT_OASIS}.nc
+ncks --overwrite --fl_fmt=${FMT_OASIS} --history ${ATM}_grid.nc                    ${ATM}_grid_${FMT_OASIS}.nc
+#
+# Creates OCEAN C grid : redundant point removed to compute proper integrals # A passer dans CreateWeights
+# ----------------------------------------------------------------------------
+cat <<EOF >add_c_grid.nco
+nav_lon_grid_C    = nav_lon_grid_T    ;
+nav_lat_grid_C    = nav_lat_grid_T    ;
+bounds_lon_grid_C = bounds_lon_grid_T ;
+bounds_lat_grid_C = bounds_lat_grid_T ;
+area_grid_C       = area_grid_T       ;
+mask_C            = maskutil_T        ; 
+EOF
+
+ncap2 --overwrite --history --script-file add_c_grid.nco ${OCE}_coordinates_mask.nc tmp_${OCE}_coordinates_mask.nc
+ncks --overwrite --variable nav_lon_grid_C,nav_lat_grid_C,bounds_lon_grid_C,bounds_lat_grid_C,area_grid_C,mask_C tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc
+rm tmp_${OCE}_coordinates_mask_${FMT_OASIS}.nc
+ncrename --dimension x_grid_T,x_grid_C                C_${OCE}_coordinates_mask.nc
+ncrename --dimension y_grid_T,y_grid_C                C_${OCE}_coordinates_mask.nc
+ncrename --dimension nvertex_grid_T,nvertex_grid_C    C_${OCE}_coordinates_mask.nc
+ncks --append C_${OCE}_coordinates_mask.nc            ${OCE}_coordinates_mask.nc
+rm C_${OCE}_coordinates_mask.nc
+
+ncks --overwrite --fl_fmt=${FMT_OASIS} --history {OCE}_coordinates_mask.nc ${OCE}_coordinates_mask_${FMT_OASIS}.nc
+
+ls -al
+
+##
+## NEMO T point towards ATM - 1st order
+## ===========================================================================
 echo ${Green}"${OCE} T toward ${ATM} - 1storder"${Norm}
 cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml   iodef.xml
@@ -162,4 +193,6 @@
 
 cp iodef.xml iodef_t${oce}_to_t${atm}_1storder_false.xml
+ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
+ln -fs ${ATM}_grid.nc              atm_grid.nc
 
 time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=no
@@ -197,19 +230,5 @@
 rm dia_t${oce}_to_t${atm}_1storder_false_mask.nc
 
-##
-## Creates mask of coastal OCE points
-## ===========================================================================
-python ComputeNemoCoast.py  -n ${OcePerio} -i oce_grid.nc
-
-##
-## Creates mask of coastal ATM points
-## ===========================================================================
-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
+
 
 ##
@@ -247,4 +266,6 @@
 		cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order_${normalize}.xml
 		
+		ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
+		ln -fs ${ATM}_grid.nc              atm_grid.nc
 		time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes
 	    fi
@@ -288,4 +309,6 @@
 	    cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize}.xml
 	    
+	    ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
+	    ln -fs ${ATM}_grid.nc              atm_grid.nc
 	    time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes
 	    
@@ -294,4 +317,19 @@
 done
 
+##
+## Creates mask of coastal OCE points
+## ===========================================================================
+python ComputeNemoCoast.py -n ${OcePerio} -i ${OCE}_coordinates_mask.nc # Creates OceCoastal
+##
+## Creates mask of coastal ATM points
+## ===========================================================================
+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
+ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc
 ##
 ## ATM towards NEMO points - runoff
@@ -312,18 +350,24 @@
     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_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]'   -k name  -v OceCoastal
-    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"]/file_definition/file[@id="dia"]'                               -k name  -v dia_o${atm}_to_c${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_o${atm}_to_c${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}
     
-    cp iodef.xml iodef_c${atm}_to_t${oce}_1storder_${normalize}.xml
+    cp iodef.xml iodef_o${atm}_to_c${oce}_1storder_${normalize}.xml
     
+    ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc
+    ln -fs ${ATM}_grid.nc              atm_grid.nc
     time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes
-done
-##
-## Change all NetCDF files to NetCDF 3 format (needed for OASIS)
+
+    # Now we should divide weight par source (atm) grid area : run-off is a quantity/s integrated on the grid mox, not a flux 
+done
+##
+## Copy all NetCDF files to NetCDF 3 format (needed for OASIS)
 ## ===========================================================================
 for InFile in *.nc ; do
-    mv ${InFile} tmp_${InFile}
-    ncks --alphabetize --fl_fmt=${FL_FMT} --history  tmp_${InFile}  ${InFile}
+    OuFile=$(basename ${InFile} .nc)_${FMT_OASIS}.nc
+    if [[ ! -f ${OuFile} ]] ; then
+	ncks --alphabetize --history --fl_fmt=${FMT_OASIS} ${InFile} ${OuFile}
+    fi
 done
 
@@ -334,4 +378,5 @@
 #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
+ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc
 
 if [[ ${atm} = ico ]] ; then
@@ -349,4 +394,6 @@
             ${ATM}_grid_maskFrom_${OCE}.nc
 fi
+ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc
+
 if [[ ${atm} = lmd ]] ; then
     cat <<EOF > add_time.nco
@@ -364,5 +411,5 @@
 fi
 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
-
+ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc
 
 ##
@@ -373,5 +420,5 @@
 NCO="$(ncks --version |& tail -1|sed 's/ncks //')"
 PYTHON_VER=$( python -i -c "import sys ; print (sys.version.split(' ')[0])" )
-for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ; do
+for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc; do
     ncatted --history \
 	    --attribute uuid,global,d,,                                           \
@@ -421,5 +468,5 @@
 for rmpFile in rmp_*.nc ; do
     mv ${rmpFile} xios_${rmpFile}
-    ncap2 --fl_fmt=${FL_FMT} --history --script-file add_dim.nco xios_${rmpFile} ${rmpFile}
+    ncap2 --fl_fmt=${FMT_OASIS} --history --script-file add_dim.nco xios_${rmpFile} ${rmpFile}
     
     ncrename --history --dimension n_weight,num_links   ${rmpFile}
@@ -460,4 +507,5 @@
 ## ===========================================================================
 for rmpFile in rmp_* ; do
+    echo ${rmpFile}
     a_to_o=false ; o_to_a=false
     case ${rmpFile} in
@@ -466,11 +514,9 @@
     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
+    for Grid in t u v o c ; do # Identify grids
+	[[ ${rmpFile} = rmp_${Grid}${oce}_to_?${atm}_*.nc ]] && ogrid=${Grid}
+	[[ ${rmpFile} = rmp_?${oce}_to_${Grid}${atm}_*.nc ]] && agrid=${Grid}
+	[[ ${rmpFile} = rmp_${Grid}${atm}_to_?${oce}_*.nc ]] && agrid=${Grid}
+	[[ ${rmpFile} = rmp_?${atm}_to_${Grid}${oce}_*.nc ]] && ogrid=${Grid}
     done
     OGRID=${ogrid^}
@@ -502,7 +548,7 @@
 EOF
 
-    [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${rmpFile}
+    [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce.nco ${OCE}_coordinates_mask_${FMT_OASIS}.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}
+    [[ ${a_to_o} = true ]] && ncap2 --history --append --script-file add_varoce.nco ${OCE}_coordinates_mask_${FMT_OASIS}.nc ${rmpFile}
 		
     if [[ ${atm} = ico ]] ; then
@@ -532,5 +578,5 @@
 EOF
 	if [[ ${o_to_a} = true ]] ; then
-	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.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}
@@ -539,5 +585,5 @@
 	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}
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.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}
@@ -573,5 +619,5 @@
 EOF
 	if [[ ${o_to_a} = true ]] ; then
-	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile}
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.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}
@@ -580,5 +626,5 @@
 	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}
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.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}
@@ -586,5 +632,5 @@
     fi
 done
-
+ls -al ${OCE}_coordinates_mask.nc
 ##
 ## Save results
