source: TOOLS/PACK_IPSL/write_liste_pack.sh @ 1765

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

Change name of list to pack to be compatible with enlarge part

File size: 9.6 KB
Line 
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
15config_card=${1}
16LISTE_DMNFS=${2}
17
18# Declaration des variables
19
20# ----
21export JOB_DIR=${JOB_DIR:-${PWD}}
22export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
23export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
24mkdir -p ${IGCM_DEM}
25mkdir -p ${IGCM_TMP}
26clean_tmp=${clean_tmp:-yes}
27EXE_DIR=$(dirname ${0} )
28SCRIPT_NAME=$(basename ${0} )
29source ${EXE_DIR}/DEM_utilities.sh
30DEM_log -0 "Demmarrage de ${SCRIPT_NAME}"
31cd ${JOB_DIR}
32# ----
33
34DEM_log -0 "config_card : ${config_card}"
35DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}"
36
37eval $(grep JobName         ${config_card}) 
38eval $(grep PATH_SIMUL_FULL ${config_card}) 
39eval $(grep DateBegin       ${config_card}) 
40eval $(grep DateEnd         ${config_card}) 
41eval $(grep IGCM_DEM_SIMU   ${config_card})
42
43SIMUL=${PATH_SIMUL_FULL}/${JobName}
44
45DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${config_card} )
46if [[ "${DEM_state}" != "FindSizePackDone" ]] ; then
47    DEM_log -0 "Attention : Etat incorrect dans ${IGCM_DEM}/config_card.liste"
48    exit -1
49fi
50
51DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackRunning
52
53# creation des repertoires with_tar et with_ncrcat
54OUTPUT_NCRCAT=${IGCM_DEM_SIMU}/output_ncrcat
55OUTPUT_TAR=${IGCM_DEM_SIMU}/output_tar
56
57mkdir -p ${OUTPUT_NCRCAT}
58mkdir -p ${OUTPUT_TAR}
59
60# lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt
61period_pack=$( awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt )
62
63year_begin=$(  echo ${DateBegin} | cut -c 1-4 )
64month_begin=$( echo ${DateBegin} | cut -c 5-6 )
65year_end=$(    echo ${DateEnd}   | cut -c 1-4 )
66month_end=$(   echo ${DateEnd}   | cut -c 5-6 )
67
68awk '{print $2}' ${IGCM_DEM_SIMU}/liste_output_files_config.txt >  ${IGCM_DEM_SIMU}/info_Output_light.txt
69
70# on cree la liste des fichiers pour chaque type_file
71for 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
77done
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
85date_begin_pack=${DateBegin}
86date_end_simulation=${DateEnd}
87
88month_begin_pack=${month_begin}
89year_begin_pack=${year_begin}
90
91number_pack=1
92
93#
94while [[ ${date_begin_pack} -le ${date_end_simulation}  ]]
95do
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
122                   echo ${file} >> ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list
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
141       sort ${OUTPUT_NCRCAT}/ncrcat_${type_file}_${date_begin_pack}_${date_end_pack}.list > ${IGCM_TMP}/${$}.ncrcat.tmp
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' )
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
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   
158done
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
164force_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
170DEM_log -1 "year_begin - year_end : ${year_begin} - ${year_end}"
171
172echo ${year_begin} > ${IGCM_TMP}/${$}.liste_date.txt
173echo ${year_end}  >> ${IGCM_TMP}/${$}.liste_date.txt
174
175force_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 ?
179file=$( head -n 2 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
180
181extract_date_file=$( echo ${file}             | sed -e "s%.*${JobName}_%%" )
182date_debut=$(        echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g')
183date_fin=$(          echo ${extract_date_file}| sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g')
184month_begin=$(       echo ${date_debut}       | cut -c 5-6 )
185month_end=$(         echo ${date_fin}         | cut -c 5-6 )
186
187DEM_log -1 "Recherche de la frequence"
188if [ ${month_end} -eq ${month_begin} ]
189then
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
198fi
199if [[ ${month_end} -eq "12" && ${month_begin} -eq "01" ]]
200then
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   
207fi
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
213DEM_log -1 "Recherche des dates manquantes"
214for type_file in `awk '{print $0}' ${IGCM_DEM_SIMU}/info_name_file.txt`
215do
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
225                ls -l ${OUTPUT_NCRCAT}/${JobName}_*_${type_file}.list > ${IGCM_TMP}/${$}.liste_ncrcat
226                for pack in $( awk '{print $9}' ${IGCM_TMP}/${$}.liste_ncrcat ) ; do
227                    extract_date_file=$( echo ${pack}       | sed -e "s%.*${JobName}_%%" )
228                    date_debut=$( echo ${extract_date_file} | sed 's%\([0-9]\{8\}\)_.*$%\1%g'     | cut -c 1-6  )
229                    date_fin=$(   echo ${extract_date_file} | sed 's%.*_\([0-9]\{8\}\)_.*$%\1%g' | cut -c 1-6  )
230                    if [[ ${date} -ge ${date_debut} && ${date} -lt ${date_fin} ]]; then
231                        mv ${pack} ${OUTPUT_TAR}/${JobName}_${date_debut}_${date_fin}_${type_file}.list
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
242done
243
244DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListPackDone
245
246DEM_log -0 "Fin de ${SCRIPT_NAME}"
247
248exit
Note: See TracBrowser for help on using the repository browser.