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