Index: TOOLS/PACK_IPSL/find_size_pack.sh
===================================================================
--- TOOLS/PACK_IPSL/find_size_pack.sh	(revision 1962)
+++ TOOLS/PACK_IPSL/find_size_pack.sh	(revision 2027)
@@ -54,5 +54,4 @@
 
 DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} FindSizePackRunning
-
 # Periodicite du pack (20 ans par defaut) 
 period_pack=20Y
@@ -119,5 +118,4 @@
 # taille qu'aurait le pack de {periodpackinyear}ans
 DEM_log -1 "Debut recherche taille de pack"
-
 # Recherche des dates du premier pack
 
@@ -136,11 +134,12 @@
 
 # on ne fait le calcul que pour les dix premiers pack (donc 20 * 10 =  200 ans) 
-# cela doit donner un echantillon suffisant 
+# cela doit donner un echantillon suffisant
+date_begin_pack=`echo $date_begin_pack|sed 's/^0*//'` 
+date_end_simulation=`echo $date_end_simulation|sed 's/^0*//'` 
 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} ))
-    
+    year_end_pack=$(( 10#${year_begin_pack} + ${periodpackinyear} ))
     date_end_pack=${year_end_pack}${month_end_pack}01 
 
@@ -202,35 +201,33 @@
 new_period=999999
 newpackinyear=0
-
-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
+if [[ -f ${IGCM_TMP}/${$}.size_pack_${type_file}.txt ]]; then 
+    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 #
-	newpackinyear=$((    ${year_end}  - ${year_begin}        ))
-	newpackinyear=$(( $newpackinyear + 1 ))
-	[[ ${newpackinyear} -lt 1 ]] && newpackinyear=1
-	
-	for taille in `head  ${IGCM_TMP}/${$}.size_pack_${type_file}.txt`
-	do 
-            [[ ${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
-
+	    newpackinyear=$((    ${year_end}  - ${year_begin}        ))
+	    newpackinyear=$(( $newpackinyear + 1 ))
+	    [[ ${newpackinyear} -lt 1 ]] && newpackinyear=1
+	    for taille in `head  ${IGCM_TMP}/${$}.size_pack_${type_file}.txt`
+	    do 
+		[[ ${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
+fi
 DEM_log -1 "taille=${taille}"
 DEM_log -1 "new_period=${new_period}"
