source: TOOLS/SURPACK_IPSL/archive_restart.sh @ 2141

Last change on this file since 2141 was 2136, checked in by acosce, 11 years ago

add new tools allows packing simulation alreaddy pack (so pack with a bigger frequency)

File size: 6.3 KB
Line 
1#!/bin/bash
2
3
4#on veut archiver les fichiers restart
5#Dans le cadre du demenagement ils seront renommes
6#ATM/Restart/****.nc
7#OCE/Restart/****.nc
8#...
9#sous la forme
10#RESTART/ATM_****.nc
11#RESTART/OCE_****.nc
12#Attention de bien conserver les dates d'origines
13#
14#Dans le cadre de la production nouvelle chaine
15#ils auront directement le bon nom
16#
17#On veut egalement que l'archive soit par periode de temps
18# cette periode est definie par la taille du pack donc connue
19# en entree du script (1M, 1Y, 5Y, 10Y etc...)
20#
21
22
23# $1= PATH/config_card d'une simulation avec
24# TagName/JobName/ExperimentName/SpaceName/DateBegin/DateEnd/PATH_SIMUL
25# $2=period_pack en M/m ou Y/y
26
27config_card=${1}
28LISTE_DMNFS=${2}
29
30
31export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}}
32export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
33export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
34mkdir -p ${IGCM_DEM}
35mkdir -p ${IGCM_TMP}
36clean_tmp=${clean_tmp:-yes}
37EXE_DIR=$(dirname ${0})
38SCRIPT_NAME=$(basename ${0} )
39
40source ${EXE_DIR}/DEM_utilities.sh
41
42# gpdebug : verif si le present script a ete execute jusqu'au bout #########
43MonitoringInfo="${SCRIPT_NAME}-->OK"
44simuMonitoring_check "$MonitoringInfo" "$config_card"
45
46DEM_log -0 "Demarrage de ${SCRIPT_NAME}"
47
48
49#### 0- lecture de config.card
50#### on veut les renseignements suivants :
51#### JobName, PATH_SIMUL, DateBegin et DateEnd
52eval $(grep JobName ${config_card}) 
53eval $(grep PATH_SIMUL_FULL ${config_card}) 
54eval $(grep DateBegin ${config_card}) 
55eval $(grep DateEnd ${config_card}) 
56eval $(grep IGCM_DEM_SIMU ${config_card})
57
58
59#### Preparation de l'environnement
60# repertoire dans lequel seront renommes les fichiers de restart
61STORE_RESTART=$IGCM_DEM_SIMU/RESTART
62mkdir -p ${STORE_RESTART}
63
64# repertoire dans lequel nous stockerons les listes de restart a archiver
65RESTART_TAR=$IGCM_DEM_SIMU/restart_tar
66mkdir -p ${RESTART_TAR}
67
68# lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt
69period_pack=`awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt`
70
71DEM_log -1 "Period pack = ${period_pack}" 
72#### 1- renommer les fichiers ######
73DEM_log -1 "Renommer les fichiers de Restart"
74
75cd ${STORE_RESTART}
76if [ "x${STORE_RESTART}" != "x" ]
77then
78    rm -rf *
79fi
80# On les copie sur le scratchdir en changeant le nom et conservant la date
81for archive in  `awk '{print $2}' ${IGCM_DEM_SIMU}/liste_restart_files_config.txt`; do
82    ccc_hsm get $archive
83    tar tf $archive >> ${IGCM_TMP}/${$}.new_liste_restart_files.txt
84done
85
86### creation de liste en fonction du type de restart
87sort ${IGCM_TMP}/${$}.new_liste_restart_files.txt > ${IGCM_TMP}/${$}.order_new_liste_restart_files.txt
88ref=`awk -F_ '{if (NR==1) print $1}' ${IGCM_TMP}/${$}.order_new_liste_restart_files.txt`
89
90i=1
91for new_file in `awk  '{print $0}' ${IGCM_TMP}/${$}.order_new_liste_restart_files.txt`; do
92    new_ref=$( echo ${new_file} | sed -e "s/_.*//") 
93
94    if [ ${new_ref} == ${ref} ]; then
95        echo ${new_file} >> ${IGCM_TMP}/${$}.restart_list_${i}.txt
96    else
97        ref=${new_ref}
98        (( i = $i + 1 ))
99        echo ${new_file} >> ${IGCM_TMP}/${$}.restart_list_${i}.txt
100    fi
101done
102
103
104
105j=1
106while [[ $j -le $i  ]]; do
107
108### 2- creer les listes de fichiers par periode ####
109    DEM_log -1 "Creation des listes de fichiers par periode"
110### 2.1- extraire l'annee et le mois de DateBegin ###
111    date_begin=${DateBegin}
112    date_end=${DateEnd}
113
114    year_begin=$(echo ${date_begin} | cut -c 1-4 )
115    month_begin=$(echo ${date_begin} | cut -c 5-6 )
116    year_end=$(echo ${date_end} | cut -c 1-4 )
117    month_end=$(echo ${date_end} | cut -c 5-6 )
118
119
120### 2.2- creation des listes ###
121    date_begin_pack=${date_begin}
122    date_end_simulation=${date_end}
123
124    month_begin_pack=${month_begin}
125    year_begin_pack=${year_begin}
126
127    number_pack=1
128    while [ ${date_begin_pack} -le ${date_end_simulation} ]
129    do
130       
131        month_end_pack=${month_begin_pack}
132        year_end_pack=`expr ${year_begin_pack} + ${period_pack}`
133
134
135        date_end_pack=${year_end_pack}${month_end_pack}01   
136       
137        for file in `awk '{print $1}' ${IGCM_TMP}/${$}.restart_list_${j}.txt`; do   
138            extract_date_file=`echo ${file}  | sed -e "s/.*\${JobName}_//"`
139            date_file=`echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g'`
140           
141            if [  ${date_file} -lt ${date_end_pack} ]
142            then
143                if [ ${date_file} -ge ${date_begin_pack} ]
144                then
145                    echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt
146                    grep -v ${file} ${IGCM_TMP}/${$}.restart_list_${j}.txt > ${IGCM_TMP}/${$}.restart_list_${j}.txt.tmp
147                    mv ${IGCM_TMP}/${$}.restart_list_${j}.txt.tmp ${IGCM_TMP}/${$}.restart_list_${j}.txt
148                fi
149               
150            fi
151            if [  ${date_file} -gt ${date_end_pack} ]
152            then
153                break
154            fi
155        done
156
157
158
159        DEM_log -1 "On definit le datebegin de la  prochaine periode pack"
160#on definit la periode pack suivante
161        month_begin_pack=${month_end_pack}
162        year_begin_pack=${year_end_pack}
163       
164        date_begin_pack=${year_begin_pack}${month_begin_pack}01
165       
166        number_pack=`expr ${number_pack} + 1`
167
168    done
169
170    ((j = $j + 1 ))
171done
172
173compt_pack=1
174while [[ $compt_pack -le $number_pack ]]; do
175#on archive les restart - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} 
176# end etant la date du dernier fichier contenu et non pas la premiere date suivant
177    DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive "
178#On classe par ordre alphabetique les fichiers contenus dans liste_pack_restart
179#la date du dernier fichier donnera la date de fin du pack
180    if [[ -f ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt ]] ; then
181        sort ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt.tmp
182
183        first_file=$(head -n 1 ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt.tmp )
184        extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
185        DateBegin_Restart=$(echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' )
186           
187        last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt.tmp )
188        extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
189        DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
190        mv ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt.tmp ${RESTART_TAR}/${JobName}_restart_${DateBegin_Restart}_${DateEnd_Restart}.list
191    fi
192
193compt_pack=`expr ${compt_pack} + 1`
194done
195
196
197cd ${EXE_DIR}
198
199# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
200simuMonitoring_OK "$MonitoringInfo" "$config_card"
Note: See TracBrowser for help on using the repository browser.