Index: trunk/libIGCM/libIGCM_post/libIGCM_post.ksh
===================================================================
--- trunk/libIGCM/libIGCM_post/libIGCM_post.ksh	(revision 152)
+++ trunk/libIGCM/libIGCM_post/libIGCM_post.ksh	(revision 157)
@@ -563,5 +563,4 @@
 	done
     fi
-
     set +vx
 
@@ -627,7 +626,15 @@
 
     #============== REBUILD POST-TREATMENT =============#
-
-    if ( [ ${config_Post_RebuildFromArchive} = true ] && [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
-	IGCM_sys_Put_Dir REBUILD_${PeriodDateBegin} ${REBUILD_DIR}
+    if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
+	# -----------------------------------------------------------------------------------
+        # Function IGCM_FlushRebuild define in rebuild.ksh has not been closed yet. Do it now
+        # -----------------------------------------------------------------------------------
+	echo IGCM_debug_PopStack "IGCM_FlushRebuild" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
+	echo }                                       >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
+	if [ ${config_Post_RebuildFromArchive} = true ] ; then
+	    IGCM_sys_Put_Dir REBUILD_${PeriodDateBegin} ${REBUILD_DIR}
+	else
+	    IGCM_sys_Mv      REBUILD_${PeriodDateBegin} ${REBUILD_DIR}
+	fi
     fi
     #
@@ -635,70 +642,65 @@
 	#
         if ( [ ${config_Post_RebuildFromArchive} = true ] ) ; then
-        #
-        IGCM_debug_Print 2 "REBUILD POST-TREATMENT FROM ARCHIVE:"
-        echo
-        #
-        typeset listVarEnv
-        listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,RebuildFromArchive,POST_DIR,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
-        IGCM_sys_RshPost <<-EOF
-        export DEBUG_debug=${DEBUG_debug}
-        export MODIPSL=${MODIPSL}
-	export libIGCM_SX=${libIGCM}
-        export libIGCM=${libIGCM_POST}
-        export SUBMIT_DIR=${SUBMIT_DIR}
-        export RebuildFromArchive=${config_Post_RebuildFromArchive}
-        export REBUILD_DIR=${REBUILD_DIR}
-        export POST_DIR=${POST_DIR}
-        export DateBegin=${DateBegin}
-        export PeriodDateBegin=${PeriodDateBegin}
-        export PeriodDateEnd=${PeriodDateEnd}
-        export NbRebuildDir=${NbRebuildDir}
-        export StandAlone=false
-        export RESOL_ATM=${RESOL_ATM}
-        export RESOL_OCE=${RESOL_OCE}
-        export RESOL_ICE=${RESOL_ICE}
-        export RESOL_SRF=${RESOL_SRF}
-        export listVarEnv=${listVarEnv}
-        . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
-        . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
-        IGCM_sys_MkdirWork ${POST_DIR}
-        IGCM_debug_Verif_Exit
-        IGCM_sys_QsubPost rebuild_fromArchive
+            #
+            IGCM_debug_Print 2 "REBUILD POST-TREATMENT FROM ARCHIVE:"
+            echo
+            #
+            typeset listVarEnv
+            listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,POST_DIR,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
+            IGCM_sys_RshPost <<-EOF
+            export DEBUG_debug=${DEBUG_debug}
+            export MODIPSL=${MODIPSL}
+	    export libIGCM_SX=${libIGCM}
+            export libIGCM=${libIGCM_POST}
+            export SUBMIT_DIR=${SUBMIT_DIR}
+            export REBUILD_DIR=${REBUILD_DIR}
+            export POST_DIR=${POST_DIR}
+            export DateBegin=${DateBegin}
+            export PeriodDateBegin=${PeriodDateBegin}
+            export PeriodDateEnd=${PeriodDateEnd}
+            export NbRebuildDir=${NbRebuildDir}
+            export StandAlone=false
+            export RESOL_ATM=${RESOL_ATM}
+            export RESOL_OCE=${RESOL_OCE}
+            export RESOL_ICE=${RESOL_ICE}
+            export RESOL_SRF=${RESOL_SRF}
+            export listVarEnv=${listVarEnv}
+            . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
+            . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
+            IGCM_sys_MkdirWork ${POST_DIR}
+            IGCM_debug_Verif_Exit
+            IGCM_sys_QsubPost rebuild_fromArchive
 EOF
-
-        else 
-        #
-        IGCM_debug_Print 2 "REBUILD POST-TREATMENT FROM WORKDIR :"
-	echo
-	IGCM_debug_Print 2 "NOT FULLY SUPPORTED"
-	IGCM_debug_Print 2 "EXIT NOW TO AVOID BIG PROBLEM"
-	IGCM_debug_Print 2 "Contact libIGCM developpers"
-	#
-	IGCM_debug_Exit "FATAL ERROR IN REBUILD CONFIGURATION"
-	IGCM_debug_Verif_Exit 
-        #
-
-#        typeset listVarEnv
-#        listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,RebuildFromArchive,POST_DIR,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
-#        export DEBUG_debug=${DEBUG_debug}
-#        export MODIPSL=${MODIPSL}
-#        export libIGCM_SX=${libIGCM}
-#        export libIGCM=${libIGCM}
-#        export SUBMIT_DIR=${SUBMIT_DIR}
-#        export RebuildFromArchive=${config_Post_RebuildFromArchive}
-#        export REBUILD_DIR=${REBUILD_DIR}
-#        export POST_DIR=${libIGCM}
-#        export DateBegin=${DateBegin}
-#        export PeriodDateBegin=${PeriodDateBegin}
-#        export PeriodDateEnd=${PeriodDateEnd}
-#        export NbRebuildDir=${NbRebuildDir}
-#        export StandAlone=false
-#        export RESOL_ATM=${RESOL_ATM}
-#        export RESOL_OCE=${RESOL_OCE}
-#        export RESOL_ICE=${RESOL_ICE}
-#        export RESOL_SRF=${RESOL_SRF}
-#        export listVarEnv=${listVarEnv}
-#        IGCM_sys_Qsub rebuild_fromWorkdir ${libIGCM}
-
+        else
+            #
+            IGCM_debug_Print 2 "REBUILD POST-TREATMENT FROM WORKDIR:"
+	    echo
+	    #
+            typeset listVarEnv
+            listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,POST_DIR,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
+	    IGCM_sys_RshPost <<-EOF
+            export DEBUG_debug=${DEBUG_debug}
+            export MODIPSL=${MODIPSL}
+            export libIGCM_SX=${libIGCM}
+            export libIGCM=${libIGCM}
+            export SUBMIT_DIR=${SUBMIT_DIR}
+            export REBUILD_DIR=${REBUILD_DIR}
+            export POST_DIR=${libIGCM}
+            export DateBegin=${DateBegin}
+            export PeriodDateBegin=${PeriodDateBegin}
+            export PeriodDateEnd=${PeriodDateEnd}
+            export NbRebuildDir=${NbRebuildDir}
+            export StandAlone=false
+            export RESOL_ATM=${RESOL_ATM}
+            export RESOL_OCE=${RESOL_OCE}
+            export RESOL_ICE=${RESOL_ICE}
+            export RESOL_SRF=${RESOL_SRF}
+            export listVarEnv=${listVarEnv}
+            . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
+            . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
+            IGCM_sys_MkdirWork ${POST_DIR}
+            IGCM_debug_Verif_Exit
+            IGCM_sys_QsubPost rebuild_fromWorkdir
+EOF
         fi
     fi
