[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 | # ---- |
---|
| 21 | export JOB_DIR=${JOB_DIR:-${PWD}} |
---|
| 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 |
---|
| 30 | DEM_log -0 "Demmarrage de ${SCRIPT_NAME}" |
---|
| 31 | cd ${JOB_DIR} |
---|
| 32 | # ---- |
---|
| 33 | |
---|
| 34 | DEM_log -0 "config_card : ${config_card}" |
---|
| 35 | DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}" |
---|
| 36 | |
---|
| 37 | eval $(grep JobName ${config_card}) |
---|
| 38 | eval $(grep PATH_SIMUL_FULL ${config_card}) |
---|
| 39 | eval $(grep DateBegin ${config_card}) |
---|
| 40 | eval $(grep DateEnd ${config_card}) |
---|
| 41 | eval $(grep IGCM_DEM_SIMU ${config_card}) |
---|
| 42 | |
---|
| 43 | SIMUL=${PATH_SIMUL_FULL}/${JobName} |
---|
| 44 | |
---|
| 45 | DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} ) |
---|
| 46 | if [[ "${DEM_state}" != "FindSizePackDone" ]] ; then |
---|
| 47 | DEM_log -0 "Attention : Etat incorrect dans ${IGCM_DEM}/config_card.liste" |
---|
| 48 | exit -1 |
---|
| 49 | fi |
---|
| 50 | |
---|
| 51 | DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackRunning |
---|
| 52 | |
---|
[1717] | 53 | # creation des repertoires with_tar et with_ncrcat |
---|
[1728] | 54 | OUTPUT_NCRCAT=${IGCM_DEM_SIMU}/output_ncrcat |
---|
| 55 | OUTPUT_TAR=${IGCM_DEM_SIMU}/output_tar |
---|
[1717] | 56 | |
---|
[1726] | 57 | mkdir -p ${OUTPUT_NCRCAT} |
---|
| 58 | mkdir -p ${OUTPUT_TAR} |
---|
[1717] | 59 | |
---|
[1709] | 60 | # lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt |
---|
| 61 | period_pack=$( awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt ) |
---|
| 62 | |
---|
| 63 | year_begin=$( echo ${DateBegin} | cut -c 1-4 ) |
---|
| 64 | month_begin=$( echo ${DateBegin} | cut -c 5-6 ) |
---|
| 65 | year_end=$( echo ${DateEnd} | cut -c 1-4 ) |
---|
| 66 | month_end=$( echo ${DateEnd} | cut -c 5-6 ) |
---|
| 67 | |
---|
[1711] | 68 | awk '{print $2}' ${IGCM_DEM_SIMU}/liste_output_files_config.txt > ${IGCM_DEM_SIMU}/info_Output_light.txt |
---|
[1709] | 69 | |
---|
| 70 | # on cree la liste des fichiers pour chaque type_file |
---|
| 71 | for type_file in $( awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt ) ; do |
---|
| 72 | #sed -e "/${type_file}/!d" ${IGCM_DEM_SIMU}/info_Output_light.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt |
---|
| 73 | grep ${type_file} ${IGCM_DEM_SIMU}/info_Output_light.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt |
---|
| 74 | sort -u ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp |
---|
| 75 | cp ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt |
---|
| 76 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.tmp_info_${type_file}.txt.tmp |
---|
| 77 | done |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | # 3- Maintenant pour chaque type de fichier de sortie nous allons creer la liste |
---|
| 81 | # des fichiers contenus dans chaque pack |
---|
| 82 | |
---|
| 83 | # Recherche des dates du premier pack |
---|
| 84 | |
---|
| 85 | date_begin_pack=${DateBegin} |
---|
| 86 | date_end_simulation=${DateEnd} |
---|
| 87 | |
---|
| 88 | month_begin_pack=${month_begin} |
---|
| 89 | year_begin_pack=${year_begin} |
---|
| 90 | |
---|
| 91 | number_pack=1 |
---|
| 92 | |
---|
| 93 | # |
---|
| 94 | while [[ ${date_begin_pack} -le ${date_end_simulation} ]] |
---|
| 95 | do |
---|
| 96 | |
---|
| 97 | month_end_pack=${month_begin_pack} |
---|
| 98 | year_end_pack=$(( ${year_begin_pack} +${period_pack} )) |
---|
| 99 | |
---|
| 100 | date_end_pack=${year_end_pack}${month_end_pack}01 |
---|
| 101 | |
---|
| 102 | 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}" |
---|
| 103 | DEM_log -2 "Entree boucle 3 : date_end_pack : ${date_end_pack}" |
---|
| 104 | |
---|
| 105 | for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt` |
---|
| 106 | do |
---|
| 107 | DEM_log -2 "Boucle 3 : ${type_file} ${number_pack}" |
---|
| 108 | taille=0 |
---|
| 109 | |
---|
| 110 | # On passe en revue chaque type de fichier |
---|
| 111 | for file in `awk '{print $0}' ${IGCM_TMP}/${$}.info_${type_file}.txt` |
---|
| 112 | do |
---|
| 113 | # Extraire la date de debut et la date de fin de la periode d'output traitee par le fichier |
---|
| 114 | extract_date_file=$( echo ${file} | sed -e "s%.*${JobName}_%%" ) |
---|
| 115 | date_debut=$( echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
| 116 | date_fin=$( echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
| 117 | |
---|
| 118 | if [ ${date_debut} -lt ${date_end_pack} ] |
---|
| 119 | then |
---|
| 120 | if [ ${date_fin} -ge ${date_begin_pack} ] |
---|
| 121 | then |
---|
[1726] | 122 | echo ${file} >> ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list |
---|
[1709] | 123 | echo ${date_debut} | cut -c 1-6 >> ${IGCM_TMP}/${$}.date_${type_file}.txt |
---|
| 124 | grep -v ${file} ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp |
---|
| 125 | cp ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt |
---|
| 126 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp |
---|
| 127 | fi |
---|
| 128 | else |
---|
| 129 | break |
---|
| 130 | fi |
---|
| 131 | |
---|
| 132 | done |
---|
| 133 | if [[ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ]] ; then |
---|
| 134 | sort -u ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_TMP}/${$}.date_tmp.txt |
---|
| 135 | mv ${IGCM_TMP}/${$}.date_tmp.txt ${IGCM_TMP}/${$}.date_${type_file}.txt |
---|
| 136 | else |
---|
| 137 | DEM_log -2 "Pas de fichier cree : ${IGCM_TMP}/${$}.date_${type_file}.txt - Date_end_pack : ${date_end_pack}" |
---|
| 138 | fi |
---|
| 139 | |
---|
| 140 | #On renomme le fichier ncrcat avec la date reelle de fin et non pas la premiere date suivant la fin |
---|
[1726] | 141 | sort ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list > ${IGCM_TMP}/${$}.ncrcat.tmp |
---|
[1709] | 142 | last_file=$(tail -n 1 ${IGCM_TMP}/${$}.ncrcat.tmp ) |
---|
| 143 | extract_date_file=$( echo ${last_file} | sed -e "s/.*${JobName}_//" ) |
---|
| 144 | date_fin=$(echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
[1765] | 145 | 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] | 146 | done |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | month_begin_pack=${month_end_pack} |
---|
| 150 | year_begin_pack=${year_end_pack} |
---|
| 151 | date_begin_pack=${year_begin_pack}${month_begin_pack}01 |
---|
| 152 | |
---|
| 153 | number_pack=$(( ${number_pack} + 1 )) |
---|
| 154 | |
---|
| 155 | 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}" |
---|
| 156 | DEM_log -2 "Sortie boucle : date_begin_pack : ${date_begin_pack}" |
---|
| 157 | |
---|
| 158 | done |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | ## Recherche des trous eventuels dans cette simulation |
---|
| 162 | |
---|
| 163 | ## Creation de la liste des annees comprisent entre DateBegin et DateEnd >> ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 164 | force_sequence (){ |
---|
| 165 | awk '{ |
---|
| 166 | if (NR==1) {avant=$1; print $1} |
---|
| 167 | else { for (i=avant+1 ; i<=$1 ; i++) printf "%04i\n", i}}' |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | DEM_log -1 "year_begin - year_end : ${year_begin} - ${year_end}" |
---|
| 171 | |
---|
| 172 | echo ${year_begin} > ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 173 | echo ${year_end} >> ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 174 | |
---|
| 175 | force_sequence < ${IGCM_TMP}/${$}.liste_date.txt > ${IGCM_TMP}/${$}.tmp ; mv ${IGCM_TMP}/${$}.tmp ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | ## il faut savoir si les fichiers d'output sont annuels ou mensuels ? |
---|
[1711] | 179 | file=$( head -n 2 ${IGCM_DEM_SIMU}/liste_output_files_config.txt ) |
---|
[1709] | 180 | |
---|
| 181 | extract_date_file=$( echo ${file} | sed -e "s%.*${JobName}_%%" ) |
---|
| 182 | date_debut=$( echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g') |
---|
| 183 | date_fin=$( echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g') |
---|
| 184 | month_begin=$( echo ${date_debut} | cut -c 5-6 ) |
---|
| 185 | month_end=$( echo ${date_fin} | cut -c 5-6 ) |
---|
| 186 | |
---|
| 187 | DEM_log -1 "Recherche de la frequence" |
---|
| 188 | if [ ${month_end} -eq ${month_begin} ] |
---|
| 189 | then |
---|
| 190 | DEM_log -1 "Mensuel" |
---|
| 191 | frequency="mensuel" |
---|
| 192 | while read an ; do |
---|
| 193 | for month in 1 2 3 4 5 6 7 8 9 10 11 12 ; do |
---|
| 194 | printf "%s%02d\n" ${an} ${month} >> ${IGCM_TMP}/${$}.toutes_dates |
---|
| 195 | done |
---|
| 196 | done < ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 197 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 198 | fi |
---|
| 199 | if [[ ${month_end} -eq "12" && ${month_begin} -eq "01" ]] |
---|
| 200 | then |
---|
| 201 | DEM_log -1 "Annuel" |
---|
| 202 | frequency="annuel" |
---|
| 203 | while read an ; do |
---|
| 204 | i=1 |
---|
| 205 | printf "%s%02d\n" ${an} ${i} >> ${IGCM_TMP}/${$}.toutes_dates |
---|
| 206 | done < ${IGCM_TMP}/${$}.liste_date.txt |
---|
| 207 | fi |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | # Maintenant il faut comparer la liste des dates avec la liste des dates des fichiers |
---|
| 211 | # et pour des dates manquantes transformer le fichier ncrcat_date correspondant en fichier |
---|
| 212 | # tar_date |
---|
| 213 | DEM_log -1 "Recherche des dates manquantes" |
---|
| 214 | for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt` |
---|
| 215 | do |
---|
| 216 | DEM_log -2 "${type_file}" |
---|
| 217 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 218 | |
---|
| 219 | if [ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ] ; then |
---|
| 220 | join -v 1 ${IGCM_TMP}/${$}.toutes_dates ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 221 | |
---|
| 222 | # On change le fichier ncrcat pour chaque date manquante en fichier tar |
---|
| 223 | if [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then |
---|
| 224 | for date in `awk '{print $0}' ${IGCM_DEM_SIMU}/${type_file}_manquant.list` ; do |
---|
[1765] | 225 | ls -l ${OUTPUT_NCRCAT}/${JobName}_*_${type_file}.list > ${IGCM_TMP}/${$}.liste_ncrcat |
---|
[1709] | 226 | for pack in $( awk '{print $9}' ${IGCM_TMP}/${$}.liste_ncrcat ) ; do |
---|
[1765] | 227 | extract_date_file=$( echo ${pack} | sed -e "s%.*${JobName}_%%" ) |
---|
[1709] | 228 | date_debut=$( echo ${extract_date_file} | sed 's%\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6 ) |
---|
[1765] | 229 | date_fin=$( echo ${extract_date_file} | sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6 ) |
---|
[1709] | 230 | if [[ ${date} -ge ${date_debut} && ${date} -lt ${date_fin} ]]; then |
---|
[1765] | 231 | mv ${pack} ${OUTPUT_TAR}/${JobName}_${date_debut}_${date_fin}_${type_file}.list |
---|
[1709] | 232 | break |
---|
| 233 | else |
---|
| 234 | rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list |
---|
| 235 | fi |
---|
| 236 | |
---|
| 237 | done |
---|
| 238 | [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_ncrcat |
---|
| 239 | done |
---|
| 240 | fi |
---|
| 241 | fi |
---|
| 242 | done |
---|
| 243 | |
---|
| 244 | DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackDone |
---|
| 245 | |
---|
| 246 | DEM_log -0 "Fin de ${SCRIPT_NAME}" |
---|
| 247 | |
---|
| 248 | exit |
---|