Index: /trunk/libIGCM/AA_pack_output
===================================================================
--- /trunk/libIGCM/AA_pack_output	(revision 583)
+++ /trunk/libIGCM/AA_pack_output	(revision 583)
@@ -0,0 +1,321 @@
+#-Q- cesium #!/bin/ksh
+#-Q- cesium ######################
+#-Q- cesium ## CESIUM   CEA ##
+#-Q- cesium ######################
+#-Q- cesium #MSUB -r PACKOUTPUT    # Nom du job                
+#-Q- cesium #MSUB -N 1              # Reservation du noeud
+#-Q- cesium #MSUB -n 1              # Reservation du processus
+#-Q- cesium #MSUB -T 86400          # Limite de temps elapsed du job
+#-Q- cesium #MSUB -E "-j o"
+#-Q- cesium #MSUB -E "-S /bin/ksh"
+#-Q- platine #!/usr/bin/ksh
+#-Q- platine ###################
+#-Q- platine ## PLATINE   CEA ##
+#-Q- platine ###################
+#-Q- platine #BSUB -J PACKOUTPUT            # Nom du job
+#-Q- platine #BSUB -N                        # message a la fin du job
+#-Q- platine #BSUB -n 1                      # reservation des processeurs pour le job
+#-Q- platine #BSUB -W 4:00                   # Limite temps
+#-Q- platine #BSUB -q post                   # Passage en queue post
+#-Q- platine #BSUB -L /bin/ksh
+#-Q- sx8brodie #!/bin/ksh
+#-Q- sx8brodie #######################
+#-Q- sx8brodie ## SX8BRODIE   IDRIS ##
+#-Q- sx8brodie #######################
+#-Q- sx8brodie # Temps Elapsed max. d'une requete hh:mm:ss
+#-Q- sx8brodie # @ wall_clock_limit = 10:00:00
+#-Q- sx8brodie # Nom du travail LoadLeveler
+#-Q- sx8brodie # @ job_name   = PACKOUTPUT
+#-Q- sx8brodie # Fichier de sortie standard du travail       
+#-Q- sx8brodie # @ output     = $(job_name).$(jobid)
+#-Q- sx8brodie # Fichier de sortie d'erreur du travail
+#-Q- sx8brodie # @ error      =  $(job_name).$(jobid)
+#-Q- sx8brodie # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
+#-Q- sx8brodie # @ notification = error
+#-Q- sx8brodie # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $DateBegin ; $DateEnd ; $PeriodPack ; $StandAlone ; $MASTER
+#-Q- sx8brodie # @ queue
+#-Q- aix6 #!/bin/ksh
+#-Q- aix6 #######################
+#-Q- aix6 ##   VARGAS   IDRIS  ##
+#-Q- aix6 #######################
+#-Q- aix6 # Temps Elapsed max. d'une requete hh:mm:ss
+#-Q- aix6 # @ wall_clock_limit = 10:00:00
+#-Q- aix6 # Nom du travail LoadLeveler
+#-Q- aix6 # @ job_name   = PACKOUTPUT
+#-Q- aix6 # Fichier de sortie standard du travail
+#-Q- aix6 # @ output     = $(job_name).$(jobid)
+#-Q- aix6 # Fichier de sortie d'erreur du travail
+#-Q- aix6 # @ error      =  $(job_name).$(jobid)
+#-Q- aix6 # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
+#-Q- aix6 # @ notification = error
+#-Q- aix6 # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $DateBegin ; $DateEnd ; $PeriodPack ; $StandAlone ; $MASTER
+#-Q- aix6 # @ queue
+#-Q- ulam #!/bin/ksh
+#-Q- ulam #######################
+#-Q- ulam ##   VARGAS   IDRIS  ##
+#-Q- ulam #######################
+#-Q- ulam # Temps Elapsed max. d'une requete hh:mm:ss
+#-Q- ulam # @ wall_clock_limit = 10:00:00
+#-Q- ulam # Nom du travail LoadLeveler
+#-Q- ulam # @ job_name   = PACKOUTPUT
+#-Q- ulam # Fichier de sortie standard du travail
+#-Q- ulam # @ output     = $(job_name).$(jobid)
+#-Q- ulam # Fichier de sortie d'erreur du travail
+#-Q- ulam # @ error      =  $(job_name).$(jobid)
+#-Q- ulam # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
+#-Q- ulam # @ notification = error
+#-Q- ulam # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $DateBegin ; $DateEnd ; $PeriodPack ; $StandAlone ; $MASTER
+#-Q- ulam # @ queue
+#-Q- sx8mercure #!/bin/ksh
+#-Q- sx8mercure ######################
+#-Q- sx8mercure ## SX8MERCURE   CEA ##
+#-Q- sx8mercure ######################
+#-Q- sx8mercure #PBS -N PACKOUTPUT          # Nom du job
+#-Q- sx8mercure #PBS -j o                    # regroupement des stdout et stderr
+#-Q- sx8mercure #PBS -S /usr/bin/ksh         # shell de soumission
+#-Q- sx8mercure #PBS -l memsz_job=1gb        # Limite memoire a 1 Go
+#-Q- sx8mercure #PBS -l cputim_job=24:00:00  # Limite temps a 1 heures
+#-Q- sx8mercure #PBS -q scalaire
+#-Q- sx9mercure #!/bin/ksh
+#-Q- sx9mercure ######################
+#-Q- sx9mercure ## CESIUM   CEA ##
+#-Q- sx9mercure ######################
+#-Q- sx9mercure #MSUB -r PACKOUTPUT    # Nom du job                
+#-Q- sx9mercure #MSUB -N 1              # Reservation du noeud
+#-Q- sx9mercure #MSUB -n 1              # Reservation du processus
+#-Q- sx9mercure #MSUB -T 86400          # Limite de temps elapsed du job
+#-Q- sx9mercure #MSUB -E "-j o"
+#-Q- sx9mercure #MSUB -E "-S /bin/ksh"
+#-Q- titane #!/bin/ksh
+#-Q- titane ######################
+#-Q- titane ## TITANE   CEA     ##
+#-Q- titane ######################
+#-Q- titane #MSUB -r PACKOUTPUT    # Nom du job                
+#-Q- titane #MSUB -eo
+#-Q- titane #MSUB -n 1              # Reservation du processus
+#-Q- titane #MSUB -T 86400          # Limite de temps elapsed du job
+#-Q- titane #MSUB -q mono
+#-Q- lxiv8 ######################
+#-Q- lxiv8 ## OBELIX      LSCE ##
+#-Q- lxiv8 ######################
+#-Q- lxiv8 #PBS -N PACKOUTPUT
+#-Q- lxiv8 #PBS -m a
+#-Q- lxiv8 #PBS -j oe
+#-Q- lxiv8 #PBS -q medium
+#-Q- lxiv8 #PBS -o PACKOUTPUT.$$
+#-Q- lxiv8 #PBS -S /bin/ksh
+#-Q- default #!/bin/ksh
+#-Q- default ##################
+#-Q- default ## DEFAULT HOST ##
+#-Q- default ##################
+
+#**************************************************************
+# Author: Sebastien Denvil
+# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
+# $Revision::                                          $ Revision of last commit
+# $Author::                                            $ Author of last commit
+# $Date::                                              $ Date of last commit
+# IPSL (2006)
+#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
+#
+#**************************************************************
+
+#set -eu
+#set -vx
+
+date
+
+########################################################################
+
+#D- Flag to determine if this job in a standalone mode
+#D- Default : value from AA_job if any
+StandAlone=${StandAlone:=true}
+
+#D- Path to libIGCM
+#D- Default : value from AA_job if any
+# WARNING For StandAlone use : To run this script on some machine (ulam and cesium)
+# WARNING you must check MirrorlibIGCM variable in sys library.
+# WARNING If this variable is true, you must use libIGCM_POST path instead
+# WARNING of your running libIGCM directory.
+libIGCM=${libIGCM:=::modipsl::/libIGCM}
+
+#-D- $hostname of the MASTER job when SUBMIT_DIR is not visible on postprocessing computer.
+MASTER=${MASTER:=mercure|titane|brodie|vargas}
+
+#D- Flag to determine begin date for restart pack
+#D- Default : value from AA_job if any
+DateBegin=${DateBegin:=20000101}
+
+#D- Flag to determine end date for restart pack
+#D- Default : value from AA_job if any
+DateEnd=${DateEnd:=20691231}
+
+#D- Flag to determine pack period
+#D- Default : value from AA_job if any
+PeriodPack=${PeriodPack:=10Y}
+
+#D- Uncomment to run interactively
+#D- For testing purpose, will be remove
+#SUBMIT_DIR=${PWD}
+#RUN_DIR_PATH=${SCRATCHDIR}/Pack_Test
+
+#D- Increased verbosity (1, 2, 3)
+#D- Default : value from AA_job if any
+Verbosity=${Verbosity:=3}
+
+#D- Low level debug : to bypass lib test checks and stack construction
+#D- Default : value from AA_job if any
+DEBUG_debug=${DEBUG_debug:=false}
+
+########################################################################
+
+. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
+( ${DEBUG_debug} ) && IGCM_debug_Check
+. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
+( ${DEBUG_debug} ) && IGCM_card_Check
+. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
+( ${DEBUG_debug} ) && IGCM_date_Check
+#-------
+. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
+. ${libIGCM}/libIGCM_post/libIGCM_post.ksh
+
+########################################################################
+
+#set -vx
+
+RUN_DIR=${RUN_DIR_PATH}
+IGCM_sys_MkdirWork ${RUN_DIR}
+IGCM_sys_Cd ${RUN_DIR}
+
+# ------------------------------------------------------------------
+# Test if all was right before proceeding further
+# ------------------------------------------------------------------
+IGCM_debug_Verif_Exit_Post
+
+if [ ${StandAlone} = true ] ; then
+    CARD_DIR=${SUBMIT_DIR}
+else
+    CARD_DIR=${RUN_DIR_PATH}/$( basename ${SUBMIT_DIR} )
+    IGCM_sys_Get_Master ${SUBMIT_DIR} ${RUN_DIR_PATH}
+fi
+
+#
+# First of all
+#
+#### 0- lecture de config.card 
+#### on veut les renseignements suivants : 
+#### JobName, PATH_SIMUL, DateBegin et DateEnd
+
+IGCM_card_DefineArrayFromSection     ${CARD_DIR}/config.card UserChoices
+typeset option
+for option in ${config_UserChoices[*]} ; do
+  IGCM_card_DefineVariableFromOption ${CARD_DIR}/config.card UserChoices ${option}
+done
+#
+echo
+IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
+IGCM_debug_PrintVariables 3 config_UserChoices_JobName
+IGCM_debug_PrintVariables 3 config_UserChoices_LongName
+IGCM_debug_PrintVariables 3 config_UserChoices_TagName
+IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName
+IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName
+IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
+IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
+IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
+IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
+echo
+
+# Get ListOfComponents to drive the loop over find
+IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents
+
+#====================================================
+#R_SAVE : Job output storage directory
+#R_BUFR : Job output buffered directory
+
+if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
+  FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
+  R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
+  R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
+else
+  R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
+  R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
+fi
+IGCM_sys_TestDirArchive ${R_SAVE}
+[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
+
+# Where to store used file list /!\ TEMPORARY /!\
+STORE_DEBUG=${R_SAVE}/DEBUG
+
+# Switch to script variables meaning (try to be compatible with ipsl_pack TGCC moving procedure)
+JobName=${config_UserChoices_JobName}
+PATH_SIMUL=${R_BUFR}
+echo $JobName $PATH_SIMUL $DateBegin $DateEnd
+
+# ------------------------------------------------------------------
+# Test if all was right before proceeding further
+# ------------------------------------------------------------------
+IGCM_debug_Verif_Exit_Post
+
+# Init loop
+date_begin_pack=${DateBegin}
+date_end_simulation=${DateEnd}
+number_pack=1
+
+IGCM_debug_PrintVariables 3 date_begin_pack
+IGCM_debug_PrintVariables 3 date_end_simulation
+
+while [ ${date_begin_pack} -le ${date_end_simulation} ] ; do
+
+  IGCM_debug_PrintVariables 3 number_pack
+  DaysTemp=$( IGCM_date_DaysInNextPeriod ${date_begin_pack} ${PeriodPack} )
+  date_end_pack=$( IGCM_date_AddDaysToGregorianDate ${date_begin_pack} $(( ${DaysTemp} - 1 )) )
+
+  for comp in ${config_ListOfComponents[*]} ; do
+    dirList=$( find ${BUFR}/${comp}/ -maxdepth 1 -mindepth 1 -type d )
+    for dir in ${dirlist} ; do
+      # dirID is like ATM.Output.MO
+      dirID=$( echo $dir | sed "s:${R_BUFR}/::" | sed "s:/:.:g" )
+      # Sort what's in the directory
+      find ${dir} -type f -name "${JobName}*.nc" -ls | sort -k 11 > liste_files.${dirID}.txt
+      # How much file type. Example : 1M_histmthCOSP.nc, 1M_histmth.nc, 1M_histmthNMC.nc, 1M_paramLMDZ_phy.nc
+      # /!\ fileType include the .nc extension /!\
+      fileType=$( gawk '{print $11}' liste_files.${dirID}.txt | gawk -F$dir/ '{print $2}' | sed "s:${JobName}_[0-9]\{8,9\}_[0-9]\{8,9\}_::g" | sort | uniq )
+      # Loop over the file type and pack them when in between date_begin_pack and date_end_pack
+      for myType in ${fileType} ; do
+	grep ${myType} liste_files.${dirID}.txt > liste_files.${dirID}.${myType}.txt
+	for file in $( gawk '{print $11}' liste_files.${dirID}.${myType}.txt ); do
+	  extract_date_file=$( echo ${file}  | sed -e "s/.*${JobName}_[0-9]*_//" )
+	  date_file=$( echo ${extract_date_file} | sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
+	  # echo pack nÂ°${number_pack}  ${date_file} ${date_begin_pack} ${date_end_pack} 
+	  if [ ${date_file} -le ${date_end_pack} ] && [ ${date_file} -ge ${date_begin_pack} ] ; then 
+            echo ${file} >> liste_pack_${myType}_${number_pack}.txt
+	  fi
+	done
+	# Create packed files
+	IGCM_debug_Print 1 "Ncrcat ongoing for ${dir} and ${myType}"
+	output=${JobName}_${date_begin_pack}_${date_end_pack}_${myType}
+	cat liste_pack_${myType}_${number_pack}.txt | xargs IGCM_sys_ncrcat -o ${output}
+	# ------------------------------------------------------------------
+        # Test if all was right before proceeding further
+        # ------------------------------------------------------------------
+	IGCM_debug_Verif_Exit_Post
+        # Save it
+	IGCM_sys_Put_Out ${output} ${R_SAVE}/${dir}
+	# ------------------------------------------------------------------
+        # Test if all was right before proceeding further
+        # ------------------------------------------------------------------
+	IGCM_debug_Verif_Exit_Post
+        # Clean file produced by ncrcat
+	IGCM_sys_Rm ${output}
+        # Clean files used by ncrcat
+	cat liste_pack_${myType}_${number_pack}.txt | xargs rm
+        # Save the list of files that has been pack (ncrcat)
+	mv liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ${STORE_DEBUG}
+	IGCM_debug_Print 1 "Ncrcat and cleaning done for ${dir} and ${myType}"
+      done
+    done
+  done
+  (( number_pack = number_pack + 1 ))
+  # Add 1 day to date_end_pack to have the new date_begin_pack
+  date_begin_pack=$( IGCM_date_AddDaysToGregorianDate ${date_end_pack} 1 )
+done
Index: /trunk/libIGCM/libIGCM_post/libIGCM_post.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_post/libIGCM_post.ksh	(revision 582)
+++ /trunk/libIGCM/libIGCM_post/libIGCM_post.ksh	(revision 583)
@@ -538,5 +538,29 @@
     IGCM_sys_QsubPost ${script}
 EOF
-
+    #
+    script=pack_output
+    #
+    Script_Post_Output=${script}.${PeriodDateEnd}
+    #
+    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 POST_DIR=${POST_DIR}
+    export MASTER=${MASTER}
+    export DateBegin=${PackDateBegin}
+    export DateEnd=${PeriodDateEnd}
+    export PeriodPack=${config_Post_PackFrequency}
+    export StandAlone=false
+    export listVarEnv=${listVarEnv}
+    export Script_Post_Output=${Script_Post_Output}
+    . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
+    . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
+    IGCM_sys_MkdirWork ${POST_DIR}
+    IGCM_debug_Verif_Exit_Post
+    #IGCM_sys_QsubPost ${script}
+EOF
     export DateBegin=${SavedDateBegin}
     export DateEnd=${SavedDateEnd}
