source: TOOLS/PACK_IPSL/write_liste_pack.sh @ 2010

Last change on this file since 2010 was 1922, checked in by acosce, 12 years ago

Correct several bugs

  • add a test on file to check if it exists or not
  • fixed bug about integer "08" and "09" that appear in simulation before year 1000
File size: 11.3 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# 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
96date_begin_pack=${DateBegin}
97date_end_simulation=${DateEnd}
98
99month_begin_pack=${month_begin}
100year_begin_pack=${year_begin}
101
102number_pack=1
103
104#
105while [[ ${date_begin_pack} -le ${date_end_simulation}  ]]
106do
107
108   month_end_pack=${month_begin_pack}
109   year_end_pack=$(( ${year_begin_pack} +${period_pack} ))
110   
111   date_end_pack=${year_end_pack}${month_end_pack}01   
112
113   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}"
114   DEM_log -2 "Entree boucle 3 : date_end_pack : ${date_end_pack}"
115   
116   for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
117   do
118       DEM_log -2 "Boucle 3 : ${type_file} ${number_pack}"
119       taille=0
120
121       # On passe en revue chaque type de fichier
122       for file in `awk '{print $0}' ${IGCM_TMP}/${$}.info_${type_file}.txt`
123       do 
124           # Extraire la date de debut et la date de fin de la periode d'output traitee par le fichier   
125           extract_date_file=$( echo ${file}             | sed -e "s%.*${JobName}_%%" )
126           date_debut=$(        echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' )
127           date_fin=$(          echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' )
128           
129           if [  ${date_debut} -lt ${date_end_pack} ]
130           then
131               if [ ${date_fin} -ge ${date_begin_pack} ]
132               then
133                   echo ${file} >> ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list
134                   echo ${date_debut} | cut -c 1-6 >>  ${IGCM_TMP}/${$}.date_${type_file}.txt
135                   grep -v ${file} ${IGCM_TMP}/${$}.info_${type_file}.txt > ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
136                   cp ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp ${IGCM_TMP}/${$}.info_${type_file}.txt
137                   [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.info_${type_file}.txt.tmp
138               fi
139           else
140               break
141           fi
142           
143       done
144       if [[ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ]] ; then
145           sort -u ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_TMP}/${$}.date_tmp.txt
146           mv ${IGCM_TMP}/${$}.date_tmp.txt ${IGCM_TMP}/${$}.date_${type_file}.txt
147       else
148           DEM_log -2 "Pas de fichier cree :  ${IGCM_TMP}/${$}.date_${type_file}.txt - Date_end_pack : ${date_end_pack}"
149       fi
150
151#On renomme le fichier ncrcat avec la date reelle de fin et non pas la premiere date suivant la fin
152#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
153       if [[ -f ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list ]]; then
154           sort ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list > ${IGCM_TMP}/${$}.ncrcat.tmp
155
156           first_file=$(head -n 1 ${IGCM_TMP}/${$}.ncrcat.tmp )
157           extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
158           date_debut=$(echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' )
159
160           last_file=$(tail -n 1 ${IGCM_TMP}/${$}.ncrcat.tmp )
161           extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
162           date_fin=$(echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' )
163           mv ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list ${OUTPUT_NCRCAT}/${JobName}_${date_debut}_${date_fin}_${type_file}.list
164       fi
165   done
166
167   month_begin_pack=${month_end_pack}
168   year_begin_pack=${year_end_pack}
169   date_begin_pack=${year_begin_pack}${month_begin_pack}01
170   
171   number_pack=$(( ${number_pack} + 1 ))
172
173   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}"
174   DEM_log -2 "Sortie boucle : date_begin_pack : ${date_begin_pack}"
175   
176done
177
178
179## Recherche des trous eventuels dans cette simulation
180
181## Creation de la liste des annees comprisent entre DateBegin et DateEnd >>  ${IGCM_TMP}/${$}.liste_date.txt
182force_sequence (){
183    awk '{
184        if (NR==1) {avant=$1; print $1}
185        else { for (i=avant+1 ; i<=$1 ; i++) printf "%04i\n", i}}'
186}
187
188DEM_log -1 "year_begin - year_end : ${year_begin} - ${year_end}"
189
190echo ${year_begin} > ${IGCM_TMP}/${$}.liste_date.txt
191echo ${year_end}  >> ${IGCM_TMP}/${$}.liste_date.txt
192
193force_sequence < ${IGCM_TMP}/${$}.liste_date.txt > ${IGCM_TMP}/${$}.tmp ; mv ${IGCM_TMP}/${$}.tmp ${IGCM_TMP}/${$}.liste_date.txt
194
195
196## il faut savoir si les fichiers d'output sont annuels ou mensuels ?
197file=$( head -n 2 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
198
199extract_date_file=$( echo ${file}             | sed -e "s%.*${JobName}_%%" )
200date_debut=$(        echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g')
201date_fin=$(          echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g')
202month_begin=$(       echo ${date_debut}       | cut -c 5-6 )
203month_end=$(         echo ${date_fin}         | cut -c 5-6 )
204
205DEM_log -1 "Recherche de la frequence"
206if [ ${month_end} -eq ${month_begin} ]
207then
208    DEM_log -1 "Mensuel"
209    frequency="mensuel"
210    while read an ; do
211        for month in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
212            printf "%s%02d\n" ${an} ${month}  >> ${IGCM_TMP}/${$}.toutes_dates
213        done
214    done < ${IGCM_TMP}/${$}.liste_date.txt
215    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_date.txt
216fi
217if [[ ${month_end} -eq "12" && ${month_begin} -eq "01" ]]
218then
219    DEM_log -1 "Annuel"
220    frequency="annuel"
221    while read an ; do
222        i=1
223        printf "%s%02d\n" ${an} ${i}  >> ${IGCM_TMP}/${$}.toutes_dates
224    done < ${IGCM_TMP}/${$}.liste_date.txt   
225fi
226
227
228# Maintenant il faut comparer la liste des dates avec la liste des dates des fichiers
229# et pour des dates manquantes transformer le fichier ncrcat_date correspondant en fichier
230# tar_date
231DEM_log -1 "Recherche des dates manquantes"
232for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
233do
234    DEM_log -2 "${type_file}"
235    rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list
236   
237    if [ -f ${IGCM_TMP}/${$}.date_${type_file}.txt ] ; then
238        join -v 1  ${IGCM_TMP}/${$}.toutes_dates ${IGCM_TMP}/${$}.date_${type_file}.txt > ${IGCM_DEM_SIMU}/${type_file}_manquant.list
239       
240        # On change le fichier ncrcat pour chaque date manquante en fichier tar
241        if [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then
242            for date in `awk '{print $0}' ${IGCM_DEM_SIMU}/${type_file}_manquant.list` ; do
243### AC : test si le fichier de list existe dans output_ncrcat (si non ca veut dire qu'il deja ete move dans output_tar)
244                nb_files=$(ls ${OUTPUT_NCRCAT} | grep ${JobName} | grep "${type_file}.list" | wc -l )
245                if [ "x$nb_files" != "x0" ] ; then
246                    ls -l ${OUTPUT_NCRCAT}/${JobName}_*_${type_file}.list > ${IGCM_TMP}/${$}.liste_ncrcat
247                    for pack in $( awk '{print $9}' ${IGCM_TMP}/${$}.liste_ncrcat ) ; do
248                        extract_date_file=$( echo ${pack}       | sed -e "s%.*${JobName}_%%" )
249                        date_debut=$( echo ${extract_date_file} | sed 's%\([0-9]\{8\}\)_.*$%\1%g'     | cut -c 1-6  )
250                        date_fin=$(   echo ${extract_date_file} | sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6  )
251                        #on retire les eventuels zero pour eviter de tomber sur des dates de type 08 ou 09
252                        date=`echo $date|sed 's/^0*//'`
253                        date_debut=`echo $date_debut|sed 's/^0*//'`
254                        date_fin=`echo $date_fin|sed 's/^0*//'`
255                        if [[ ${date} -ge ${date_debut} && ${date} -lt ${date_fin} ]]; then
256                            mv ${pack} ${OUTPUT_TAR}/.
257                            break
258                        else
259                            rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list
260                        fi
261                    done
262                fi
263                [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_ncrcat
264            done
265        elif [[ -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list && ! -s ${IGCM_DEM_SIMU}/${type_file}_manquant.list ]]; then
266            rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list
267        fi
268    fi
269    rm -f ${IGCM_DEM_SIMU}/${type_file}_manquant.list
270done
271
272DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackDone
273
274# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
275simuMonitoring_OK "$MonitoringInfo" "$config_card"
276
277DEM_log -0 "Fin de ${SCRIPT_NAME}"
278
279exit
Note: See TracBrowser for help on using the repository browser.