source: TOOLS/PACK_IPSL/find_size_pack.sh @ 3620

Last change on this file since 3620 was 2130, checked in by acosce, 11 years ago

Fix two bug in find_size_pack

1- the calcul for the PackFrequency? was wrong for pack bigger than 70G
2- there was a bug when we try to fix the PackFrequency? to 1, 2, 5, 10 ... year

File size: 11.2 KB
Line 
1#!/bin/bash
2# But : trouver la taille ideale de pack pour une simulation donnee
3# on part sur une base de 10 ans et on augmente par 0.5 ou on divise
4# par 2 suivant un critÚre de taille
5# on passe en revue tous les types de fichiers d'Output et on conserve
6# la taille de pack la plus petite (hors HF)
7
8# $1= PATH/config_card d'une simulation avec
9# TagName/JobName/ExperimentName/SpaceName/DateBegin/DateEnd/PATH_SIMUL
10
11# pour commencer on travaille avec le fichier information_dmnfs
12#/cscratch/cont003/p86mart/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2011-09-21
13
14config_card=${1}
15LISTE_DMNFS=${2}
16
17# ----
18export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}}
19export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
20export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
21mkdir -p ${IGCM_DEM}
22mkdir -p ${IGCM_TMP}
23clean_tmp=${clean_tmp:-yes}
24EXE_DIR=$(dirname ${0})
25SCRIPT_NAME=$(basename ${0} )
26source ${EXE_DIR}/DEM_utilities.sh
27
28# gpdebug : verif si le present script a ete execute jusqu'au bout #########
29MonitoringInfo="${SCRIPT_NAME}-->OK"
30simuMonitoring_check "$MonitoringInfo" "$config_card"
31
32# gpdebug : Execute la function errorReceive() si reception d'un signal TERM
33trap 'DEM_errorReceive' TERM ########
34
35# gpdebug : on augmente la liste des proc à détruire en cas d'erreur bloquante du présent proc
36export listPID="$$ ${listPID}" #########
37
38DEM_log -0 "Demmarrage de ${SCRIPT_NAME}"
39cd ${EXE_DIR}
40# ----
41
42eval $(grep JobName         ${config_card} ) 
43eval $(grep PATH_SIMUL_FULL ${config_card} ) 
44eval $(grep DateBegin       ${config_card} ) 
45eval $(grep DateEnd         ${config_card} ) 
46eval $(grep IGCM_DEM_SIMU   ${config_card} )
47
48DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} )
49# gpdebug : si c'est une premiere exec (pas une reprise)
50if [[ "x${execEveryStep}" == "1" ]] && [[ "${DEM_state}" != "ListToBeDone" ]] ; then
51    echo "gpdebug : DEM_state=${DEM_state}"
52    DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Etat incorrect dans ${IGCM_DEM}/config_card.liste"
53fi
54
55DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} FindSizePackRunning
56# Periodicite du pack (20 ans par defaut)
57period_pack=20Y
58periodpackinyear=$( echo ${period_pack} | sed -e 's/[yY]//' ) 
59
60# Taille max et min que devra avoir un pack en octet (20Go - 70Go)
61size_pack_max=70000000000
62size_pack_min=20000000000
63
64SIMUL=${PATH_SIMUL_FULL}/
65
66# Nettoyons les tests precedents ....
67rm -f ${IGCM_DEM_SIMU}/info_Output.txt
68rm -f ${IGCM_DEM_SIMU}/info_name_file.txt
69
70# 1- Trouver tous les repertoires d'Output
71DEM_log -1 "Recherche des repertoires Output"
72
73#grep ${SIMUL} ${LISTE_DMNFS} > ${IGCM_TMP}/${$}.info_tmp.txt
74#grep "/Output/"  ${IGCM_TMP}/${$}.info_tmp.txt >  ${IGCM_TMP}/${$}.info_tmp_2.txt
75#awk '{print $(NF-2) " " $(NF-1)}' ${IGCM_TMP}/${$}.info_tmp_2.txt > ${IGCM_DEM_SIMU}/info_Output.txt
76
77[[ "${clean_tmp}" = "yes" ]] && rm -f   ${IGCM_TMP}/${$}.info_tmp.txt  ${IGCM_TMP}/${$}.info_tmp_2.txt
78
79# 2- Trouver la liste des noms des fichiers d'Output
80DEM_log -1 "Recherche des noms de fichiers Output"
81
82sed -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
83
84#on enleve si des fichiers ne repondent pas au critere et sont donc encore en /
85cat ${IGCM_TMP}/${$}.info_tmp.txt | grep -v "/" > ${IGCM_TMP}/${$}.info_tmp_bis.txt
86
87
88## On enleve mesh_mask qui est un cas particulier a traiter ulterieurement
89#sed '/mesh_mask/d' ${IGCM_TMP}/${$}.info_tmp_bis.txt >  ${IGCM_TMP}/${$}.info_tmp_2.txt
90
91# On retire les doublons de la liste précédent
92awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <  ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_DEM_SIMU}/info_name_file.txt
93[[ "${clean_tmp}" = "yes" ]] && rm -f  ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt
94
95
96#!!!# Reduction de la taille du probleme pour test
97# grep 1M_cpl_atm.nc  ${IGCM_DEM_SIMU}/info_name_file.txt >  ${IGCM_DEM_SIMU}/info_name_file.txt.tmp
98# grep 1M_grid_T.nc  ${IGCM_DEM_SIMU}/info_name_file.txt >>  ${IGCM_DEM_SIMU}/info_name_file.txt.tmp
99# mv ${IGCM_DEM_SIMU}/info_name_file.txt.tmp ${IGCM_DEM_SIMU}/info_name_file.txt
100
101# On cree la liste des fichiers pour chaque type_file
102DEM_log -1 "Creation de la liste des fichiers"
103
104for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
105do
106#for type_file in 1D_cpl_atm.nc ; do
107    DEM_log -1 "Traitement type de fichier = ${type_file}"
108    grep ${type_file} ${IGCM_DEM_SIMU}/liste_output_files_config.txt >  ${IGCM_TMP}/${$}.info_${type_file}.txt
109    # cette liste comporte en premiere colonne la taille et en deuxieme le path du fichier
110    # on classe la liste par ordre alphabetique des path des fichiers
111    sort -k 2  ${IGCM_TMP}/${$}.info_${type_file}.txt >  ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp
112    cp ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp  ${IGCM_TMP}/${$}.info_${type_file}.txt
113    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp
114done
115
116
117# 3- Maintenant pour chaque type de fichier de sortie nous allons calculer la
118# taille qu'aurait le pack de {periodpackinyear}ans
119DEM_log -1 "Debut recherche taille de pack"
120# Recherche des dates du premier pack
121
122year_begin=$(  echo ${DateBegin} | cut -c 1-4 )
123month_begin=$( echo ${DateBegin} | cut -c 5-6 )
124year_end=$(    echo ${DateEnd}   | cut -c 1-4 )
125month_end=$(   echo ${DateEnd}   | cut -c 5-6 )
126
127date_begin_pack=${DateBegin}
128date_end_simulation=${DateEnd}
129
130month_begin_pack=${month_begin}
131year_begin_pack=${year_begin}
132
133number_pack=1
134
135# on ne fait le calcul que pour les dix premiers pack (donc 20 * 10 =  200 ans)
136# cela doit donner un echantillon suffisant
137date_begin_pack=`echo $date_begin_pack|sed 's/^0*//'` 
138date_end_simulation=`echo $date_end_simulation|sed 's/^0*//'` 
139while [[ ${date_begin_pack} -le ${date_end_simulation}  && ${number_pack} -le 10 ]]
140do
141   
142    month_end_pack=${month_begin_pack}
143    year_end_pack=$(( 10#${year_begin_pack} + ${periodpackinyear} ))
144    date_end_pack=${year_end_pack}${month_end_pack}01 
145
146    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}"
147    # on travaille pour chaque type de fichiers
148    for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
149    do
150    #for type_file in 1M_grid_T.nc ; do
151        DEM_log -3 ${type_file} ${number_pack}
152        taille=0
153        #il faut les passer en revue et calculer par tranche de period_pack leur somme
154        for file in `awk '{print $2}'  ${IGCM_TMP}/${$}.info_${type_file}.txt` ; do 
155            #extraire la date de debut et la date de fin de la periode d'output traitee par le fichier   
156            extract_date_file=$( echo ${file}             | sed "s%.*${JobName}_%%"            )
157            date_debut=$(        echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g'    )
158            date_fin=$(          echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' )
159            if [  ${date_debut} -lt ${date_end_pack} ]
160            then
161                if [ ${date_fin} -ge ${date_begin_pack} ]
162                then
163                    grep ${file}  ${IGCM_TMP}/${$}.info_${type_file}.txt >>  ${IGCM_TMP}/${$}.info_${type_file}_${number_pack}.txt
164                    # on efface le fichier de la liste pour ne pas travailler dessus pour le prochain pack
165                    grep -v ${file} ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
166                    cp ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt
167                    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
168                fi
169            else
170            # comme la liste est classee par ordre alphabetique --> par ordre croissant des periodes de sorties
171            # des que un fichier n'est plus dans le pack on peut sortir c'est qu'on les a tous.
172                break
173            fi
174           
175        done
176       # on fait la somme par periodpack et par type de fichier de la taille qu'aurait le pack
177        if [ -f ${IGCM_TMP}/${$}.info_${type_file}_${number_pack}.txt ]
178        then
179            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
180            [[ "${clean_tmp}" = "yes" ]] && rm -f  ${IGCM_TMP}/${$}.info_${type_file}_${number_pack}.txt
181        fi
182    done
183   
184    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}"
185
186    month_begin_pack=${month_end_pack}
187    year_begin_pack=${year_end_pack}
188    date_begin_pack=${year_begin_pack}${month_begin_pack}01
189   
190    number_pack=$(( ${number_pack} + 1 ))
191
192
193done
194
195# Pour chaque type de fichier on verifie si toutes les tailles sont dans
196# la fourchette size_pack_min / size_pack_max
197# Si une taille est plus petite
198# attention il ne faut pas tenir compte du dernier pack qui peut etre
199# inferieur a periodpack
200
201new_period=999999
202newpackinyear=0
203if [[ -f ${IGCM_TMP}/${$}.size_pack_${type_file}.txt ]]; then
204    for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
205    do
206        nb_line=$(cat ${IGCM_TMP}/${$}.size_pack_${type_file}.txt | wc -l )
207        if [ ${nb_line} -gt 1 ]
208        then
209            for taille in `head -n -1  ${IGCM_TMP}/${$}.size_pack_${type_file}.txt`
210            do 
211                [[ ${taille} -lt ${size_pack_min} ]] && period_tmp=$(( ${size_pack_min} * ${periodpackinyear} / ${taille} ))
212                [[ ${taille} -gt ${size_pack_max} ]] && period_tmp=$(( ${size_pack_max} * ${periodpackinyear} / ${taille} ))
213                [[ ${taille} -ge ${size_pack_min} && ${taille} -le ${size_pack_max} ]] && period_tmp=${periodpackinyear}
214                [[ ${period_tmp} -lt ${new_period} ]] && new_period=${period_tmp}
215            done
216        else
217        # Dans ce cas la il n'y avait pas assez de fichiers pour remplir une periode complete #
218        # il faut donc commencer par calculer la taille du pack que l'on a fait #
219            newpackinyear=$((    ${year_end}  - ${year_begin}        ))
220            newpackinyear=$(( $newpackinyear + 1 ))
221            [[ ${newpackinyear} -lt 1 ]] && newpackinyear=1
222            for taille in `head  ${IGCM_TMP}/${$}.size_pack_${type_file}.txt`
223            do 
224                [[ ${taille} -lt ${size_pack_min} ]] && period_tmp=${newpackinyear}
225                [[ ${taille} -gt ${size_pack_max} ]] && period_tmp=$(( ${size_pack_max} * ${newpackinyear} / ${taille} ))
226                [[ ${taille} -ge ${size_pack_min} && ${taille} -le ${size_pack_max} ]] && period_tmp=${newpackinyear}
227                [[ ${period_tmp} -lt ${new_period} ]] && new_period=${period_tmp}
228            done
229        fi
230    done
231fi
232DEM_log -1 "taille=${taille}"
233DEM_log -1 "new_period=${new_period}"
234
235# on veut que la taille de pack soit de 1 2 5 10 20 50 ou 100 ans
236# sauf si newperiod = nb annee de simul auquel cas on ne tronque pas
237declare -a liste_period=( 1 2 5 10 20 50 100 )
238
239change=0
240for i in 1 2 3 4 5 6 ; do
241    if [[ ${new_period} -lt ${liste_period[i]} && ${change} -eq 0 && ${newpackinyear} -ne 0 ]]
242    then
243        new_period=${liste_period[i-1]}
244        change=1
245    fi
246done
247
248[[ ${new_period} -gt 100 ]] && new_period=100
249
250[[ ${new_period} -eq 0 ]] && new_period=1
251
252[[ "${clean_tmp}" = "yes" ]] && rm -f  ${IGCM_TMP}/${$}.*
253
254echo ${new_period} > ${IGCM_DEM_SIMU}/period_pack.txt
255DEM_log -0 "La nouvelle periode de pack est : ${new_period}Y"
256
257DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} FindSizePackDone
258
259# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
260simuMonitoring_OK "$MonitoringInfo" "$config_card"
261DEM_log -0 "Fin de ${SCRIPT_NAME}"
262
263exit
Note: See TracBrowser for help on using the repository browser.