Index: /trunk/libIGCM/libIGCM_post/IGCM_Patch_20091118_mask.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_post/IGCM_Patch_20091118_mask.ksh	(revision 201)
+++ /trunk/libIGCM/libIGCM_post/IGCM_Patch_20091118_mask.ksh	(revision 201)
@@ -0,0 +1,100 @@
+#!/bin/ksh
+
+#------------------------------------------------------------
+# Add mask from meshmask file to oceanic variables
+#------------------------------------------------------------
+
+function IGCM_Patch_20091118_mask {
+
+    set -vx
+    IGCM_debug_PushStack "IGCM_Patch_mask" $@
+
+    [ -f ${config_UserChoices_JobName}_mesh_mask.nc ] || IGCM_sys_Get ${R_SAVE}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc .
+
+    filename=${1}
+
+    chaineT=${filename%%'grid_T'*}
+    chaineU=${filename%%'grid_U'*}
+    chaineV=${filename%%'grid_V'*}
+    chaineW=${filename%%'grid_W'*}
+    chaineIce=${filename%%'icemod'*}
+
+    if [ ${filename} != ${chaineT} ]; then
+	mask='tmask' ; depth='deptht'
+    elif [ ${filename} != ${chaineU} ]; then
+	mask='umask' ; depth='depthu'
+    elif [ ${filename} != ${chaineV} ]; then
+	mask='vmask' ; depth='depthv'
+    elif [ ${filename} != ${chaineW} ]; then
+	mask='tmask' ; depth='depthw'
+    elif [ ${filename} != ${chaineIce} ]; then
+	mask='tmask' ; depth='deptht'
+    fi
+
+#============================================
+# Remove nav_lon, nav_lat file
+    IGCM_sys_ncks -Oh -x -v nav_lon,nav_lat ${filename} file1.nc
+
+#============================================
+# Extract mask variable
+    IGCM_sys_ncks -Oh -v ${mask} ${config_UserChoices_JobName}_mesh_mask.nc mask3D.nc
+
+#============================================
+# Rename deptht dimension
+    IGCM_sys_ncrename -Oh -d z,${depth} mask3D.nc
+
+#============================================
+# Remove single dimension t
+    IGCM_sys_ncwa -Oh -a t mask3D.nc mask3D.nc
+
+#============================================
+# Create mask2D 
+    IGCM_sys_ncks -Oh -d ${depth},0,0 mask3D.nc mask2D.nc
+    IGCM_sys_ncwa -Oh -a ${depth} mask2D.nc mask2D.nc
+    IGCM_sys_ncrename -v ${mask},mask2D mask2D.nc
+
+#============================================
+# Append mask (2D) to file1.nc
+    IGCM_sys_ncks -Ah -c -v mask2D mask2D.nc file1.nc
+
+    if [ ${filename} = ${chaineIce} ]; then
+
+#============================================
+# Append mask (3D) only for oceanic files
+	IGCM_sys_ncks -Ah -v ${mask} mask3D.nc file1.nc
+	IGCM_sys_ncrename -v ${mask},mask3D file1.nc
+
+#============================================
+# Add record dimension only for oceanic files
+	IGCM_sys_ncecat -Oh file1.nc file1.nc
+
+#============================================
+# Apply mask 3D only for oceanic files
+	IGCM_sys_ncwa -Oh -a record -B 'mask3D==1' file1.nc file1.nc
+
+    fi
+
+#============================================
+# Add record dimension
+    IGCM_sys_ncecat -Oh file1.nc file1.nc
+
+#============================================
+# Apply mask 2D
+    IGCM_sys_ncwa -Oh -a record -B 'mask2D==1' file1.nc file1.nc
+
+#============================================
+# Remove mask
+    IGCM_sys_ncks -Oh -x -v mask2D,mask3D file1.nc file_mask.nc
+
+#============================================
+# Add nav_lon nav_lat
+    IGCM_sys_ncks -Ah -v nav_lon,nav_lat ${filename} file_mask.nc
+
+#============================================
+# Cleaning
+    IGCM_debug_Verif_Exit_Post
+    IGCM_sys_Mv file_mask.nc ${filename}
+    IGCM_sys_Rm mask3D.nc mask2D.nc file1.nc
+    
+    IGCM_debug_PopStack "IGCM_Patch_mask"
+}
Index: /trunk/libIGCM/libIGCM_post/libIGCM_post.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_post/libIGCM_post.ksh	(revision 200)
+++ /trunk/libIGCM/libIGCM_post/libIGCM_post.ksh	(revision 201)
@@ -389,5 +389,5 @@
 
         typeset listVarEnv
