Index: TOOLS/PACK_IPSL/DEM_utilities.sh
===================================================================
--- TOOLS/PACK_IPSL/DEM_utilities.sh	(revision 1709)
+++ TOOLS/PACK_IPSL/DEM_utilities.sh	(revision 1709)
@@ -0,0 +1,102 @@
+#!/bin/bash
+
+#
+# Fonctions utiles pour les scripts de Pack IPSL
+#
+
+function DEM_read_state {
+# Lire l'Ã©tat du pack pour une simulation
+    local L_CONFIG_FILE=${1}
+    local L_CONFIG_CARD=${2}
+
+    local L_OLD_STATE=$( grep ${L_CONFIG_CARD} ${L_CONFIG_FILE} | awk '{print $2}' )
+    
+    if [ ${?} -eq 0 ] 
+    then 
+	echo ${L_OLD_STATE}
+	return 0
+    else
+	return 1
+    fi
+    return 0
+}
+
+function DEM_write_state {
+# Mettre Ã  jour l'Ã©tat du pack pour une simulation
+    
+    local L_CONFIG_FILE=${1}
+    local L_CONFIG_CARD=${2}
+    local L_NEW_STATE=${3}
+    
+    local L_OLD_LINE=$( grep ${L_CONFIG_CARD} ${L_CONFIG_FILE} )
+    [[ ${?} -eq 0 ]] || ( return 1 ; )
+    local L_OLD_STATE=$( echo ${L_OLD_LINE} | awk '{print $2}' )
+    [[ ${?} -eq 0 ]] || ( return 1 ; )
+    
+    L_NEW_LINE="${L_CONFIG_CARD} ${L_NEW_STATE}"
+
+    if [[ ! -f ${L_CONFIG_FILE}.lock ]]
+    then 
+	touch ${L_CONFIG_FILE}.lock
+	sed -i "s%${L_OLD_LINE}%${L_NEW_LINE}%" ${L_CONFIG_FILE}
+	rm -f ${L_CONFIG_FILE}.lock
+    else
+	DEM_log -0 "Erreur. Verrou sur le fichier : ${L_CONFIG_FILE}"
+	return 1
+    fi
+    
+    return 0
+}
+
+function DEM_min {
+# Calcul du minimum d'un nombre quelconque d'entiers
+    local l_min=${1} l_xx
+  
+    for l_xx in ${*:2:${#}}
+    do
+	[[ ${l_xx} -lt ${l_min} ]] && l_min=${l_xx}
+    done
+    echo ${l_min}
+}
+
+function DEM_max {
+# Calcul du maximum d'un nombre quelconque d'entiers
+    local l_max=${1} l_xx
+  
+    for l_xx in ${*:2:${#}}
+    do
+	[[ ${l_xx} -gt ${l_max} ]] && l_max=${l_xx}
+    done
+    echo ${l_max}
+}
+
+function DEM_log {
+# Affichage d'un message sur stdout et dans un fichier de log
+# DEM_log [-0|-1|-2|-3] Message
+#
+    local MESSAGE P_LINE
+    LOG_LEV=${LOG_LEV:-3}
+    local OPTARG OPTIND L_LOG=1
+    local L_DEM_LOG=${DEM_LOG:-dem_log.${$}}
+
+    while getopts 0123 l_name
+    do
+	case ${l_name} in
+            ( 0 )  L_LOG=1 ;;
+            ( 1 )  L_LOG=1 ;;
+            ( 2 )  L_LOG=2 ;;
+	    ( 3 )  L_LOG=3 ;;
+	esac
+    done
+    shift $(( ${OPTIND} - 1 ))
+
+    if [[ ${L_LOG} -le ${LOG_LEV} ]]
+    then 
+	MESSAGE=${*}
+	P_LINE="$(date) - ${MESSAGE}"
+	
+	echo ${P_LINE}
+	echo ${P_LINE} >> ${L_DEM_LOG}
+    fi
+    return
+}
Index: TOOLS/PACK_IPSL/archive_restart.sh
===================================================================
--- TOOLS/PACK_IPSL/archive_restart.sh	(revision 1709)
+++ TOOLS/PACK_IPSL/archive_restart.sh	(revision 1709)
@@ -0,0 +1,175 @@
+#!/bin/bash
+
+
+#on veut archiver les fichiers restart
+#Dans le cadre du demenagement ils seront renommes
+#ATM/Restart/****.nc
+#OCE/Restart/****.nc
+#...
+#sous la forme
+#RESTART/ATM_****.nc
+#RESTART/OCE_****.nc
+#Attention de bien conserver les dates d'origines 
+#
+#Dans le cadre de la production nouvelle chaine
+#ils auront directement le bon nom
+#
+#On veut egalement que l'archive soit par periode de temps 
+# cette periode est definie par la taille du pack donc connue 
+# en entree du script (1M, 1Y, 5Y, 10Y etc...) 
+#
+
+
+# $1= PATH/config_card d'une simulation avec 
+# TagName/JobName/ExperimentName/SpaceName/DateBegin/DateEnd/PATH_SIMUL
+# $2=period_pack en M/m ou Y/y
+
+config_card=${1}
+LISTE_DMNFS=${2}
+
+
+export JOB_DIR=${JOB_DIR:-${PWD}}
+export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
+export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
+mkdir -p ${IGCM_DEM}
+mkdir -p ${IGCM_TMP}
+clean_tmp=${clean_tmp:-yes}
+EXE_DIR=$(dirname ${0})
+SCRIPT_NAME=$(basename ${0} )
+
+source ${EXE_DIR}/DEM_utilities.sh
+
+DEM_log -0 "Demarrage de ${SCRIPT_NAME}"
+
+
+#### 0- lecture de config.card 
+#### on veut les renseignements suivants : 
+#### JobName, PATH_SIMUL, DateBegin et DateEnd
+eval $(grep JobName ${config_card}) 
+eval $(grep PATH_SIMUL_FULL ${config_card}) 
+eval $(grep DateBegin ${config_card}) 
+eval $(grep DateEnd ${config_card}) 
+eval $(grep IGCM_DEM_SIMU ${config_card})
+
+
+#### Preparation de l'environnement
+# repertoire dans lequel seront crees les archives
+STORE_RESTART=$IGCM_DEM_SIMU/Restart
+mkdir -p ${STORE_RESTART}
+
+# lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt
+period_pack=`awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt`
+
+#### 1- renommer les fichiers ######
+DEM_log -1 "Renommer les fichiers de Restart"
+
+cd ${STORE_RESTART}
+rm -rf *
+
+# On les copie sur le scratchdir en changeant le nom et conservant la date
+grep ${PATH_SIMUL_FULL} ${LISTE_DMNFS} | grep Restart | awk '{print $3}' | sed '/^.*Restart$/d' >> ${IGCM_DEM_SIMU}/liste_restart_files.txt
+
+
+#awk -F/ '{dest_name=$(NF-2)("_") $(NF);
+#   system("cp --preserve " $0 " "dest_name)}' ${IGCM_DEM_SIMU}/liste_restart_files.txt
+  
+gawk -F/ '{dest_name=$(NF-2)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_DEM_SIMU}/liste_restart_files.txt
+
+ls -l ${STORE_RESTART} > ${IGCM_DEM_SIMU}/new_liste_restart_files.txt
+
+### 2- creer les listes de fichiers par periode ####
+DEM_log -1 "Creation des listes de fichiers par periode"
+### 2.1- extraire l'annee et le mois de DateBegin ###
+date_begin=${DateBegin}
+date_end=${DateEnd}
+
+year_begin=$(echo ${date_begin} | cut -c 1-4 )
+month_begin=$(echo ${date_begin} | cut -c 5-6 )
+year_end=$(echo ${date_end} | cut -c 1-4 )
+month_end=$(echo ${date_end} | cut -c 5-6 )
+
+
+### 2.2- creation des listes ###
+date_begin_pack=${date_begin}
+date_end_simulation=${date_end}
+
+month_begin_pack=${month_begin}
+year_begin_pack=${year_begin}
+
+number_pack=1
+
+while [ ${date_begin_pack} -le ${date_end_simulation} ]
+do 
+
+DEM_log -1 "On calcule la date de fin du pack "
+
+   month_end_pack=${month_begin_pack}
+   year_end_pack=`expr ${year_begin_pack} + ${period_pack}`
+
+   if [ ${month_end_pack} -le 9 ] 
+   then 
+      date_end_pack=${year_end_pack}0${month_end_pack}01
+   fi 
+   if [ ${month_end_pack} -gt 9 ] 
+   then 
+      date_end_pack=${year_end_pack}${month_end_pack}01   
+   fi 
+
+  
+   for file in `awk '{print $9}' ${IGCM_DEM_SIMU}/new_liste_restart_files.txt`; do 
+   
+     extract_date_file=`echo ${file}  | sed -e "s/.*\${JobName}_//"`
+     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} -lt ${date_end_pack} ]
+     then 
+        if [ ${date_file} -ge ${date_begin_pack} ]
+        then 
+           echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt
+        fi
+     fi
+   
+   done
+
+#on archive les restart - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} 
+# end etant la date du dernier fichier contenu et non pas la premiere date suivant 
+DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive "
+#On classe par ordre alphabetique les fichiers contenus dans liste_pack_restart 
+#la date du dernier fichier donnera la date de fin du pack
+   sort ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt.tmp
+   last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt.tmp )
+   extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
+   echo ${extract_date_file}
+   DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
+   echo ${DateEnd_Restart}
+   mv ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt.tmp ${IGCM_DEM_SIMU}/liste_pack_restart_${date_begin_pack}_${DateEnd_Restart}.txt
+
+
+DEM_log -1 "Passage de la commande Tar pour archiver la liste creee"
+   tar -cf ${JobName}_${date_begin_pack}_${DateEnd_Restart}_restart.tar --dereference  --files-from ${IGCM_DEM_SIMU}/liste_pack_restart_${date_begin_pack}_${DateEnd_Restart}.txt
+#   cat  ${IGCM_DEM_SIMU}/liste_pack_restart_${number_pack}.txt | xargs rm 
+
+
+DEM_log -1 "On defini le datebegin de la  prochaine periode pack"
+#on defini la periode pack suivante
+   month_begin_pack=${month_end_pack}
+   year_begin_pack=${year_end_pack}
+
+   if [ ${month_begin_pack} -le 9 ]
+   then 
+      date_begin_pack=${year_begin_pack}0${month_begin_pack}01
+   fi 
+   if [ ${month_begin_pack} -gt 9 ]
+   then 
+      date_begin_pack=${year_begin_pack}${month_begin_pack}01
+   fi 
+
+
+   number_pack=`expr ${number_pack} + 1`
+
+done
+
+
+
Index: TOOLS/PACK_IPSL/calcul_size_simul.sh
===================================================================
--- TOOLS/PACK_IPSL/calcul_size_simul.sh	(revision 1709)
+++ TOOLS/PACK_IPSL/calcul_size_simul.sh	(revision 1709)
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+
+#### On veut calculer si l'ensemble des fichiers d'une simulation 
+#### est bien superieur a 1G
+
+config_card=${1}
+LISTE_DMNFS=${2}
+
+export JOB_DIR=${JOB_DIR:-${PWD}}
+export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
+export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
+mkdir -p ${IGCM_DEM}
+mkdir -p ${IGCM_TMP}
+
+eval $(grep JobName ${config_card}) 
+eval $(grep PATH_SIMUL_FULL ${config_card}) 
+eval $(grep DateBegin ${config_card}) 
+eval $(grep DateEnd ${config_card}) 
+eval $(grep IGCM_DEM_SIMU ${config_card})
+
+
+
+## 1 Go
+limitmin=1000000000
+
+#cree la liste de l'ensemble des fichiers de la simulation
+grep ${PATH_SIMUL_FULL} ${LISTE_DMNFS} | grep 'R ' > ${IGCM_TMP}/$$.info_tmp.txt 
+awk '{print $(NF-2) " " $(NF-1)}' ${IGCM_TMP}/$$.info_tmp.txt > ${IGCM_DEM_SIMU}/All_files_simul.txt
+
+size=`awk 'BEGIN {y = 0} {x = $1 ; y = y + x } END{print y}'  ${IGCM_DEM_SIMU}/All_files_simul.txt`
+echo $size
+if [  ${size} -lt ${limitmin} ]
+then
+
+    echo "trop petit on archive cette simulation avec tar"
+    PATH_SIMUL_SHORT=$(echo ${PATH_SIMUL_FULL} | sed 's%/[^/]*/[^/]*/[^/]*/%%' )
+    echo  ${PATH_SIMUL_FULL} > ${IGCM_DEM_SIMU}/tar_full_simul.txt
+
+
+fi
Index: TOOLS/PACK_IPSL/create_config_card.sh
===================================================================
--- TOOLS/PACK_IPSL/create_config_card.sh	(revision 1709)
+++ TOOLS/PACK_IPSL/create_config_card.sh	(revision 1709)
@@ -0,0 +1,158 @@
+#!/bin/bash
+
+##
+## Job permettant de recreer une partie du config.card d'une simulation
+## Champs vises : JobName / DateBegin / DateEnd / Calendar 
+##
+
+# Prend en argument un fichier contenant une liste de simulations
+# cree pour chacune son config.card
+# Ex : ./create_config_card.job liste_simul_fichier_param_test1.txt liste_fichier_dmnfs
+# Ex : ./create_config_card.job liste_simul_param_SL.txt /cscratch/cont003/labetoul/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2012-03-21
+
+
+LISTE_SIMUL=${1}
+LISTE_DMNFS=${2}
+
+# ----
+export JOB_DIR=${JOB_DIR:-${PWD}}
+export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
+export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
+mkdir -p ${IGCM_DEM}
+mkdir -p ${IGCM_TMP}
+clean_tmp=${clean_tmp:-yes}
+EXE_DIR=$(dirname ${0})
+SCRIPT_NAME=$(basename ${0} )
+source ${EXE_DIR}/DEM_utilities.sh
+DEM_log -0 "Demarrage de ${SCRIPT_NAME}"
+cd ${JOB_DIR}
+# ----
+
+DEM_log -0 "LISTE_SIMUL : ${LISTE_SIMUL}"
+DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}"
+
+[[ -f ${IGCM_DEM}/config_card.liste ]] && rm ${IGCM_DEM}/config_card.liste
+
+#ROOT_DIR=/dmnfs05/cont003/labetoul # soit DMFDIR, soit le tampon. a ameliorer ...
+
+
+cd ${JOB_DIR}
+
+for PATH_SIMUL_FULL in `awk  '{print $0}' ${LISTE_SIMUL}` ; do 
+
+    DEM_log -3 PATH_SIMUL_FULL : ${PATH_SIMUL_FULL}
+    #PATH_SIMUL_SHORT=${PATH_SIMUL_FULL##${ROOT_DIR}} # Enleve le debut du path
+    PATH_SIMUL_SHORT=$(echo ${PATH_SIMUL_FULL} | sed 's%/[^/]*/[^/]*/[^/]*/%%' )
+    DEM_log -3 PATH_SIMUL_SHORT : ${PATH_SIMUL_SHORT}
+    
+    IGCM_DEM_SIMU=${IGCM_DEM}/${PATH_SIMUL_SHORT}
+    mkdir -p ${IGCM_DEM_SIMU}
+    rm -f ${IGCM_DEM_SIMU}/*
+    
+    JobName=""
+    
+    # Etablir la liste des fichiers de restart
+    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Restart | awk '{print $2 " " $3}' | grep -e '.*/Restart/.*\..*' |grep -v "jnl" | sort  >> ${IGCM_TMP}/${$}.liste_restart_files_config.txt
+
+    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires au repetoire restart/
+    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt ` ; do 
+	dir=$( echo $file | sed -e "s%.*Restart/%%") 
+	testdir=$(dirname ${dir}) 
+	if [ $testdir != "." ]; then 
+	    echo $( grep ${file} ${IGCM_TMP}/${$}.liste_restart_files_config.txt)  >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
+	fi
+    done
+    if [ -f ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ]; then 
+	join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
+	mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
+    fi
+    
+    # Etablir la liste des fichiers output
+    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Output  | awk '{print $2 " "  $3}' | grep -e '.*/Output/.*\.nc$'  | sort >> ${IGCM_TMP}/${$}.liste_output_files_config.txt
+    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires aux repetoires Output/*/
+    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_output_files_config.txt ` ; do 
+	dir=$( echo $file | sed -e "s%.*Output/[A-Za-z0-9][A-Za-z0-9]/%%") 
+	testdir=$(dirname ${dir}) 
+	if [ $testdir != "." ]; then 
+	    echo $( grep ${file} ${IGCM_TMP}/${$}.liste_output_files_config.txt ) >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
+	fi
+    done
+    if [ -f ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ]; then 
+	join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_no_output_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
+	mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_output_files_config.txt
+    fi
+
+    # Lecture du nom du job
+    JobName=`awk -F/ '{if (NR==1) print $(NF-3)}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt`
+    DEM_log -2 JobName ${JobName}
+
+# Maintenant que nous avons JobName verifions que tous les fichiers de restart/Output sont bien du type JobName_date_*
+    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_restart_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
+    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
+    join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.restart.tmp
+    sort -k 2 ${IGCM_TMP}/${$}.restart.tmp > ${IGCM_TMP}/${$}.restart_bis.tmp
+    mv ${IGCM_TMP}/${$}.restart_bis.tmp ${IGCM_DEM_SIMU}/liste_restart_files_config.txt
+# Sauvegarde des fichiers qui ne sont pas dans la norme
+    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
+    mv ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ${IGCM_DEM_SIMU}/liste_no_restart_files_config.txt
+
+
+    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_output_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
+    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
+    join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.output.tmp
+    sort -k 2 ${IGCM_TMP}/${$}.output.tmp > ${IGCM_TMP}/${$}.output_bis.tmp
+    mv ${IGCM_TMP}/${$}.output_bis.tmp ${IGCM_DEM_SIMU}/liste_output_files_config.txt
+# Sauvegarde des fichiers qui ne sont pas dans la norme
+    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
+    mv ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ${IGCM_DEM_SIMU}/liste_no_output_files_config.txt
+
+
+# Recherche de DateBegin et DateEnd pour les Restarts
+    first_file=$(        head -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
+    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
+    DateBegin_Restart=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
+    
+    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
+    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
+    DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
+    
+# Recherche de DateBegin et DateEnd pour les Output
+    first_file=$( head -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
+    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
+    DateBegin_Output=$(  echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
+    
+    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
+    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
+    DateEnd_Output=$(    echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
+    
+    DateBegin=${DateBegin_Restart}
+    DateEnd=${DateEnd_Restart}
+
+    DEM_log -2 "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
+    DEM_log -2 "DateBegin_Output DateEnd_Output : ${DateBegin_Output} ${DateEnd_Output}"
+    DEM_log -2 "DateBegin_Restart DateEnd_Restart : ${DateBegin_Restart} ${DateEnd_Restart}"
+
+    DateBegin=$( DEM_min ${DateBegin_Output} ${DateBegin} ) 
+    DateEnd=$(   DEM_max ${DateEnd_Output}   ${DateEnd}   )
+    
+    DEM_log -2  "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
+    
+    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.config_name ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
+    
+    rm -f ${IGCM_DEM_SIMU}/config_card_${JobName}
+    cat<<EOD>${IGCM_DEM_SIMU}/config_card_${JobName}
+JobName=${JobName}
+DateBegin=${DateBegin}
+DateEnd=${DateEnd}
+PATH_SIMUL_FULL=${PATH_SIMUL_FULL}
+IGCM_DEM_SIMU=${IGCM_DEM_SIMU}
+EOD
+    
+    echo "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone" >> ${IGCM_DEM}/config_card.liste
+
+    DEM_log -1 "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone >> ${IGCM_DEM}/config_card.liste"
+
+done
+
+DEM_log -0 "Fin de ${SCRIPT_NAME}"
+
Index: TOOLS/PACK_IPSL/find_directory_simul.sh
===================================================================
--- TOOLS/PACK_IPSL/find_directory_simul.sh	(revision 1709)
+++ TOOLS/PACK_IPSL/find_directory_simul.sh	(revision 1709)
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+# prend en argument le path et le nom d'un fichier param (argument de la commande
+# ccc_archive avec option ipsl_pack) 
+# ex : ./find_directory_simul.job  fichier_param_test1.txt liste_fichier_dmnfs
+# ex : find_directory_simul.job param_SL.txt /cscratch/cont003/labetoul/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2012-03-21
+
+#-------------------------------
+# A modifier avant utilisation : 
+#--------------------------------
+
+LISTE_SIMUL=${1}
+LISTE_DMNFS=${2}
+
+# ----
+export JOB_DIR=${JOB_DIR:-${PWD}}
+export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
+export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
+mkdir -p ${IGCM_DEM}
+mkdir -p ${IGCM_TMP}
+clean_tmp=${clean_tmp:-yes}
+EXE_DIR=$(dirname ${0})
+SCRIPT_NAME=$(basename ${0} )
+source ${EXE_DIR}/DEM_utilities.sh
+DEM_log -0 "Demmarrage de ${SCRIPT_NAME}"
+cd ${JOB_DIR}
+# ----
+
+LISTE_SIMUL=${1}
+LISTE_DMNFS=${2}
+
+LISTE_SIMUL_NAME=$(basename ${LISTE_SIMUL} )
+
+
+
+# Pour tous les fichiers ou repertoires contenus dans le fichier de parametres 
+for DIR in $( awk '{print $0}' ${LISTE_SIMUL} ) ; do 
+    DEM_log -1 ${SCRIPT_NAME} - Inspection de ${DIR}
+    # trouve la liste des rÃ©pertoires restart sous l'arborescence
+    grep ${DIR}"/" ${LISTE_DMNFS} | grep Restart | awk '{print $3}' | sed 's%/Restart.*%%'  >> ${IGCM_TMP}/${$}.liste_Restart.txt
+
+done
+ 
+# On cherche le path (deux crans au dessus des repertoires Restart) 
+DEM_log -1 "Recherche du path"
+
+for DIR in  $( awk '{print $0}' ${IGCM_TMP}/${$}.liste_Restart.txt ) ; do 
+    DEM_log -3 ${SCRIPT_NAME} - Recherche path : ${DIR}
+    dirname ${DIR} >> ${IGCM_TMP}/${$}.path_simul.txt
+
+done
+
+# On retire les doublons pour avoir la liste des simulations a tester
+DEM_log -1 "Suppression des doublons"
+
+awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <${IGCM_TMP}/${$}.path_simul.txt  >> liste_simul_${LISTE_SIMUL_NAME}
+awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <liste_simul_${LISTE_SIMUL_NAME}  >> liste_simul_${LISTE_SIMUL_NAME}.tmp${$}
+mv liste_simul_${LISTE_SIMUL_NAME}.tmp${$} liste_simul_${LISTE_SIMUL_NAME}
+
+DEM_log -1 "Fichier cree : liste_simul_${LISTE_SIMUL_NAME}"
+
+[[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.path_simul.txt
+[[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_Restart.txt
+
+DEM_log -0 "Fin de ${SCRIPT_NAME}"
Index: TOOLS/PACK_IPSL/find_size_pack.sh
===================================================================
--- TOOLS/PACK_IPSL/find_size_pack.sh	(revision 1709)
+++ TOOLS/PACK_IPSL/find_size_pack.sh	(revision 1709)
@@ -0,0 +1,249 @@
+#!/bin/bash
+
+# But : trouver la taille ideale de pack pour une simulation donnee
+# on part sur une base de 10 ans et on augmente par 0.5 ou on divise 
+# par 2 suivant un critÃšre de taille
+# on passe en revue tous les types de fichiers d'Output et on conserve
+# la taille de pack la plus petite (hors HF) 
+
+# $1= PATH/config_card d'une simulation avec 
+# TagName/JobName/ExperimentName/SpaceName/DateBegin/DateEnd/PATH_SIMUL
+
+# pour commencer on travaille avec le fichier information_dmnfs
+#/cscratch/cont003/p86mart/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2011-09-21
+
+config_card=${1}
+LISTE_DMNFS=${2}
+
+# ----
+export JOB_DIR=${JOB_DIR:-${PWD}}
+export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
+export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
+mkdir -p ${IGCM_DEM}
+mkdir -p ${IGCM_TMP}
+clean_tmp=${clean_tmp:-yes}
+EXE_DIR=$(dirname ${0})
+SCRIPT_NAME=$(basename ${0} )
+source ${EXE_DIR}/DEM_utilities.sh
+DEM_log -0 "Demmarrage de ${SCRIPT_NAME}"
+cd ${JOB_DIR}
+# ----
+
+eval $(grep JobName         ${config_card} ) 
+eval $(grep PATH_SIMUL_FULL ${config_card} ) 
+eval $(grep DateBegin       ${config_card} ) 
+eval $(grep DateEnd         ${config_card} ) 
+eval $(grep IGCM_DEM_SIMU   ${config_card} )
+
+DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} )
+if [[ "${DEM_state}" != "ListToBeDone" ]] ; then
+    DEM_log -0 "Attention : Etat incorrect dans ${IGCM_DEM}/config_card.liste"
+    exit -1
+fi
+
+DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} FindSizePackRunning
+
+# Periodicite du pack (20 ans par defaut) 
+period_pack=20Y
+periodpackinyear=$( echo ${period_pack} | sed -e 's/[yY]//' ) 
+
+# Taille max et min que devra avoir un pack en octet (20Go - 70Go) 
+size_pack_max=70000000000
+size_pack_min=20000000000
+
+SIMUL=${PATH_SIMUL_FULL}/
+
+# Nettoyons les tests precedents .... 
+rm -f ${IGCM_DEM_SIMU}/info_Output.txt
+rm -f ${IGCM_DEM_SIMU}/info_name_file.txt
+
+# 1- Trouver tous les repertoires d'Output
+DEM_log -1 "Recherche des repertoires Output"
+
+#grep ${SIMUL} ${LISTE_DMNFS} > ${IGCM_TMP}/${$}.info_tmp.txt
+#grep "/Output/"  ${IGCM_TMP}/${$}.info_tmp.txt >  ${IGCM_TMP}/${$}.info_tmp_2.txt
+#awk '{print $(NF-2) " " $(NF-1)}' ${IGCM_TMP}/${$}.info_tmp_2.txt > ${IGCM_DEM_SIMU}/info_Output.txt
+
+[[ "${clean_tmp}" = "yes" ]] && rm -f   ${IGCM_TMP}/${$}.info_tmp.txt  ${IGCM_TMP}/${$}.info_tmp_2.txt
+
+# 2- Trouver la liste des noms des fichiers d'Output
+DEM_log -1 "Recherche des noms de fichiers Output"
+
+sed -e "s%.*_\([0-9]\{8\}\)_\([0-9]\{8\}\)_%%" ${IGCM_DEM_SIMU}/liste_output_files_config.txt  | awk '/.nc/{print $0}'  >  ${IGCM_TMP}/${$}.info_tmp.txt
+
+#on enleve si des fichiers ne repondent pas au critere et sont donc encore en /
+cat ${IGCM_TMP}/${$}.info_tmp.txt | grep -v "/" > ${IGCM_TMP}/${$}.info_tmp_bis.txt
+
+
+# On enleve mesh_mask qui est un cas particulier a traiter ulterieurement
+sed '/mesh_mask/d' ${IGCM_TMP}/${$}.info_tmp_bis.txt >  ${IGCM_TMP}/${$}.info_tmp_2.txt
+
+# On retire les doublons de la liste prÃ©cÃ©dent
+awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <  ${IGCM_TMP}/${$}.info_tmp_2.txt >> ${IGCM_DEM_SIMU}/info_name_file.txt
+[[ "${clean_tmp}" = "yes" ]] && rm -f  ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.info_tmp_2.txt
+
+
+#!!!# Reduction de la taille du probleme pour test
+# grep 1M_cpl_atm.nc  ${IGCM_DEM_SIMU}/info_name_file.txt >  ${IGCM_DEM_SIMU}/info_name_file.txt.tmp
+# grep 1M_grid_T.nc  ${IGCM_DEM_SIMU}/info_name_file.txt >>  ${IGCM_DEM_SIMU}/info_name_file.txt.tmp
+# mv ${IGCM_DEM_SIMU}/info_name_file.txt.tmp ${IGCM_DEM_SIMU}/info_name_file.txt
+
+# On cree la liste des fichiers pour chaque type_file
+DEM_log -1 "Creation de la liste des fichiers"
+
+for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
+do 
+#for type_file in 1D_cpl_atm.nc ; do
+    DEM_log -1 "Traitement type de fichier = ${type_file}"
+    grep ${type_file} ${IGCM_DEM_SIMU}/liste_output_files_config.txt >  ${IGCM_TMP}/${$}.info_${type_file}.txt
+    # cette liste comporte en premiere colonne la taille et en deuxieme le path du fichier
+    # on classe la liste par ordre alphabetique des path des fichiers
+    sort -k 2  ${IGCM_TMP}/${$}.info_${type_file}.txt >  ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp
+    cp ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp  ${IGCM_TMP}/${$}.info_${type_file}.txt
+    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp
+done
+
+
+# 3- Maintenant pour chaque type de fichier de sortie nous allons calculer la 
+# taille qu'aurait le pack de {periodpackinyear}ans
+DEM_log -1 "Debut recherche taille de pack"
+
+# Recherche des dates du premier pack
+
+year_begin=$(  echo ${DateBegin} | cut -c 1-4 )
+month_begin=$( echo ${DateBegin} | cut -c 5-6 )
+year_end=$(    echo ${DateEnd}   | cut -c 1-4 )
+month_end=$(   echo ${DateEnd}   | cut -c 5-6 )
+
+date_begin_pack=${DateBegin}
+date_end_simulation=${DateEnd}
+
+month_begin_pack=${month_begin}
+year_begin_pack=${year_begin}
+
+number_pack=1
+
+# on ne fait le calcul que pour les dix premiers pack (donc 20 * 10 =  200 ans) 
+# cela doit donner un echantillon suffisant 
+while [[ ${date_begin_pack} -le ${date_end_simulation}  && ${number_pack} -le 10 ]]
+do 
+    
+    month_end_pack=${month_begin_pack}
+    year_end_pack=$(( ${year_begin_pack} + ${periodpackinyear} ))
+    
+    date_end_pack=${year_end_pack}${month_end_pack}01 
+
+    DEM_log -2 "Entree boucle : year_begin_pack month_begin_pack year_end_pack month_end_pack : ${year_begin_pack} ${month_begin_pack} ${year_end_pack} ${month_end_pack}"
+
+    # on travaille pour chaque type de fichiers 
+    for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
+    do
+    #for type_file in 1M_grid_T.nc ; do
+	DEM_log -3 ${type_file} ${number_pack}
+	taille=0
+        #il faut les passer en revue et calculer par tranche de period_pack leur somme
+	for file in `awk '{print $2}'  ${IGCM_TMP}/${$}.info_${type_file}.txt` ; do 
+            #extraire la date de debut et la date de fin de la periode d'output traitee par le fichier    
+            extract_date_file=$( echo ${file}             | sed "s%.*${JobName}_%%"            )
+            date_debut=$(        echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g'    )
+            date_fin=$(          echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' )
+            if [  ${date_debut} -lt ${date_end_pack} ]
+            then 
+		if [ ${date_fin} -ge ${date_begin_pack} ]
+		then 
+		    grep ${file}  ${IGCM_TMP}/${$}.info_${type_file}.txt >>  ${IGCM_TMP}/${$}.info_${type_file}_${number_pack}.txt
+	            # on efface le fichier de la liste pour ne pas travailler dessus pour le prochain pack
+		    grep -v ${file} ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
+                    cp ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt
+		    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
+		fi
+	    else 
+	    # comme la liste est classee par ordre alphabetique --> par ordre croissant des periodes de sorties
+	    # des que un fichier n'est plus dans le pack on peut sortir c'est qu'on les a tous. 
+		break
+            fi
+	    
+	done
+       # on fait la somme par periodpack et par type de fichier de la taille qu'aurait le pack
+	awk 'BEGIN {y = 0} {x = $1 ; y = y + x } END{print y}'  ${IGCM_TMP}/${$}.info_${type_file}_${number_pack}.txt >> ${IGCM_TMP}/${$}.size_pack_${type_file}.txt
+	[[ "${clean_tmp}" = "yes" ]] && rm -f  ${IGCM_TMP}/${$}.info_${type_file}_${number_pack}.txt
+    done
+    
+    month_begin_pack=${month_end_pack}
+    year_begin_pack=${year_end_pack}
+    date_begin_pack=${year_begin_pack}${month_begin_pack}01
+    
+    number_pack=$(( ${number_pack} + 1 ))
+
+    DEM_log -2 "Sortie boucle : year_begin_pack month_begin_pack year_end_pack month_end_pack : ${year_begin_pack} ${month_begin_pack} ${year_end_pack} ${month_end_pack}"
+
+done
+
+# Pour chaque type de fichier on verifie si toutes les tailles sont dans 
+# la fourchette size_pack_min / size_pack_max 
+# Si une taille est plus petite 
+# attention il ne faut pas tenir compte du dernier pack qui peut etre
+# inferieur a periodpack
+
+new_period=999999
+
+for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
+do 
+    nb_line=$(cat ${IGCM_TMP}/${$}.size_pack_${type_file}.txt | wc -l )
+    if [ ${nb_line} -gt 1 ] 
+    then 
+	for taille in `head -n -1  ${IGCM_TMP}/${$}.size_pack_${type_file}.txt`
+	do 
+            [[ ${taille} -lt ${size_pack_min} ]] && period_tmp=$(( ${size_pack_min} * ${periodpackinyear} / ${taille} ))
+            [[ ${taille} -gt ${size_pack_max} ]] && period_tmp=$(( ${size_pack_min} * ${periodpackinyear} / ${taille} ))
+            [[ ${taille} -ge ${size_pack_min} && ${taille} -le ${size_pack_max} ]] && period_tmp=${periodpackinyear}
+            [[ ${period_tmp} -lt ${new_period} ]] && new_period=${period_tmp}
+	done
+    else
+        # Dans ce cas la il n'y avait pas assez de fichiers pour remplir une periode complete #
+        # il faut donc commencer par calculer la taille du pack que l'on a fait #
+	yearnewpack=$((    ${year_end}  - ${year_begin}        ))
+	monthnewpack=$((   ${month_end} - ${month_begin} + 1   ))
+	newpackinmonth=$(( ${yearnewpack}*12 + ${monthnewpack} ))
+	newpackinyear=$((  ${newpackinmonth}/12                ))
+	[[ ${newpackinyear} -lt 1 ]] && newpackinyear=1
+	
+	for taille in `head  ${IGCM_TMP}/${$}.size_pack_${type_file}.txt`
+	do 
+#	  echo ${taille} ${type_file}
+            [[ ${taille} -lt ${size_pack_min} ]] && period_tmp=${newpackinyear}
+            [[ ${taille} -gt ${size_pack_max} ]] && period_tmp=$(( ${size_pack_min} * ${newpackinyear} / ${taille} ))
+            [[ ${taille} -ge ${size_pack_min} && ${taille} -le ${size_pack_max} ]] && period_tmp=${newpackinyear}
+            [[ ${period_tmp} -lt ${new_period} ]] && new_period=${period_tmp}
+	done
+	
+    fi 
+done
+
+DEM_log -1 "taille=${taille}"
+DEM_log -1 "new_period=${new_period}"
+
+# on veut que la taille de pack soit de 1 2 5 10 20 50 ou 100 ans
+declare -a liste_period=( 1 2 5 10 20 50 100 )
+
+change=0
+for i in 1 2 3 4 5 6 ; do
+    if [[ ${new_period} -lt ${liste_period[i]} && ${change} -eq 0 ]]
+    then 
+	new_period=${liste_period[i-1]}
+	change=1
+    fi 
+done
+
+[[ ${new_period} -gt 100 ]] && new_period=100
+
+[[ "${clean_tmp}" = "yes" ]] && rm -f  ${IGCM_TMP}/${$}.*
+
+echo ${new_period} > ${IGCM_DEM_SIMU}/period_pack.txt
+DEM_log -0 "La nouvelle periode de pack est : ${new_period}Y"
+
+DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} FindSizePackDone
+
+DEM_log -0 "Fin de ${SCRIPT_NAME}"
+
+exit 
Index: TOOLS/PACK_IPSL/launch_ipsl_pack.sh
===================================================================
--- TOOLS/PACK_IPSL/launch_ipsl_pack.sh	(revision 1709)
+++ TOOLS/PACK_IPSL/launch_ipsl_pack.sh	(revision 1709)
@@ -0,0 +1,76 @@
+#!/bin/bash
+######################
+## TITANE   CEA ##
+######################
+#MSUB -r ipsl_pack      # Nom du job                
+#MSUB -eo
+#MSUB -n 1              # Reservation du processus
+#MSUB -T 86400          # Limite de temps elapsed du job
+#MSUB -p gen2211
+#MSUB -q mono
+
+# ex : ./launch_ipsl_pack.sh fichier_param_test1.txt liste_fichier_dmnfs
+# ex : ./launch_ipsl_pack.sh param_SL.txt SL_information_dmnfs_2012-03-21
+# ex : ./launch_ipsl_pack.sh param_OM.txt OM_information_dmnfs_2012-03-21
+
+export JOB_DIR=${LS_SUBCWD:-${PWD}}
+export EXE_DIR=${JOB_DIR}
+
+LISTE_SIMUL=${1}
+LISTE_DMNFS=${2}
+
+#LISTE_SIMUL=${JOB_DIR}/param_SL.txt 
+#LISTE_DMNFS=${JOB_DIR}/SL_information_dmnfs_2012-03-21
+
+# LISTE_SIMUL=${JOB_DIR}/param_OM.txt
+# LISTE_DMNFS=${JOB_DIR}/OM_information_dmnfs_2012-03-21
+
+LISTE_SIMUL_NAME=$(basename ${LISTE_SIMUL} )
+SCRIPT_NAME=$(basename ${0} )
+
+export IGCM_DEM=${SCRATCHDIR}/IGCM_DEM
+export IGCM_TMP=${SCRATCHDIR}/IGCM_DEM/tmp
+export clean_tmp=${clean_tmp:-yes}
+export DEM_LOG=${JOB_DIR}/dem_${LSB_JOBID:-${$}}.log
+export LOG_LEV=2
+
+source ${EXE_DIR}/DEM_utilities.sh
+
+DEM_log -0 "Demarrage de ${SCRIPT_NAME}"
+
+mkdir -p ${IGCM_DEM}
+mkdir -p ${IGCM_TMP}
+
+rm -rf ${IGCM_TMP}/tmp/*
+rm -f ${DEM_LOG}
+
+# 1- A partir de param_list - on recherche l'ensemble des simulations a packer
+# la liste creee (liste_simul_$1) est stockee dans $SCRATCHDIR/IGCM_DEM
+
+${EXE_DIR}/find_directory_simul.sh ${LISTE_SIMUL} ${LISTE_DMNFS}
+
+# 2- Pour chacune des simulations listees on cree un fichier config.card correspondant
+# ces fichiers seront stockes dans ${IGCM_DEM}/arborescence/
+# un fichier recapitulatif des fichiers config.card (config_card.liste) crees sera stocke dans ${IGCM_DEM}
+
+${EXE_DIR}/create_config_card.sh liste_simul_${LISTE_SIMUL_NAME}  ${LISTE_DMNFS}
+
+#3- recherche de la taille ideale de pack pour chacune des simulations - puis creation des listes
+
+for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste ) ; do 
+    
+    DEM_log ${CONFIG}
+
+    eval $(grep IGCM_DEM_SIMU ${CONFIG})
+    ${EXE_DIR}/calcul_size_simul.sh ${CONFIG} ${LISTE_DMNFS}
+
+    if [ ! -f ${IGCM_DEM_SIMU}/tar_full_simul.txt ]
+    then 
+	echo "la simulation est superieur a 1Go alors on pack"
+	${EXE_DIR}/find_size_pack.sh   ${CONFIG} ${LISTE_DMNFS}
+	${EXE_DIR}/write_liste_pack.sh ${CONFIG} ${LISTE_DMNFS}
+#	${EXE_DIR}/archive_restart.sh ${CONFIG} ${LISTE_DMNFS}
+    fi
+done
+
+DEM_log -0 "Fin de ${SCRIPT_NAME}"
Index: TOOLS/PACK_IPSL/write_liste_pack.sh
===================================================================
--- TOOLS/PACK_IPSL/write_liste_pack.sh	(revision 1709)
+++ TOOLS/PACK_IPSL/write_liste_pack.sh	(revision 1709)
@@ -0,0 +1,241 @@
+#!/bin/bash
+
+
+# Script permettant de creer les listes de fichiers pour ncrcat
+# si un trou est detecte dans la simulation alors cette liste sera 
+# pour un tar
+
+# $1= PATH/config_card d'une simulation avec 
+# TagName/JobName/ExperimentName/SpaceName/DateBegin/DateEnd/PATH_SIMUL
+
+
+# Pour commencer on travaille avec le fichier information_dmnfs
+# /cscratch/cont003/p86mart/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2011-09-21
+
+config_card=${1}
+LISTE_DMNFS=${2}
+
+# Declaration des variables
+
+# ----
+export JOB_DIR=${JOB_DIR:-${PWD}}
+export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
+export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
+mkdir -p ${IGCM_DEM}
+mkdir -p ${IGCM_TMP}
+clean_tmp=${clean_tmp:-yes}
+EXE_DIR=$(dirname ${0} )
+SCRIPT_NAME=$(basename ${0} )
+source ${EXE_DIR}/DEM_utilities.sh
+DEM_log -0 "Demmarrage de ${SCRIPT_NAME}"
+cd ${JOB_DIR}
+# ----
+
+DEM_log -0 "config_card : ${config_card}"
+DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}"
+
+eval $(grep JobName         ${config_card}) 
+eval $(grep PATH_SIMUL_FULL ${config_card}) 
+eval $(grep DateBegin       ${config_card}) 
+eval $(grep DateEnd         ${config_card}) 
+eval $(grep IGCM_DEM_SIMU   ${config_card})
+
+SIMUL=${PATH_SIMUL_FULL}/${JobName}
+
+DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} )
+if [[ "${DEM_state}" != "FindSizePackDone" ]] ; then
+    DEM_log -0 "Attention : Etat incorrect dans ${IGCM_DEM}/config_card.liste"
+    exit -1
+fi
+
+DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackRunning
+
+# lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt
+period_pack=$( awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt )
+
+year_begin=$(  echo ${DateBegin} | cut -c 1-4 )
+month_begin=$( echo ${DateBegin} | cut -c 5-6 )
+year_end=$(    echo ${DateEnd}   | cut -c 1-4 )
+month_end=$(   echo ${DateEnd}   | cut -c 5-6 )
+
+awk '{print $2}' ${IGCM_DEM_SIMU}/info_Output.txt >  ${IGCM_DEM_SIMU}/info_Output_light.txt
+
+# on cree la liste des fichiers pour chaque type_file
+for type_file in $( awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt ) ; do 
+   #sed -e "/${type_file}/!d" ${IGCM_DEM_SIMU}/info_Output_light.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt
+    grep ${type_file} ${IGCM_DEM_SIMU}/info_Output_light.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt
+    sort -u ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp
+    cp ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt
+    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp
+done
+
+
+# 3- Maintenant pour chaque type de fichier de sortie nous allons creer la liste
+# des fichiers contenus dans chaque pack
+
+# Recherche des dates du premier pack
+
+date_begin_pack=${DateBegin}
+date_end_simulation=${DateEnd}
+
+month_begin_pack=${month_begin}
+year_begin_pack=${year_begin}
+
+number_pack=1
+
+#
+while [[ ${date_begin_pack} -le ${date_end_simulation}  ]]
+do 
+
+   month_end_pack=${month_begin_pack}
+   year_end_pack=$(( ${year_begin_pack} +${period_pack} ))
+   
+   date_end_pack=${year_end_pack}${month_end_pack}01   
+
+   DEM_log -2 "Entree boucle 3 : year_begin_pack month_begin_pack year_end_pack month_end_pack : ${year_begin_pack} ${month_begin_pack} ${year_end_pack} ${month_end_pack}"
+   DEM_log -2 "Entree boucle 3 : date_end_pack : ${date_end_pack}"
+   
+   for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
+   do 
+       DEM_log -2 "Boucle 3 : ${type_file} ${number_pack}"
+       taille=0
+
+       # On passe en revue chaque type de fichier 
+       for file in `awk '{print $0}' ${IGCM_TMP}/${$}.info_${type_file}.txt`
+       do 
+           # Extraire la date de debut et la date de fin de la periode d'output traitee par le fichier    
+           extract_date_file=$( echo ${file}             | sed -e "s%.*${JobName}_%%" )
+           date_debut=$(        echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' )
+           date_fin=$(          echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' )
+	   
+           if [  ${date_debut} -lt ${date_end_pack} ]
+           then 
+               if [ ${date_fin} -ge ${date_begin_pack} ]
+               then 
+		   echo ${file} >> ${IGCM_DEM_SIMU}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list
+		   echo ${date_debut} | cut -c 1-6 >>  ${IGCM_TMP}/${$}.date_${type_file}.txt
+		   grep -v ${file} ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
+		   cp ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt
+		   [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
+               fi
+	   else 
+	       break
+           fi
+	   
+       done
+       if [[ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ]] ; then
+	   sort -u ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_TMP}/${$}.date_tmp.txt
+	   mv ${IGCM_TMP}/${$}.date_tmp.txt ${IGCM_TMP}/${$}.date_${type_file}.txt
+       else
+	   DEM_log -2 "Pas de fichier cree :  ${IGCM_TMP}/${$}.date_${type_file}.txt - Date_end_pack : ${date_end_pack}"
+       fi
+
+#On renomme le fichier ncrcat avec la date reelle de fin et non pas la premiere date suivant la fin 
+       sort ${IGCM_DEM_SIMU}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list > ${IGCM_TMP}/${$}.ncrcat.tmp
+       last_file=$(tail -n 1 ${IGCM_TMP}/${$}.ncrcat.tmp )
+       extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
+       date_fin=$(echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' )
+       mv ${IGCM_DEM_SIMU}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list ${IGCM_DEM_SIMU}/ncrcat_${type_file}_${date_begin_pack}_${date_fin}.list
+   done
+   
+   
+   month_begin_pack=${month_end_pack}
+   year_begin_pack=${year_end_pack}
+   date_begin_pack=${year_begin_pack}${month_begin_pack}01
+   
+   number_pack=$(( ${number_pack} + 1 ))
+
+   DEM_log -2 "Sortie boucle : year_begin_pack month_begin_pack year_end_pack month_end_pack : ${year_begin_pack} ${month_begin_pack} ${year_end_pack} ${month_end_pack}"
+   DEM_log -2 "Sortie boucle : date_begin_pack : ${date_begin_pack}"
+   
+done
+
+
+## Recherche des trous eventuels dans cette simulation
+
+## Creation de la liste des annees comprisent entre DateBegin et DateEnd >>  ${IGCM_TMP}/${$}.liste_date.txt
+force_sequence (){
+    awk '{
+        if (NR==1) {avant=$1; print $1}
+        else { for (i=avant+1 ; i<=$1 ; i++) printf "%04i\n", i}}'
+}
+
+DEM_log -1 "year_begin - year_end : ${year_begin} - ${year_end}"
+
+echo ${year_begin} > ${IGCM_TMP}/${$}.liste_date.txt
+echo ${year_end}  >> ${IGCM_TMP}/${$}.liste_date.txt
+
+force_sequence < ${IGCM_TMP}/${$}.liste_date.txt > ${IGCM_TMP}/${$}.tmp ; mv ${IGCM_TMP}/${$}.tmp ${IGCM_TMP}/${$}.liste_date.txt
+
+
+## il faut savoir si les fichiers d'output sont annuels ou mensuels ? 
+file=$( head -n 2 ${IGCM_DEM_SIMU}/info_Output.txt )
+
+extract_date_file=$( echo ${file}             | sed -e "s%.*${JobName}_%%" )
+date_debut=$(        echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g')
+date_fin=$(          echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g')
+month_begin=$(       echo ${date_debut}       | cut -c 5-6 )
+month_end=$(         echo ${date_fin}         | cut -c 5-6 )
+
+DEM_log -1 "Recherche de la frequence"
+if [ ${month_end} -eq ${month_begin} ] 
+then 
+    DEM_log -1 "Mensuel"
+    frequency="mensuel"
+    while read an ; do
+        for month in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
+            printf "%s%02d\n" ${an} ${month}  >> ${IGCM_TMP}/${$}.toutes_dates
+	done
+    done < ${IGCM_TMP}/${$}.liste_date.txt
+    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_date.txt
+fi 
+if [[ ${month_end} -eq "12" && ${month_begin} -eq "01" ]]
+then 
+    DEM_log -1 "Annuel"
+    frequency="annuel"
+    while read an ; do
+	i=1
+	printf "%s%02d\n" ${an} ${i}  >> ${IGCM_TMP}/${$}.toutes_dates
+    done < ${IGCM_TMP}/${$}.liste_date.txt    
+fi 
+
+
+# Maintenant il faut comparer la liste des dates avec la liste des dates des fichiers 
+# et pour des dates manquantes transformer le fichier ncrcat_date correspondant en fichier 
+# tar_date
+DEM_log -1 "Recherche des dates manquantes"
+for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
+do 
+    DEM_log -2 "${type_file}"
+    rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list
+    
+    if [ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ] ; then
+	join -v 1  ${IGCM_TMP}/${$}.toutes_dates ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_DEM_SIMU}/${type_file}_manquant.list
+	
+        # On change le fichier ncrcat pour chaque date manquante en fichier tar
+	if [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then 
+	    for date in `awk '{print $0}' ${IGCM_DEM_SIMU}/${type_file}_manquant.list` ; do 
+		ls -l ${IGCM_DEM_SIMU}/ncrcat_${type_file}* > ${IGCM_TMP}/${$}.liste_ncrcat
+		for pack in $( awk '{print $9}' ${IGCM_TMP}/${$}.liste_ncrcat ) ; do 
+		    extract_date_file=$( echo ${pack}       | sed -e "s%.*${type_file}_%%" )
+		    date_debut=$( echo ${extract_date_file} | sed 's%\([0-9]\{8\}\)_.*$%\1%g'     | cut -c 1-6  )
+		    date_fin=$(   echo ${extract_date_file} | sed 's%.*_\([0-9]\{8\}\).list%\1%g' | cut -c 1-6  )
+		    if [[ ${date} -ge ${date_debut} && ${date} -lt ${date_fin} ]]; then
+			mv ${pack} ${IGCM_DEM_SIMU}/tar_${type_file}_${date_debut}_${date_fin}.list
+			break 
+		    else
+			rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list
+		    fi
+		    
+		done
+		[[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_ncrcat
+	    done
+	fi
+    fi
+done
+
+DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackDone
+
+DEM_log -0 "Fin de ${SCRIPT_NAME}"
+
+exit
