[2136] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # Script permettant de creer les listes de fichiers pour ncrcat |
---|
| 4 | # si un trou est detecte dans la simulation alors cette liste sera |
---|
| 5 | # pour un tar |
---|
| 6 | |
---|
| 7 | # $1= PATH/config_card d'une simulation avec |
---|
| 8 | # TagName/JobName/ExperimentName/SpaceName/DateBegin/DateEnd/PATH_SIMUL |
---|
| 9 | |
---|
| 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 | # Declaration des variables |
---|
| 18 | |
---|
| 19 | # ---- |
---|
| 20 | export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}} |
---|
| 21 | export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM} |
---|
| 22 | export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp} |
---|
| 23 | mkdir -p ${IGCM_DEM} |
---|
| 24 | mkdir -p ${IGCM_TMP} |
---|
| 25 | clean_tmp=${clean_tmp:-yes} |
---|
| 26 | EXE_DIR=$(dirname ${0} ) |
---|
| 27 | SCRIPT_NAME=$(basename ${0} ) |
---|
| 28 | source ${EXE_DIR}/DEM_utilities.sh |
---|
| 29 | |
---|
| 30 | # gpdebug : verif si le present script a ete execute jusqu'au bout ######### |
---|
| 31 | MonitoringInfo="${SCRIPT_NAME}-->OK" |
---|
| 32 | simuMonitoring_check "$MonitoringInfo" "$config_card" |
---|
| 33 | |
---|
| 34 | # gpdebug : Execute la function errorReceive() si reception d'un signal TERM |
---|
| 35 | trap 'DEM_errorReceive' TERM ######## |
---|
| 36 | |
---|
| 37 | # gpdebug : on augmente la liste des proc à détruire en cas d'erreur bloquante du présent proc |
---|
| 38 | export listPID="$$ ${listPID}" ######### |
---|
| 39 | |
---|
| 40 | DEM_log -0 "Demmarrage de ${SCRIPT_NAME}" |
---|
| 41 | cd ${JOB_DIR} |
---|
| 42 | # ---- |
---|
| 43 | |
---|
| 44 | DEM_log -0 "config_card : ${config_card}" |
---|
| 45 | DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}" |
---|
| 46 | |
---|
| 47 | eval $(grep JobName ${config_card}) |
---|
| 48 | eval $(grep PATH_SIMUL_FULL ${config_card}) |
---|
| 49 | eval $(grep DateBegin ${config_card}) |
---|
| 50 | eval $(grep DateEnd ${config_card}) |
---|
| 51 | eval $(grep IGCM_DEM_SIMU ${config_card}) |
---|
| 52 | |
---|
| 53 | SIMUL=${PATH_SIMUL_FULL}/${JobName} |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} ) |
---|
| 57 | # gpdebug : si c'est une premiere exec (pas une reprise) |
---|
| 58 | if [[ "x${execEveryStep}" == "1" ]] && [[ "${DEM_state}" != "FindSizePackDone" ]] ; then |
---|
| 59 | DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Etat incorrect dans ${IGCM_DEM}/config_card.liste" |
---|
| 60 | fi |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackRunning |
---|
| 64 | |
---|
| 65 | # creation des repertoires with_tar et with_ncrcat |
---|
| 66 | OUTPUT_NCRCAT=${IGCM_DEM_SIMU}/output_ncrcat |
---|
| 67 | OUTPUT_TAR=${IGCM_DEM_SIMU}/output_tar |
---|
| 68 | |
---|
| 69 | mkdir -p ${OUTPUT_NCRCAT} |
---|
| 70 | mkdir -p ${OUTPUT_TAR} |
---|
| 71 | |
---|
| 72 | # lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt |
---|
| 73 | period_pack=$( awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt ) |
---|
| 74 | |
---|
| 75 | year_begin=$( echo ${DateBegin} | cut -c 1-4 ) |
---|
| 76 | month_begin=$( echo ${DateBegin} | cut -c 5-6 ) |
---|
| 77 | year_end=$( echo ${DateEnd} | cut -c 1-4 ) |
---|
| 78 | month_end=$( echo ${DateEnd} | cut -c 5-6 ) |
---|
| 79 | |
---|
| 80 | awk '{print $2}' ${IGCM_DEM_SIMU}/liste_output_files_config.txt > ${IGCM_DEM_SIMU}/info_Output_light.txt |
---|
| 81 | |
---|
| 82 | # on cree la liste des fichiers pour chaque type_file |
---|
| 83 | for type_file in $( awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt ) ; do |
---|
| 84 | #sed -e "/${type_file}/!d" ${IGCM_DEM_SIMU}/info_Output_light.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt |
---|
| 85 | grep ${type_file} ${IGCM_DEM_SIMU}/info_Output_light.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt |
---|
| 86 | sort -u ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp |
---|
| 87 | cp ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt |
---|
| 88 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp |
---|
| 89 | done |
---|
| 90 | |
---|
| 91 | # 3- Maintenant pour chaque type de fichier de sortie nous allons creer la liste |
---|
| 92 | # des fichiers contenus dans chaque pack |
---|
| 93 | |
---|
| 94 | # Recherche des dates du premier pack |
---|
| 95 | |
---|
| 96 | date_begin_pack=${DateBegin} |
---|
| 97 | date_end_simulation=${DateEnd} |
---|
| 98 | |
---|
| 99 | month_begin_pack=${month_begin} |
---|
| 100 | year_begin_pack=${year_begin} |
---|
| 101 | |
---|
| 102 | number_pack=1 |
---|
| 103 | |
---|
| 104 | # |
---|
| 105 | date_begin_pack=`echo $date_begin_pack|sed 's/^0*//'` |
---|
| 106 | date_end_simulation=`echo $date_end_simulation|sed 's/^0*//'` |
---|
| 107 | |
---|
| 108 | while [[ ${date_begin_pack} -le ${date_end_simulation} ]] |
---|
| 109 | do |
---|
| 110 | |
---|
| 111 | month_end_pack=${month_begin_pack} |
---|
| 112 | year_end_pack=$(( ${year_begin_pack} +${period_pack} )) |
---|
| 113 | |
---|
| 114 | date_end_pack=${year_end_pack}${month_end_pack}01 |
---|
| 115 | |
---|
| 116 | DEM_log -2 "Entree boucle 3 : year_begin_pack month_begin_pack year_end_pack month_end_pack : ${year_begin_pack} ${month_begin_pack} ${year_end_pack} ${month_end_pack}" |
---|
| 117 | DEM_log -2 "Entree boucle 3 : date_end_pack : ${date_end_pack}" |
---|
| 118 | |
---|
| 119 | for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt` |
---|
| 120 | do |
---|
| 121 | DEM_log -2 "Boucle 3 : ${type_file} ${number_pack}" |
---|
| 122 | taille=0 |
---|
| 123 | |
---|
| 124 | # On passe en revue chaque type de fichier |
---|
| 125 | for file in `awk '{print $0}' ${IGCM_TMP}/${$}.info_${type_file}.txt` |
---|
| 126 | do |
---|
| 127 | # Extraire la date de debut et la date de fin de la periode d'output traitee par le fichier |
---|
| 128 | extract_date_file=$( echo ${file} | sed -e "s%.*${JobName}_%%" ) |
---|
| 129 | date_debut=$( echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
| 130 | date_fin=$( echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
| 131 | |
---|
| 132 | if [ ${date_debut} -lt ${date_end_pack} ] |
---|
| 133 | then |
---|
| 134 | if [ ${date_fin} -ge ${date_begin_pack} ] |
---|
| 135 | then |
---|
| 136 | echo ${file} >> ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list |
---|
| 137 | echo ${date_debut} | cut -c 1-6 >> ${IGCM_TMP}/${$}.date_${type_file}.txt |
---|
| 138 | grep -v ${file} ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp |
---|
| 139 | cp ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt |
---|
| 140 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp |
---|
| 141 | fi |
---|
| 142 | else |
---|
| 143 | break |
---|
| 144 | fi |
---|
| 145 | |
---|
| 146 | done |
---|
| 147 | if [[ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ]] ; then |
---|
| 148 | sort -u ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_TMP}/${$}.date_tmp.txt |
---|
| 149 | mv ${IGCM_TMP}/${$}.date_tmp.txt ${IGCM_TMP}/${$}.date_${type_file}.txt |
---|
| 150 | else |
---|
| 151 | DEM_log -2 "Pas de fichier cree : ${IGCM_TMP}/${$}.date_${type_file}.txt - Date_end_pack : ${date_end_pack}" |
---|
| 152 | fi |
---|
| 153 | |
---|
| 154 | #On renomme le fichier ncrcat avec la date reelle de fin et non pas la premiere date suivant la fin |
---|
| 155 | #on renomme egalement en fonction de la date reelle de debut pour le cas des annees < 1000 qui perdent leurs zeros en cour de route |
---|
| 156 | if [[ -f ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list ]]; then |
---|
| 157 | sort ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list > ${IGCM_TMP}/${$}.ncrcat.tmp |
---|
| 158 | |
---|
| 159 | first_file=$(head -n 1 ${IGCM_TMP}/${$}.ncrcat.tmp ) |
---|
| 160 | extract_date_file=$( echo ${first_file} | sed -e "s/.*${JobName}_//" ) |
---|
| 161 | date_debut=$(echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
| 162 | |
---|
| 163 | last_file=$(tail -n 1 ${IGCM_TMP}/${$}.ncrcat.tmp ) |
---|
| 164 | extract_date_file=$( echo ${last_file} | sed -e "s/.*${JobName}_//" ) |
---|
| 165 | date_fin=$(echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
| 166 | mv ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list ${OUTPUT_NCRCAT}/${JobName}_${date_debut}_${date_fin}_${type_file}.list |
---|
| 167 | fi |
---|
| 168 | done |
---|
| 169 | |
---|
| 170 | month_begin_pack=${month_end_pack} |
---|
| 171 | year_begin_pack=${year_end_pack} |
---|
| 172 | date_begin_pack=${year_begin_pack}${month_begin_pack}01 |
---|
| 173 | |
---|
| 174 | number_pack=$(( ${number_pack} + 1 )) |
---|
| 175 | |
---|
| 176 | 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}" |
---|
| 177 | DEM_log -2 "Sortie boucle : date_begin_pack : ${date_begin_pack}" |
---|
| 178 | |
---|
| 179 | done |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | ## Recherche des trous eventuels dans cette simulation |
---|
| 183 | |
---|
| 184 | ## Creation de la liste des annees comprisent entre DateBegin et DateEnd >> ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 185 | force_sequence (){ |
---|
| 186 | awk '{ |
---|
| 187 | if (NR==1) {avant=$1; print $1} |
---|
| 188 | else { for (i=avant+1 ; i<=$1 ; i++) printf "%04i\n", i}}' |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | DEM_log -1 "year_begin - year_end : ${year_begin} - ${year_end}" |
---|
| 192 | |
---|
| 193 | echo ${year_begin} > ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 194 | echo ${year_end} >> ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 195 | |
---|
| 196 | force_sequence < ${IGCM_TMP}/${$}.liste_date.txt > ${IGCM_TMP}/${$}.tmp ; mv ${IGCM_TMP}/${$}.tmp ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | ## il faut savoir si les fichiers d'output sont annuels ou mensuels ? |
---|
| 200 | file=$( head -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt ) |
---|
| 201 | |
---|
| 202 | extract_date_file=$( echo ${file} | sed -e "s%.*${JobName}_%%" ) |
---|
| 203 | date_debut=$( echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g') |
---|
| 204 | date_fin=$( echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g') |
---|
| 205 | month_begin=$( echo ${date_debut} | cut -c 5-6 ) |
---|
| 206 | month_end=$( echo ${date_fin} | cut -c 5-6 ) |
---|
| 207 | year_debut=$( echo ${date_debut} | cut -c 1-4 ) |
---|
| 208 | year_fin=$( echo ${date_fin} | cut -c 1-4 ) |
---|
| 209 | DEM_log -1 "Recherche de la frequence" |
---|
| 210 | if [ ${month_end} -eq ${month_begin} ] |
---|
| 211 | then |
---|
| 212 | DEM_log -1 "Mensuel" |
---|
| 213 | while read an ; do |
---|
| 214 | for month in 1 2 3 4 5 6 7 8 9 10 11 12 ; do |
---|
| 215 | printf "%s%02d\n" ${an} ${month} >> ${IGCM_TMP}/${$}.toutes_dates |
---|
| 216 | done |
---|
| 217 | done < ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 218 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 219 | else |
---|
| 220 | freqwriteyear=0 |
---|
| 221 | #la frequence peut être de plusieurs mois (<1 an) |
---|
| 222 | #ou de plusieurs années |
---|
| 223 | #attention une simulation ne commence pas obligatoirement au 1er janvier |
---|
| 224 | if [[ ${year_debut} -eq ${year_fin} ]]; then |
---|
| 225 | freqwritemonth=$(( ${month_end} - ${month_begin} + 1 )) |
---|
| 226 | else |
---|
| 227 | freqwritemonth=$(( 12 + ${month_end} - ${month_begin} + 1 )) |
---|
| 228 | fi |
---|
| 229 | if [[ $freqwritemonth -eq 12 ]]; then |
---|
| 230 | ## frequence annuelle |
---|
| 231 | if [[ ${year_debut} -eq ${year_fin} ]]; then |
---|
| 232 | freqwriteyear=1 |
---|
| 233 | else |
---|
| 234 | if [[ ${month_end} -gt {month_begin} ]]; then |
---|
| 235 | freqwriteyear=$(( ${year_fin} - ${year_debut} + 1 )) |
---|
| 236 | else |
---|
| 237 | freqwriteyear=$(( ${year_fin} - ${year_debut} )) |
---|
| 238 | fi |
---|
| 239 | fi |
---|
| 240 | fi |
---|
| 241 | |
---|
| 242 | if [[ $freqwriteyear -eq 0 ]]; then |
---|
| 243 | DEM_log -1 "mensuel avec sorties tous les $freqwritemonth mois " |
---|
| 244 | while read an ; do |
---|
| 245 | i=${month_begin} |
---|
| 246 | while [[ ${i} -le 12 ]] ; do |
---|
| 247 | printf "%s%02d\n" ${an} ${i} >> ${IGCM_TMP}/${$}.toutes_dates |
---|
| 248 | i=$(( $i + $freqwritemonth )) |
---|
| 249 | done |
---|
| 250 | done < ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 251 | else |
---|
| 252 | DEM_log -1 "annuel avec sorties tous les $freqwriteyear month " |
---|
| 253 | i=${month_begin} |
---|
| 254 | y=${year_debut} |
---|
| 255 | while [[ $y -le ${year_end} ]]; do # attention year_fin = annee de fin du premier fichier / year_end = annee de fin de la simulation |
---|
| 256 | printf "%s%02d\n" ${y} ${i} >> ${IGCM_TMP}/${$}.toutes_dates |
---|
| 257 | y=$(( $y + $freqwriteyear )) |
---|
| 258 | done |
---|
| 259 | fi |
---|
| 260 | |
---|
| 261 | fi |
---|
| 262 | |
---|
| 263 | # Maintenant il faut comparer la liste des dates avec la liste des dates des fichiers |
---|
| 264 | # et pour des dates manquantes transformer le fichier ncrcat_date correspondant en fichier |
---|
| 265 | # tar_date |
---|
| 266 | DEM_log -1 "Recherche des dates manquantes" |
---|
| 267 | for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt` |
---|
| 268 | do |
---|
| 269 | DEM_log -2 "${type_file}" |
---|
| 270 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 271 | |
---|
| 272 | if [ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ] ; then |
---|
| 273 | join -v 1 ${IGCM_TMP}/${$}.toutes_dates ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 274 | |
---|
| 275 | # On change le fichier ncrcat pour chaque date manquante en fichier tar |
---|
| 276 | if [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then |
---|
| 277 | for date in `awk '{print $0}' ${IGCM_DEM_SIMU}/${type_file}_manquant.list` ; do |
---|
| 278 | ### AC : test si le fichier de list existe dans output_ncrcat (si non ca veut dire qu'il deja ete move dans output_tar) |
---|
| 279 | nb_files=$(ls ${OUTPUT_NCRCAT} | grep ${JobName} | grep "${type_file}.list" | wc -l ) |
---|
| 280 | if [ "x$nb_files" != "x0" ] ; then |
---|
| 281 | ls -l ${OUTPUT_NCRCAT}/${JobName}_*_${type_file}.list > ${IGCM_TMP}/${$}.liste_ncrcat |
---|
| 282 | for pack in $( awk '{print $9}' ${IGCM_TMP}/${$}.liste_ncrcat ) ; do |
---|
| 283 | extract_date_file=$( echo ${pack} | sed -e "s%.*${JobName}_%%" ) |
---|
| 284 | date_debut=$( echo ${extract_date_file} | sed 's%\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6 ) |
---|
| 285 | date_fin=$( echo ${extract_date_file} | sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6 ) |
---|
| 286 | #on retire les eventuels zero pour eviter de tomber sur des dates de type 08 ou 09 |
---|
| 287 | date=`echo $date|sed 's/^0*//'` |
---|
| 288 | date_debut=`echo $date_debut|sed 's/^0*//'` |
---|
| 289 | date_fin=`echo $date_fin|sed 's/^0*//'` |
---|
| 290 | if [[ ${date} -ge ${date_debut} && ${date} -lt ${date_fin} ]]; then |
---|
| 291 | mv ${pack} ${OUTPUT_TAR}/. |
---|
| 292 | break |
---|
| 293 | else |
---|
| 294 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 295 | fi |
---|
| 296 | done |
---|
| 297 | fi |
---|
| 298 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_ncrcat |
---|
| 299 | done |
---|
| 300 | elif [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && ! -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then |
---|
| 301 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 302 | fi |
---|
| 303 | fi |
---|
| 304 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 305 | done |
---|
| 306 | |
---|
| 307 | DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackDone |
---|
| 308 | |
---|
| 309 | # gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi |
---|
| 310 | simuMonitoring_OK "$MonitoringInfo" "$config_card" |
---|
| 311 | |
---|
| 312 | DEM_log -0 "Fin de ${SCRIPT_NAME}" |
---|
| 313 | |
---|
| 314 | exit |
---|