-        listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,MASTER,RebuildFrequency,DateBegin,PeriodDateEnd,StandAlone,CompletedFlag,TsTask,CompToRead,FlagToRead,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_BIOS"
+        listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,MASTER,RebuildFrequency,DateBegin,PeriodDateEnd,StandAlone,CompletedFlag,TsTask,CompToRead,FlagToRead,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_BIOS,config_UserChoices_JobName,R_SAVE"
 	#
 	jLoop=${#ListDimension[*]}
@@ -424,4 +424,6 @@
 		    echo export RESOL_SRF=${RESOL_SRF}                >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
 		    echo export RESOL_BIOS=${RESOL_BIOS}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
+		    echo export config_UserChoices_JobName=${config_UserChoices_JobName}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
+		    echo export R_SAVE=${R_SAVE}                      >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
 		    echo export listVarEnv=${listVarEnv}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
 		    echo IGCM_sys_MkdirWork ${POST_DIR}               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
@@ -451,4 +453,6 @@
                     export RESOL_SRF=${RESOL_SRF}
                     export RESOL_BIOS=${RESOL_BIOS}
+                    export config_UserChoices_JobName=${config_UserChoices_JobName}
+                    export R_SAVE=${R_SAVE}
                     export listVarEnv=${listVarEnv}
                     . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
@@ -514,4 +518,6 @@
 			echo export RESOL_SRF=${RESOL_SRF}                >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
 			echo export RESOL_BIOS=${RESOL_BIOS}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
+			echo export config_UserChoices_JobName=${config_UserChoices_JobName}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
+			echo export R_SAVE=${R_SAVE}                      >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
 			echo export listVarEnv=${listVarEnv}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
 			echo IGCM_sys_MkdirWork ${POST_DIR}               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
@@ -543,4 +549,6 @@
                         export RESOL_SRF=${RESOL_SRF}
                         export RESOL_BIOS=${RESOL_BIOS}
+                        export config_UserChoices_JobName=${config_UserChoices_JobName}
+                        export R_SAVE=${R_SAVE}
                         export listVarEnv=${listVarEnv}
                         . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
@@ -571,5 +579,5 @@
         #
         typeset listVarEnv
-	listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,MASTER,RebuildFrequency,DateBegin,PeriodDateEnd,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_BIOS"
+	listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,MASTER,RebuildFrequency,DateBegin,PeriodDateEnd,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_BIOS,config_UserChoices_JobName,R_SAVE"
 
 	if [ ${RebuildFrequency} = true ] ; then
@@ -592,4 +600,6 @@
             echo export RESOL_SRF=${RESOL_SRF}                >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
             echo export RESOL_BIOS=${RESOL_BIOS}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
+	    echo export config_UserChoices_JobName=${config_UserChoices_JobName}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
+	    echo export R_SAVE=${R_SAVE}                      >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
             echo export listVarEnv=${listVarEnv}              >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
 	    echo IGCM_sys_MkdirWork ${POST_DIR}               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
@@ -617,4 +627,6 @@
             export RESOL_SRF=${RESOL_SRF}
             export RESOL_BIOS=${RESOL_BIOS}
+            export config_UserChoices_JobName=${config_UserChoices_JobName}
+            export R_SAVE=${R_SAVE}
             export listVarEnv=${listVarEnv}
             . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
@@ -650,5 +662,5 @@
             #
             typeset listVarEnv
-            listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,POST_DIR,MASTER,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_BIOS"
+            listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,POST_DIR,MASTER,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_BIOS,config_UserChoices_JobName,R_SAVE"
             IGCM_sys_RshPost <<-EOF
             export DEBUG_debug=${DEBUG_debug}
@@ -671,4 +683,6 @@
             export RESOL_SRF=${RESOL_SRF}
             export RESOL_BIOS=${RESOL_BIOS}
+            export config_UserChoices_JobName=${config_UserChoices_JobName}
+            export R_SAVE=${R_SAVE}
             export listVarEnv=${listVarEnv}
             . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
@@ -684,5 +698,5 @@
 	    #
             typeset listVarEnv
-            listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,POST_DIR,MASTER,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_BIOS"
+            listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,POST_DIR,MASTER,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_BIOS,config_UserChoices_JobName,R_SAVE"
 	    IGCM_sys_RshPost <<-EOF
             export DEBUG_debug=${DEBUG_debug}
@@ -705,4 +719,6 @@
             export RESOL_SRF=${RESOL_SRF}
             export RESOL_BIOS=${RESOL_BIOS}
+            export config_UserChoices_JobName=${config_UserChoices_JobName}
+            export R_SAVE=${R_SAVE}
             export listVarEnv=${listVarEnv}
             . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
