source: TOOLS/PACK_IPSL/find_size_pack.sh @ 1906

Last change on this file since 1906 was 1900, checked in by aclsce, 12 years ago

Modified to write log files in TMP_MIGR_DATA directory (instead of current directory)

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