source: TOOLS/PACK_IPSL/write_liste_pack.sh @ 1723

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