[1709] | 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 | |
---|
| 14 | config_card=${1} |
---|
| 15 | LISTE_DMNFS=${2} |
---|
| 16 | |
---|
| 17 | # ---- |
---|
[1900] | 18 | export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}} |
---|
[1709] | 19 | export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM} |
---|
| 20 | export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp} |
---|
| 21 | mkdir -p ${IGCM_DEM} |
---|
| 22 | mkdir -p ${IGCM_TMP} |
---|
| 23 | clean_tmp=${clean_tmp:-yes} |
---|
| 24 | EXE_DIR=$(dirname ${0}) |
---|
| 25 | SCRIPT_NAME=$(basename ${0} ) |
---|
| 26 | source ${EXE_DIR}/DEM_utilities.sh |
---|
[1822] | 27 | |
---|
| 28 | # gpdebug : verif si le present script a ete execute jusqu'au bout ######### |
---|
| 29 | MonitoringInfo="${SCRIPT_NAME}-->OK" |
---|
| 30 | simuMonitoring_check "$MonitoringInfo" "$config_card" |
---|
| 31 | |
---|
| 32 | # gpdebug : Execute la function errorReceive() si reception d'un signal TERM |
---|
| 33 | trap 'DEM_errorReceive' TERM ######## |
---|
| 34 | |
---|
| 35 | # gpdebug : on augmente la liste des proc à détruire en cas d'erreur bloquante du présent proc |
---|
| 36 | export listPID="$$ ${listPID}" ######### |
---|
| 37 | |
---|
[1709] | 38 | DEM_log -0 "Demmarrage de ${SCRIPT_NAME}" |
---|
[1900] | 39 | cd ${EXE_DIR} |
---|
[1709] | 40 | # ---- |
---|
| 41 | |
---|
| 42 | eval $(grep JobName ${config_card} ) |
---|
| 43 | eval $(grep PATH_SIMUL_FULL ${config_card} ) |
---|
| 44 | eval $(grep DateBegin ${config_card} ) |
---|
| 45 | eval $(grep DateEnd ${config_card} ) |
---|
| 46 | eval $(grep IGCM_DEM_SIMU ${config_card} ) |
---|
| 47 | |
---|
| 48 | DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} ) |
---|
[1822] | 49 | # gpdebug : si c'est une premiere exec (pas une reprise) |
---|
| 50 | if [[ "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" |
---|
[1709] | 53 | fi |
---|
| 54 | |
---|
| 55 | DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} FindSizePackRunning |
---|
| 56 | # Periodicite du pack (20 ans par defaut) |
---|
| 57 | period_pack=20Y |
---|
| 58 | periodpackinyear=$( echo ${period_pack} | sed -e 's/[yY]//' ) |
---|
| 59 | |
---|
| 60 | # Taille max et min que devra avoir un pack en octet (20Go - 70Go) |
---|
| 61 | size_pack_max=70000000000 |
---|
| 62 | size_pack_min=20000000000 |
---|
| 63 | |
---|
| 64 | SIMUL=${PATH_SIMUL_FULL}/ |
---|
| 65 | |
---|
| 66 | # Nettoyons les tests precedents .... |
---|
| 67 | rm -f ${IGCM_DEM_SIMU}/info_Output.txt |
---|
| 68 | rm -f ${IGCM_DEM_SIMU}/info_name_file.txt |
---|
| 69 | |
---|
| 70 | # 1- Trouver tous les repertoires d'Output |
---|
| 71 | DEM_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 |
---|
| 80 | DEM_log -1 "Recherche des noms de fichiers Output" |
---|
| 81 | |
---|
| 82 | sed -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 / |
---|
| 85 | cat ${IGCM_TMP}/${$}.info_tmp.txt | grep -v "/" > ${IGCM_TMP}/${$}.info_tmp_bis.txt |
---|
| 86 | |
---|
| 87 | |
---|
[1736] | 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 |
---|
[1709] | 90 | |
---|
| 91 | # On retire les doublons de la liste précédent |
---|
[1736] | 92 | awk '{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 |
---|
[1709] | 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 |
---|
| 102 | DEM_log -1 "Creation de la liste des fichiers" |
---|
| 103 | |
---|
| 104 | for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt` |
---|
| 105 | do |
---|
| 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 |
---|
| 114 | done |
---|
| 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 |
---|
| 119 | DEM_log -1 "Debut recherche taille de pack" |
---|
| 120 | # Recherche des dates du premier pack |
---|
| 121 | |
---|
| 122 | year_begin=$( echo ${DateBegin} | cut -c 1-4 ) |
---|
| 123 | month_begin=$( echo ${DateBegin} | cut -c 5-6 ) |
---|
| 124 | year_end=$( echo ${DateEnd} | cut -c 1-4 ) |
---|
| 125 | month_end=$( echo ${DateEnd} | cut -c 5-6 ) |
---|
| 126 | |
---|
| 127 | date_begin_pack=${DateBegin} |
---|
| 128 | date_end_simulation=${DateEnd} |
---|
| 129 | |
---|
| 130 | month_begin_pack=${month_begin} |
---|
| 131 | year_begin_pack=${year_begin} |
---|
| 132 | |
---|
| 133 | number_pack=1 |
---|
| 134 | |
---|
| 135 | # on ne fait le calcul que pour les dix premiers pack (donc 20 * 10 = 200 ans) |
---|
[2027] | 136 | # cela doit donner un echantillon suffisant |
---|
| 137 | date_begin_pack=`echo $date_begin_pack|sed 's/^0*//'` |
---|
| 138 | date_end_simulation=`echo $date_end_simulation|sed 's/^0*//'` |
---|
[1709] | 139 | while [[ ${date_begin_pack} -le ${date_end_simulation} && ${number_pack} -le 10 ]] |
---|
| 140 | do |
---|
| 141 | |
---|
| 142 | month_end_pack=${month_begin_pack} |
---|
[2027] | 143 | year_end_pack=$(( 10#${year_begin_pack} + ${periodpackinyear} )) |
---|
[1709] | 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 |
---|
[1920] | 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 |
---|
[1709] | 182 | done |
---|
| 183 | |
---|
[1921] | 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 | |
---|
[1709] | 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 | |
---|
| 193 | done |
---|
| 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 | |
---|
| 201 | new_period=999999 |
---|
[1851] | 202 | newpackinyear=0 |
---|
[2027] | 203 | if [[ -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} )) |
---|
[2130] | 212 | [[ ${taille} -gt ${size_pack_max} ]] && period_tmp=$(( ${size_pack_max} * ${periodpackinyear} / ${taille} )) |
---|
[2027] | 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 |
---|
[1709] | 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 # |
---|
[2027] | 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} |
---|
[2130] | 225 | [[ ${taille} -gt ${size_pack_max} ]] && period_tmp=$(( ${size_pack_max} * ${newpackinyear} / ${taille} )) |
---|
[2027] | 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 |
---|
| 231 | fi |
---|
[1709] | 232 | DEM_log -1 "taille=${taille}" |
---|
| 233 | DEM_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 |
---|
[1851] | 236 | # sauf si newperiod = nb annee de simul auquel cas on ne tronque pas |
---|
[1709] | 237 | declare -a liste_period=( 1 2 5 10 20 50 100 ) |
---|
| 238 | |
---|
| 239 | change=0 |
---|
| 240 | for i in 1 2 3 4 5 6 ; do |
---|
[2130] | 241 | if [[ ${new_period} -lt ${liste_period[i]} && ${change} -eq 0 && ${newpackinyear} -ne 0 ]] |
---|
[1709] | 242 | then |
---|
| 243 | new_period=${liste_period[i-1]} |
---|
| 244 | change=1 |
---|
| 245 | fi |
---|
| 246 | done |
---|
| 247 | |
---|
| 248 | [[ ${new_period} -gt 100 ]] && new_period=100 |
---|
| 249 | |
---|
[1962] | 250 | [[ ${new_period} -eq 0 ]] && new_period=1 |
---|
| 251 | |
---|
[1709] | 252 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.* |
---|
| 253 | |
---|
| 254 | echo ${new_period} > ${IGCM_DEM_SIMU}/period_pack.txt |
---|
| 255 | DEM_log -0 "La nouvelle periode de pack est : ${new_period}Y" |
---|
| 256 | |
---|
| 257 | DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} FindSizePackDone |
---|
| 258 | |
---|
[1822] | 259 | # gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi |
---|
| 260 | simuMonitoring_OK "$MonitoringInfo" "$config_card" |
---|
[1709] | 261 | DEM_log -0 "Fin de ${SCRIPT_NAME}" |
---|
| 262 | |
---|
| 263 | exit |
---|