[1709] | 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 | # ---- |
---|
[1900] | 20 | export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}} |
---|
[1709] | 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 |
---|
[1822] | 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 | |
---|
[1709] | 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 | |
---|
[1822] | 55 | |
---|
[1709] | 56 | DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} ) |
---|
[1822] | 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" |
---|
[1709] | 60 | fi |
---|
| 61 | |
---|
[1822] | 62 | |
---|
[1709] | 63 | DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackRunning |
---|
| 64 | |
---|
[1717] | 65 | # creation des repertoires with_tar et with_ncrcat |
---|
[1728] | 66 | OUTPUT_NCRCAT=${IGCM_DEM_SIMU}/output_ncrcat |
---|
| 67 | OUTPUT_TAR=${IGCM_DEM_SIMU}/output_tar |
---|
[1717] | 68 | |
---|
[1726] | 69 | mkdir -p ${OUTPUT_NCRCAT} |
---|
| 70 | mkdir -p ${OUTPUT_TAR} |
---|
[1717] | 71 | |
---|
[1709] | 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 | |
---|
[1711] | 80 | awk '{print $2}' ${IGCM_DEM_SIMU}/liste_output_files_config.txt > ${IGCM_DEM_SIMU}/info_Output_light.txt |
---|
[1709] | 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 | # |
---|
[2027] | 105 | date_begin_pack=`echo $date_begin_pack|sed 's/^0*//'` |
---|
| 106 | date_end_simulation=`echo $date_end_simulation|sed 's/^0*//'` |
---|
| 107 | |
---|
[1709] | 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 |
---|
[1726] | 136 | echo ${file} >> ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list |
---|
[1709] | 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 |
---|
[1922] | 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 |
---|
[1709] | 168 | done |
---|
[1922] | 169 | |
---|
[1709] | 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 ? |
---|
[1711] | 200 | file=$( head -n 2 ${IGCM_DEM_SIMU}/liste_output_files_config.txt ) |
---|
[1709] | 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 | |
---|
| 208 | DEM_log -1 "Recherche de la frequence" |
---|
| 209 | if [ ${month_end} -eq ${month_begin} ] |
---|
| 210 | then |
---|
| 211 | DEM_log -1 "Mensuel" |
---|
| 212 | frequency="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 | fi |
---|
| 220 | if [[ ${month_end} -eq "12" && ${month_begin} -eq "01" ]] |
---|
| 221 | then |
---|
| 222 | DEM_log -1 "Annuel" |
---|
| 223 | frequency="annuel" |
---|
| 224 | while read an ; do |
---|
| 225 | i=1 |
---|
| 226 | printf "%s%02d\n" ${an} ${i} >> ${IGCM_TMP}/${$}.toutes_dates |
---|
| 227 | done < ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 228 | fi |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | # Maintenant il faut comparer la liste des dates avec la liste des dates des fichiers |
---|
| 232 | # et pour des dates manquantes transformer le fichier ncrcat_date correspondant en fichier |
---|
| 233 | # tar_date |
---|
| 234 | DEM_log -1 "Recherche des dates manquantes" |
---|
| 235 | for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt` |
---|
| 236 | do |
---|
| 237 | DEM_log -2 "${type_file}" |
---|
| 238 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 239 | |
---|
| 240 | if [ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ] ; then |
---|
| 241 | join -v 1 ${IGCM_TMP}/${$}.toutes_dates ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 242 | |
---|
| 243 | # On change le fichier ncrcat pour chaque date manquante en fichier tar |
---|
| 244 | if [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then |
---|
[1913] | 245 | for date in `awk '{print $0}' ${IGCM_DEM_SIMU}/${type_file}_manquant.list` ; do |
---|
| 246 | ### AC : test si le fichier de list existe dans output_ncrcat (si non ca veut dire qu'il deja ete move dans output_tar) |
---|
| 247 | nb_files=$(ls ${OUTPUT_NCRCAT} | grep ${JobName} | grep "${type_file}.list" | wc -l ) |
---|
| 248 | if [ "x$nb_files" != "x0" ] ; then |
---|
| 249 | ls -l ${OUTPUT_NCRCAT}/${JobName}_*_${type_file}.list > ${IGCM_TMP}/${$}.liste_ncrcat |
---|
| 250 | for pack in $( awk '{print $9}' ${IGCM_TMP}/${$}.liste_ncrcat ) ; do |
---|
| 251 | extract_date_file=$( echo ${pack} | sed -e "s%.*${JobName}_%%" ) |
---|
| 252 | date_debut=$( echo ${extract_date_file} | sed 's%\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6 ) |
---|
| 253 | date_fin=$( echo ${extract_date_file} | sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6 ) |
---|
[1922] | 254 | #on retire les eventuels zero pour eviter de tomber sur des dates de type 08 ou 09 |
---|
| 255 | date=`echo $date|sed 's/^0*//'` |
---|
| 256 | date_debut=`echo $date_debut|sed 's/^0*//'` |
---|
| 257 | date_fin=`echo $date_fin|sed 's/^0*//'` |
---|
[1913] | 258 | if [[ ${date} -ge ${date_debut} && ${date} -lt ${date_fin} ]]; then |
---|
| 259 | mv ${pack} ${OUTPUT_TAR}/. |
---|
| 260 | break |
---|
| 261 | else |
---|
| 262 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 263 | fi |
---|
| 264 | done |
---|
| 265 | fi |
---|
[1709] | 266 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_ncrcat |
---|
| 267 | done |
---|
[1860] | 268 | elif [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && ! -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then |
---|
| 269 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
[1709] | 270 | fi |
---|
| 271 | fi |
---|
[1913] | 272 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
[1709] | 273 | done |
---|
| 274 | |
---|
| 275 | DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackDone |
---|
| 276 | |
---|
[1822] | 277 | # gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi |
---|
| 278 | simuMonitoring_OK "$MonitoringInfo" "$config_card" |
---|
| 279 | |
---|
[1709] | 280 | DEM_log -0 "Fin de ${SCRIPT_NAME}" |
---|
| 281 | |
---|
| 282 | exit |
---|