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