Index: /TOOLS/MOSAIX/CreateWeightsMask.bash
===================================================================
--- /TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 4316)
+++ /TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 4317)
@@ -3,5 +3,4 @@
 #MSUB -o Out_WeightsMask    # Standard output
 #MSUB -e Out_WeightsMask    # Error output
-#MSUB -eo
 #MSUB -n 16                 # Number of processors
 #MSUB -T 7200               # Time limit (seconds)
@@ -37,12 +36,12 @@
 #  $HeadURL$
 #
-# export CplModel=eORCA1.2xLMD144142 ; qsub -r ${CplModel} -o Out_${CplModel} -e Out_${CplModel} CreateWeightsMask.bash
-# export CplModel=ORCA2.3xLMD9695
-# export CplModel=ORCA2.3xICO30
-# export CplModel=ORCA2.3xICO40
-# export CplModel=eORCA1.2xICO40
-# export CplModel=eORCA1.2xLMD256256
-# export CplModel=eORCA1.2xICO450
-# export CplModel=eORCA025.1xLMD256256
+# CplModel=eORCA1.2xLMD144142 ; qsub -r ${CplModel} -o Out_${CplModel} -e Out_${CplModel} CreateWeightsMask.bash
+# CplModel=ORCA2.3xLMD9695
+# CplModel=ORCA2.3xICO30
+# CplModel=ORCA2.3xICO40
+# CplModel=eORCA1.2xICO40
+# CplModel=eORCA1.2xLMD256256
+# CplModel=eORCA1.2xICO450
+# CplModel=eORCA025.1xLMD256256
 #
 
@@ -63,26 +62,22 @@
 
 #
-echo ${Titre}"Defines models"${Norm}
-# ==================================
-OCE=ORCA2.3
-#OCE=eORCA1.2
-#OCE=eORCA025.1
-
-ATM=ICO30
-#ATM=ICO40
-#ATM=ICO450
-#ATM=LMD9695
-#ATM=LMD144142
-#ATM=LMD256256
-
-
-Comment="Preliminary attempt - Do not trust !"
-Version="v2"
-
-CplModel=${OCE}x${ATM}
-# If available, get model names from job name
+echo ${Titre}"Defines model"${Norm}
+# =================================
+#CplModel=ORCA2.3xLMD9695
+#CplModel=ORCA2.3xICO30
+#CplModel=ORCA2.3xICO40
+CplModel=eORCA1.2xLMD144142
+#CplModel=eORCA1.2xLMD256256
+#CplModel=eORCA1.2xICO40
+#CplModel=eORCA1.2xICO450
+#CplModel=eORCA025.1xLMD256256
+
+Version="v3" ; Comment="Preliminary attempt - Do not trust !"
+
+# If available, get model name from job name
 if [[ X${SLURM_JOB_NAME} = X*ORC* ||  X${SLURM_JOB_NAME} = X*LMD*  ||  X${SLURM_JOB_NAME} = X*ICO* ]] ; then
