source: TOOLS/PACK_IPSL/write_liste_pack.sh @ 1921

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