#!/bin/bash # Script permettant de creer les listes de fichiers pour ncrcat # si un trou est detecte dans la simulation alors cette liste sera # pour un tar # $1= PATH/config_card d'une simulation avec # TagName/JobName/ExperimentName/SpaceName/DateBegin/DateEnd/PATH_SIMUL # Pour commencer on travaille avec le fichier information_dmnfs # /cscratch/cont003/p86mart/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2011-09-21 config_card=${1} LISTE_DMNFS=${2} # Declaration des variables # ---- export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}} export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM} export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp} mkdir -p ${IGCM_DEM} mkdir -p ${IGCM_TMP} clean_tmp=${clean_tmp:-yes} EXE_DIR=$(dirname ${0} ) SCRIPT_NAME=$(basename ${0} ) source ${EXE_DIR}/DEM_utilities.sh # gpdebug : verif si le present script a ete execute jusqu'au bout ######### MonitoringInfo="${SCRIPT_NAME}-->OK" simuMonitoring_check "$MonitoringInfo" "$config_card" # gpdebug : Execute la function errorReceive() si reception d'un signal TERM trap 'DEM_errorReceive' TERM ######## # gpdebug : on augmente la liste des proc à détruire en cas d'erreur bloquante du présent proc export listPID="$$ ${listPID}" ######### DEM_log -0 "Demmarrage de ${SCRIPT_NAME}" cd ${JOB_DIR} # ---- DEM_log -0 "config_card : ${config_card}" DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}" eval $(grep JobName ${config_card}) eval $(grep PATH_SIMUL_FULL ${config_card}) eval $(grep DateBegin ${config_card}) eval $(grep DateEnd ${config_card}) eval $(grep IGCM_DEM_SIMU ${config_card}) SIMUL=${PATH_SIMUL_FULL}/${JobName} DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} ) # gpdebug : si c'est une premiere exec (pas une reprise) if [[ "x${execEveryStep}" == "1" ]] && [[ "${DEM_state}" != "FindSizePackDone" ]] ; then DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Etat incorrect dans ${IGCM_DEM}/config_card.liste" fi DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackRunning # creation des repertoires with_tar et with_ncrcat OUTPUT_NCRCAT=${IGCM_DEM_SIMU}/output_ncrcat OUTPUT_TAR=${IGCM_DEM_SIMU}/output_tar mkdir -p ${OUTPUT_NCRCAT} mkdir -p ${OUTPUT_TAR} # lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt period_pack=$( awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt ) year_begin=$( echo ${DateBegin} | cut -c 1-4 ) month_begin=$( echo ${DateBegin} | cut -c 5-6 ) year_end=$( echo ${DateEnd} | cut -c 1-4 ) month_end=$( echo ${DateEnd} | cut -c 5-6 ) awk '{print $2}' ${IGCM_DEM_SIMU}/liste_output_files_config.txt > ${IGCM_DEM_SIMU}/info_Output_light.txt # on cree la liste des fichiers pour chaque type_file for type_file in $( awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt ) ; do #sed -e "/${type_file}/!d" ${IGCM_DEM_SIMU}/info_Output_light.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt grep ${type_file} ${IGCM_DEM_SIMU}/info_Output_light.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt sort -u ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp cp ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp done # 3- Maintenant pour chaque type de fichier de sortie nous allons creer la liste # des fichiers contenus dans chaque pack # Recherche des dates du premier pack date_begin_pack=${DateBegin} date_end_simulation=${DateEnd} month_begin_pack=${month_begin} year_begin_pack=${year_begin} number_pack=1 # date_begin_pack=`echo $date_begin_pack|sed 's/^0*//'` date_end_simulation=`echo $date_end_simulation|sed 's/^0*//'` while [[ ${date_begin_pack} -le ${date_end_simulation} ]] do month_end_pack=${month_begin_pack} year_end_pack=$(( ${year_begin_pack} +${period_pack} )) date_end_pack=${year_end_pack}${month_end_pack}01 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}" DEM_log -2 "Entree boucle 3 : date_end_pack : ${date_end_pack}" for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt` do DEM_log -2 "Boucle 3 : ${type_file} ${number_pack}" taille=0 # On passe en revue chaque type de fichier for file in `awk '{print $0}' ${IGCM_TMP}/${$}.info_${type_file}.txt` do # Extraire la date de debut et la date de fin de la periode d'output traitee par le fichier extract_date_file=$( echo ${file} | sed -e "s%.*${JobName}_%%" ) date_debut=$( echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' ) date_fin=$( echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' ) if [ ${date_debut} -lt ${date_end_pack} ] then if [ ${date_fin} -ge ${date_begin_pack} ] then echo ${file} >> ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list echo ${date_debut} | cut -c 1-6 >> ${IGCM_TMP}/${$}.date_${type_file}.txt grep -v ${file} ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp cp ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp fi else break fi done if [[ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ]] ; then sort -u ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_TMP}/${$}.date_tmp.txt mv ${IGCM_TMP}/${$}.date_tmp.txt ${IGCM_TMP}/${$}.date_${type_file}.txt else DEM_log -2 "Pas de fichier cree : ${IGCM_TMP}/${$}.date_${type_file}.txt - Date_end_pack : ${date_end_pack}" fi #On renomme le fichier ncrcat avec la date reelle de fin et non pas la premiere date suivant la fin #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 if [[ -f ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list ]]; then sort ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list > ${IGCM_TMP}/${$}.ncrcat.tmp first_file=$(head -n 1 ${IGCM_TMP}/${$}.ncrcat.tmp ) extract_date_file=$( echo ${first_file} | sed -e "s/.*${JobName}_//" ) date_debut=$(echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' ) last_file=$(tail -n 1 ${IGCM_TMP}/${$}.ncrcat.tmp ) extract_date_file=$( echo ${last_file} | sed -e "s/.*${JobName}_//" ) date_fin=$(echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' ) mv ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list ${OUTPUT_NCRCAT}/${JobName}_${date_debut}_${date_fin}_${type_file}.list fi done month_begin_pack=${month_end_pack} year_begin_pack=${year_end_pack} date_begin_pack=${year_begin_pack}${month_begin_pack}01 number_pack=$(( ${number_pack} + 1 )) 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}" DEM_log -2 "Sortie boucle : date_begin_pack : ${date_begin_pack}" done ## Recherche des trous eventuels dans cette simulation ## Creation de la liste des annees comprisent entre DateBegin et DateEnd >> ${IGCM_TMP}/${$}.liste_date.txt force_sequence (){ awk '{ if (NR==1) {avant=$1; print $1} else { for (i=avant+1 ; i<=$1 ; i++) printf "%04i\n", i}}' } DEM_log -1 "year_begin - year_end : ${year_begin} - ${year_end}" echo ${year_begin} > ${IGCM_TMP}/${$}.liste_date.txt echo ${year_end} >> ${IGCM_TMP}/${$}.liste_date.txt force_sequence < ${IGCM_TMP}/${$}.liste_date.txt > ${IGCM_TMP}/${$}.tmp ; mv ${IGCM_TMP}/${$}.tmp ${IGCM_TMP}/${$}.liste_date.txt ## il faut savoir si les fichiers d'output sont annuels ou mensuels ? file=$( head -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt ) extract_date_file=$( echo ${file} | sed -e "s%.*${JobName}_%%" ) date_debut=$( echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g') date_fin=$( echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g') month_begin=$( echo ${date_debut} | cut -c 5-6 ) month_end=$( echo ${date_fin} | cut -c 5-6 ) year_debut=$( echo ${date_debut} | cut -c 1-4 ) year_fin=$( echo ${date_fin} | cut -c 1-4 ) DEM_log -1 "Recherche de la frequence" if [ ${month_end} -eq ${month_begin} ] then DEM_log -1 "Mensuel" while read an ; do for month in 1 2 3 4 5 6 7 8 9 10 11 12 ; do printf "%s%02d\n" ${an} ${month} >> ${IGCM_TMP}/${$}.toutes_dates done done < ${IGCM_TMP}/${$}.liste_date.txt [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_date.txt else freqwriteyear=0 #la frequence peut être de plusieurs mois (<1 an) #ou de plusieurs années #attention une simulation ne commence pas obligatoirement au 1er janvier if [[ ${year_debut} -eq ${year_fin} ]]; then freqwritemonth=$(( ${month_end} - ${month_begin} + 1 )) else freqwritemonth=$(( 12 + ${month_end} - ${month_begin} + 1 )) fi if [[ $freqwritemonth -eq 12 ]]; then ## frequence annuelle if [[ ${year_debut} -eq ${year_fin} ]]; then freqwriteyear=1 else if [[ ${month_end} -gt {month_begin} ]]; then freqwriteyear=$(( ${year_fin} - ${year_debut} + 1 )) else freqwriteyear=$(( ${year_fin} - ${year_debut} )) fi fi fi if [[ $freqwriteyear -eq 0 ]]; then DEM_log -1 "mensuel avec sorties tous les $freqwritemonth mois " while read an ; do i=${month_begin} while [[ ${i} -le 12 ]] ; do printf "%s%02d\n" ${an} ${i} >> ${IGCM_TMP}/${$}.toutes_dates i=$(( $i + $freqwritemonth )) done done < ${IGCM_TMP}/${$}.liste_date.txt else DEM_log -1 "annuel avec sorties tous les $freqwriteyear month " i=${month_begin} y=${year_debut} while [[ $y -le ${year_end} ]]; do # attention year_fin = annee de fin du premier fichier / year_end = annee de fin de la simulation printf "%s%02d\n" ${y} ${i} >> ${IGCM_TMP}/${$}.toutes_dates y=$(( $y + $freqwriteyear )) done fi fi # Maintenant il faut comparer la liste des dates avec la liste des dates des fichiers # et pour des dates manquantes transformer le fichier ncrcat_date correspondant en fichier # tar_date DEM_log -1 "Recherche des dates manquantes" for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt` do DEM_log -2 "${type_file}" rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list if [ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ] ; then join -v 1 ${IGCM_TMP}/${$}.toutes_dates ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_DEM_SIMU}/${type_file}_manquant.list # On change le fichier ncrcat pour chaque date manquante en fichier tar if [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then for date in `awk '{print $0}' ${IGCM_DEM_SIMU}/${type_file}_manquant.list` ; do ### AC : test si le fichier de list existe dans output_ncrcat (si non ca veut dire qu'il deja ete move dans output_tar) nb_files=$(ls ${OUTPUT_NCRCAT} | grep ${JobName} | grep "${type_file}.list" | wc -l ) if [ "x$nb_files" != "x0" ] ; then ls -l ${OUTPUT_NCRCAT}/${JobName}_*_${type_file}.list > ${IGCM_TMP}/${$}.liste_ncrcat for pack in $( awk '{print $9}' ${IGCM_TMP}/${$}.liste_ncrcat ) ; do extract_date_file=$( echo ${pack} | sed -e "s%.*${JobName}_%%" ) date_debut=$( echo ${extract_date_file} | sed 's%\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6 ) date_fin=$( echo ${extract_date_file} | sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6 ) #on retire les eventuels zero pour eviter de tomber sur des dates de type 08 ou 09 date=`echo $date|sed 's/^0*//'` date_debut=`echo $date_debut|sed 's/^0*//'` date_fin=`echo $date_fin|sed 's/^0*//'` if [[ ${date} -ge ${date_debut} && ${date} -lt ${date_fin} ]]; then mv ${pack} ${OUTPUT_TAR}/. break else rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list fi done fi [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_ncrcat done elif [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && ! -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list fi fi rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list done DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackDone # gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi simuMonitoring_OK "$MonitoringInfo" "$config_card" DEM_log -0 "Fin de ${SCRIPT_NAME}" exit