-    CplModel=${SLURM_JOB_NAME} ; OCE=${CplModel//x*} ; ATM=${CplModel##*x}
+    CplModel=${SLURM_JOB_NAME} ; 
 fi
+OCE=${CplModel//x*} ; ATM=${CplModel##*x}
 
 echo ${Titre}"ATM model : ${ATM}"${Norm}
@@ -99,5 +94,4 @@
 [[ ${OCE} = eORCA1.2  ]] && oceCoastWidth=3
 [[ ${OCE} = eORCA025* ]] && oceCoastWidth=1
-
 
 # Default values, used to create ocean fraction on atmospheric grid 
@@ -137,5 +131,5 @@
 AtmOceFluxes2nd="Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=HeatWaterFluxes" # Heat and water fluxes
 OceAtmFluxes2nd="Direction=o2a,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=OceAtmFluxes" # e.g. CO2 fluxes
-AtmOceTemps2nd=" Direction=o2a,Order=2nd,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
+AtmOceTemp2nd="  Direction=o2a,Order=2nd,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
 
 ## Creates the list
@@ -145,13 +139,13 @@
 
 # More comprehensive list for IPSLCM6 with new features
-CommandList=( ${AtmOceFluxes} ${OceAtmTemp} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${AtmOceTemp} Runoff Calving Grids )
+#CommandList=( ${AtmOceFluxes} ${OceAtmTemp} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${AtmOceTemp} Runoff Calving Grids )
 
 # With 2nd order
-#CommandList=( ${AtmOceFluxes} ${AtmOceFluxes2nd} ${OceAtmTemp} ${OceAtmTemp2nd} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${OceAtmFluxes2nd} ${AtmOceTemp} ${AtmOceTemp2nd} Runoff Calving Grids )
+CommandList=( ${AtmOceFluxes} ${AtmOceFluxes2nd} ${OceAtmTemp} ${OceAtmTemp2nd} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${OceAtmFluxes2nd} ${AtmOceTemp} ${AtmOceTemp2nd} Runoff Calving Grids )
 
 # Debugs
 #CommandList=( ${AtmOceFluxes} ${OceAtmTemp} Runoff Calving Grids )
 #CommandList=( ${AtmOceFluxes} Runoff Calving Grids )
-#CommandList=( ${AtmOceFluxes}  )
+#CommandList=( ${AtmOceFluxes} ${OceAtmTemp} )
 #CommandList=( Runoff )
 #CommandList=( Runoff Calving Grids )
@@ -187,10 +181,11 @@
 
 function setValues {
-    #
+    # Set default values
     read_Command "Direction=None,Order=None,Quantity=None,Renormalize=None,atmGrid=None,oceGrid=None,useArea=None,maskSrc=None,maskDst=None"
+    # Read command line
     read_Command ${1}
     #
-    oceGrid=${oceGrid,,} ; atmGrid=${atmGrid,,}
-    OCEGRID=${oceGrid^^} ; ATMGRID=${atmGrid^^}
+    oceGrid=${oceGrid,,} ; atmGrid=${atmGrid,,} # Model names to lower case
+    OCEGRID=${oceGrid^^} ; ATMGRID=${atmGrid^^} # Model names to upper case
 
     case ${Order} in
@@ -303,30 +298,18 @@
 cp ${R_IN}/ATM/GRID/${ATM}_grid.nc .
 
-#
-# echo ${Titre}"Creates OCEAN C grid : redundant points removed to compute proper integrals # A passer dans CreateWeights"${Norm}
-# # --------------------------------------------------------------------------------------------------------
-# cat <<EOF >add_c_grid.nco
-# defdim("x_grid_C", \$x_grid_T.size) ;
-# defdim("y_grid_C", \$y_grid_T.size) ;
-# defdim("nvertex_grid_C",  4)         ;
-# nav_lon_grid_C[y_grid_C,x_grid_C]    = nav_lon_grid_T(:,:)    ;
-# nav_lat_grid_C[y_grid_C,x_grid_C]    = nav_lat_grid_T(:,:)    ;
-# bounds_lon_grid_C[y_grid_C,x_grid_C,nvertex_grid_C] = bounds_lon_grid_T(:,:,:) ;
-# bounds_lat_grid_C[y_grid_C,x_grid_C,nvertex_grid_C] = bounds_lat_grid_T(:,:,:) ;
-# mask_C[y_grid_C,x_grid_C]            = maskutil_T(:,:)        ; 
-# area_grid_C[y_grid_C,x_grid_C]       = area_grid_T(:,:)       ;
-# EOF
-
-# ncap2 --overwrite --history --script-file add_c_grid.nco ${OCE}_coordinates_mask.nc tmp_${OCE}_coordinates_mask.nc
-# ncatted --history --attribute bounds,nav_lon_grid_C,m,c,"bounds_lon_grid_C" tmp_${OCE}_coordinates_mask.nc
-# ncatted --history --attribute bounds,nav_lat_grid_C,m,c,"bounds_lat_grid_C" tmp_${OCE}_coordinates_mask.nc
-# ncks --history --overwrite --variable nav_lon_grid_C,nav_lat_grid_C       tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc
-# ncks --history --append    --variable bounds_lon_grid_C,bounds_lat_grid_C tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc
-# ncks --history --append    --variable area_grid_C             tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc 
-
-# ncks --history --append C_${OCE}_coordinates_mask.nc            ${OCE}_coordinates_mask.nc
-# rm C_${OCE}_coordinates_mask.nc
-
-# ls -al
+# Soucis a corriger plus tard
+if [[ ${ATM} = LMD9695 ]] ; then
+    cat <<EOF > toDouble.nco
+lat                = double (lat) ;
+lon                = double (lon) ;
+aire               = double (aire) ;
+fract_oce          = double (fract_oce) ;
+fract_sic          = double (fract_sic) ;
+fract_oce_plus_sic = double (fract_oce_plus_sic) ;
+EOF
+    ncap2 --history --overwrite --script-file toDouble.nco ${ATM}_grid.nc tmp_${ATM}_grid.nc
+    mv tmp_${ATM}_grid.nc ${ATM}_grid.nc
+fi
+
 
 ##
@@ -391,4 +374,5 @@
 cp dia_t${oce}_to_t${atm}_${FullName}.nc  dia_t${oce}_to_t${atm}_${FullName}_mask.nc
 ncks --alphabetize --history --overwrite --variable OceFrac dia_t${oce}_to_t${atm}_${FullName}_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc
+ncatted  --history --attribute name,global,m,c,"${ATM}_grid_maskFrom_${OCE}.nc" ${ATM}_grid_maskFrom_${OCE}.nc
 
 cat <<EOF > creation_masque.nco
@@ -401,7 +385,7 @@
 ncks --overwrite --history --variable OceMask,OceFrac,Oce2AtmMask tmp_dia_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
 
-echo "Change dimension names, and some attributes accordingly"
-## ===========================================================
 if [[ $(ncdump -h ${ATM}_grid_maskFrom_${OCE}.nc | grep domain_dst | wc -l) -gt 0 ]] ; then
+    echo "Change dimension names, and some attributes accordingly"
+    ## ===========================================================
     case ${atm} in
 	( *ico* ) 
@@ -415,7 +399,9 @@
 	ncatted  --history --attribute bounds,lon,m,c,"bounds_lon"       ${ATM}_grid_maskFrom_${OCE}.nc
 	;;
-	( *lmd* ) 
-	ncrename --history --dimension lon_domain_dst,lon            ${ATM}_grid_maskFrom_${OCE}.nc
-	ncrename --history --dimension lat_domain_dst,lat            ${ATM}_grid_maskFrom_${OCE}.nc
+	( *lmd* )
+	ncrename --history --variabl   lon_domain_dst,lon                ${ATM}_grid_maskFrom_${OCE}.nc
+	ncrename --history --variable  lat_domain_dst,lat                ${ATM}_grid_maskFrom_${OCE}.nc
+	ncrename --history --dimension lon_domain_dst,lon                ${ATM}_grid_maskFrom_${OCE}.nc
+	ncrename --history --dimension lat_domain_dst,lat                ${ATM}_grid_maskFrom_${OCE}.nc
 	;;
     esac
@@ -423,13 +409,18 @@
     ncatted  --history --attribute coordinates,OceMask,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc
     ncatted  --history --attribute coordinates,Oce2AtmMask,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc
+
+    ncatted  --history --attribute long_name,OceFrac,c,c,"fraction of ocean in a grid cell" ${ATM}_grid_maskFrom_${OCE}.nc
+    ncatted  --history --attribute units,OceFrac,c,c,"[0,1]" ${ATM}_grid_maskFrom_${OCE}.nc
+    ncatted  --history --attribute long_name,OceMask,c,c,"fraction of ocean in a grid cell" ${ATM}_grid_maskFrom_${OCE}.nc
+    ncatted  --history --attribute units,OceMask,c,c,"[0,1]" ${ATM}_grid_maskFrom_${OCE}.nc
+    ncatted  --history --attribute long_name,Oce2AtmMask,c,c,"land mask" ${ATM}_grid_maskFrom_${OCE}.nc
+    ncatted  --history --attribute units,Oce2AtmMask,c,c,"Land:0, Ocean:1" ${ATM}_grid_maskFrom_${OCE}.nc
  
 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
-
-##
-
-#cp ${ATM}_grid.nc ${ATM}_gridFromOce.nc
 
 
@@ -470,5 +461,5 @@
 	cp iodef_oce_to_atm.xml iodef.xml
 	
-	python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]'   -k name -v mask_${DSTGRID} 
+	python3 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_${DSTGRID} 
 	python3 update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]'   -k name -v Oce2AtmMask
 	
