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