source: TOOLS/PACK_IPSL/find_size_pack.sh @ 2010

Last change on this file since 2010 was 1962, checked in by aclsce, 11 years ago

Fixed some bugs.

File size: 11.1 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
57# Periodicite du pack (20 ans par defaut)
58period_pack=20Y
59periodpackinyear=$( echo ${period_pack} | sed -e 's/[yY]//' ) 
60
61# Taille max et min que devra avoir un pack en octet (20Go - 70Go)
62size_pack_max=70000000000
63size_pack_min=20000000000
64
65SIMUL=${PATH_SIMUL_FULL}/
66
67# Nettoyons les tests precedents ....
68rm -f ${IGCM_DEM_SIMU}/info_Output.txt
69rm -f ${IGCM_DEM_SIMU}/info_name_file.txt
70
71# 1- Trouver tous les repertoires d'Output
72DEM_log -1 "Recherche des repertoires Output"
73
74#grep ${SIMUL} ${LISTE_DMNFS} > ${IGCM_TMP}/${$}.info_tmp.txt
75#grep "/Output/"  ${IGCM_TMP}/${$}.info_tmp.txt >  ${IGCM_TMP}/${$}.info_tmp_2.txt
76#awk '{print $(NF-2) " " $(NF-1)}' ${IGCM_TMP}/${$}.info_tmp_2.txt > ${IGCM_DEM_SIMU}/info_Output.txt
77
78[[ "${clean_tmp}" = "yes" ]] && rm -f   ${IGCM_TMP}/${$}.info_tmp.txt  ${IGCM_TMP}/${$}.info_tmp_2.txt
79
80# 2- Trouver la liste des noms des fichiers d'Output
81DEM_log -1 "Recherche des noms de fichiers Output"
82
83sed -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
84
85#on enleve si des fichiers ne repondent pas au critere et sont donc encore en /
86cat ${IGCM_TMP}/${$}.info_tmp.txt | grep -v "/" > ${IGCM_TMP}/${$}.info_tmp_bis.txt
87
88
89## On enleve mesh_mask qui est un cas particulier a traiter ulterieurement
90#sed '/mesh_mask/d' ${IGCM_TMP}/${$}.info_tmp_bis.txt >  ${IGCM_TMP}/${$}.info_tmp_2.txt
91
92# On retire les doublons de la liste précédent
93awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <  ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_DEM_SIMU}/info_name_file.txt
94[[ "${clean_tmp}" = "yes" ]] && rm -f  ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt
95
96
97#!!!# Reduction de la taille du probleme pour test
98# grep 1M_cpl_atm.nc  ${IGCM_DEM_SIMU}/info_name_file.txt >  ${IGCM_DEM_SIMU}/info_name_file.txt.tmp
99# grep 1M_grid_T.nc  ${IGCM_DEM_SIMU}/info_name_file.txt >>  ${IGCM_DEM_SIMU}/info_name_file.txt.tmp
100# mv ${IGCM_DEM_SIMU}/info_name_file.txt.tmp ${IGCM_DEM_SIMU}/info_name_file.txt
101
102# On cree la liste des fichiers pour chaque type_file
103DEM_log -1 "Creation de la liste des fichiers"
104
105for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
106do
107#for type_file in 1D_cpl_atm.nc ; do
108    DEM_log -1 "Traitement type de fichier = ${type_file}"
109    grep ${type_file} ${IGCM_DEM_SIMU}/liste_output_files_config.txt >  ${IGCM_TMP}/${$}.info_${type_file}.txt
110    # cette liste comporte en premiere colonne la taille et en deuxieme le path du fichier
111    # on classe la liste par ordre alphabetique des path des fichiers
112    sort -k 2  ${IGCM_TMP}/${$}.info_${type_file}.txt >  ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp
113    cp ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp  ${IGCM_TMP}/${$}.info_${type_file}.txt
114    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp
115done
116
117
118# 3- Maintenant pour chaque type de fichier de sortie nous allons calculer la
119# taille qu'aurait le pack de {periodpackinyear}ans
120DEM_log -1 "Debut recherche taille de pack"
121
122# Recherche des dates du premier pack
123
124year_begin=$(  echo ${DateBegin} | cut -c 1-4 )
125month_begin=$( echo ${DateBegin} | cut -c 5-6 )
126year_end=$(    echo ${DateEnd}   | cut -c 1-4 )
127month_end=$(   echo ${DateEnd}   | cut -c 5-6 )
128
129date_begin_pack=${DateBegin}
130date_end_simulation=${DateEnd}
131
132month_begin_pack=${month_begin}
133year_begin_pack=${year_begin}
134
135number_pack=1
136
137# on ne fait le calcul que pour les dix premiers pack (donc 20 * 10 =  200 ans)
138# cela doit donner un echantillon suffisant
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=$(( ${year_begin_pack} + ${periodpackinyear} ))
144   
145    date_end_pack=${year_end_pack}${month_end_pack}01
146
147    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}"
148    # on travaille pour chaque type de fichiers
149    for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
150    do
151    #for type_file in 1M_grid_T.nc ; do
152        DEM_log -3 ${type_file} ${number_pack}
153        taille=0
154        #il faut les passer en revue et calculer par tranche de period_pack leur somme
155        for file in `awk '{print $2}'  ${IGCM_TMP}/${$}.info_${type_file}.txt` ; do 
156            #extraire la date de debut et la date de fin de la periode d'output traitee par le fichier   
157            extract_date_file=$( echo ${file}             | sed "s%.*${JobName}_%%"            )
158            date_debut=$(        echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g'    )
159            date_fin=$(          echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' )
160            if [  ${date_debut} -lt ${date_end_pack} ]
161            then
162                if [ ${date_fin} -ge ${date_begin_pack} ]
163                then
164                    grep ${file}  ${IGCM_TMP}/${$}.info_${type_file}.txt >>  ${IGCM_TMP}/${$}.info_${type_file}_${number_pack}.txt
165                    # on efface le fichier de la liste pour ne pas travailler dessus pour le prochain pack
166                    grep -v ${file} ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
167                    cp ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt
168                    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
169                fi
170            else
171            # comme la liste est classee par ordre alphabetique --> par ordre croissant des periodes de sorties
172            # des que un fichier n'est plus dans le pack on peut sortir c'est qu'on les a tous.
173                break
174            fi
175           
176        done
177       # on fait la somme par periodpack et par type de fichier de la taille qu'aurait le pack
178        if [ -f ${IGCM_TMP}/${$}.info_${type_file}_${number_pack}.txt ]
179        then
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        fi
183    done
184   
185    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}"
186
187    month_begin_pack=${month_end_pack}
188    year_begin_pack=${year_end_pack}
189    date_begin_pack=${year_begin_pack}${month_begin_pack}01
190   
191    number_pack=$(( ${number_pack} + 1 ))
192
193
194done
195
196# Pour chaque type de fichier on verifie si toutes les tailles sont dans
197# la fourchette size_pack_min / size_pack_max
198# Si une taille est plus petite
199# attention il ne faut pas tenir compte du dernier pack qui peut etre
200# inferieur a periodpack
201
202new_period=999999
203newpackinyear=0
204
205for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
206do
207    nb_line=$(cat ${IGCM_TMP}/${$}.size_pack_${type_file}.txt | wc -l )
208    if [ ${nb_line} -gt 1 ]
209    then
210        for taille in `head -n -1  ${IGCM_TMP}/${$}.size_pack_${type_file}.txt`
211        do 
212            [[ ${taille} -lt ${size_pack_min} ]] && period_tmp=$(( ${size_pack_min} * ${periodpackinyear} / ${taille} ))
213            [[ ${taille} -gt ${size_pack_max} ]] && period_tmp=$(( ${size_pack_min} * ${periodpackinyear} / ${taille} ))
214            [[ ${taille} -ge ${size_pack_min} && ${taille} -le ${size_pack_max} ]] && period_tmp=${periodpackinyear}
215            [[ ${period_tmp} -lt ${new_period} ]] && new_period=${period_tmp}
216        done
217    else
218        # Dans ce cas la il n'y avait pas assez de fichiers pour remplir une periode complete #
219        # il faut donc commencer par calculer la taille du pack que l'on a fait #
220        newpackinyear=$((    ${year_end}  - ${year_begin}        ))
221        newpackinyear=$(( $newpackinyear + 1 ))
222        [[ ${newpackinyear} -lt 1 ]] && newpackinyear=1
223       
224        for taille in `head  ${IGCM_TMP}/${$}.size_pack_${type_file}.txt`
225        do 
226            [[ ${taille} -lt ${size_pack_min} ]] && period_tmp=${newpackinyear}
227            [[ ${taille} -gt ${size_pack_max} ]] && period_tmp=$(( ${size_pack_min} * ${newpackinyear} / ${taille} ))
228            [[ ${taille} -ge ${size_pack_min} && ${taille} -le ${size_pack_max} ]] && period_tmp=${newpackinyear}
229            [[ ${period_tmp} -lt ${new_period} ]] && new_period=${period_tmp}
230        done
231       
232    fi
233done
234
235DEM_log -1 "taille=${taille}"
236DEM_log -1 "new_period=${new_period}"
237
238# on veut que la taille de pack soit de 1 2 5 10 20 50 ou 100 ans
239# sauf si newperiod = nb annee de simul auquel cas on ne tronque pas
240declare -a liste_period=( 1 2 5 10 20 50 100 )
241
242change=0
243for i in 1 2 3 4 5 6 ; do
244    if [[ ${new_period} -lt ${liste_period[i]} && ${change} -eq 0 && ${newpackinyear} -eq 0 ]]
245    then
246        new_period=${liste_period[i-1]}
247        change=1
248    fi
249done
250
251[[ ${new_period} -gt 100 ]] && new_period=100
252
253[[ ${new_period} -eq 0 ]] && new_period=1
254
255[[ "${clean_tmp}" = "yes" ]] && rm -f  ${IGCM_TMP}/${$}.*
256
257echo ${new_period} > ${IGCM_DEM_SIMU}/period_pack.txt
258DEM_log -0 "La nouvelle periode de pack est : ${new_period}Y"
259
260DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} FindSizePackDone
261
262# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
263simuMonitoring_OK "$MonitoringInfo" "$config_card"
264DEM_log -0 "Fin de ${SCRIPT_NAME}"
265
266exit
Note: See TracBrowser for help on using the repository browser.