source: TOOLS/PACK_IPSL/find_size_pack.sh @ 1715

Last change on this file since 1715 was 1709, checked in by acosce, 12 years ago

Add tool pack used for ccrt/tgcc migration

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