source: TOOLS/SURPACK_IPSL/archive_restart.sh @ 3624

Last change on this file since 3624 was 2160, checked in by acosce, 11 years ago

Some update on surpack tools

1) add a script to move new pack on store and remove old simulation after checking results
2) make some improvement on launch_ipsl_pack.sh and other scripts

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
84    tar xf $archive
85done
86
87### creation de liste en fonction du type de restart
88sort ${IGCM_TMP}/${$}.new_liste_restart_files.txt > ${IGCM_TMP}/${$}.order_new_liste_restart_files.txt
89ref=`awk -F_ '{if (NR==1) print $1}' ${IGCM_TMP}/${$}.order_new_liste_restart_files.txt`
90
91i=1
92for new_file in `awk  '{print $0}' ${IGCM_TMP}/${$}.order_new_liste_restart_files.txt`; do
93    new_ref=$( echo ${new_file} | sed -e "s/_.*//") 
94
95    if [ ${new_ref} == ${ref} ]; then
96        echo ${new_file} >> ${IGCM_TMP}/${$}.restart_list_${i}.txt
97    else
98        ref=${new_ref}
99        (( i = $i + 1 ))
100        echo ${new_file} >> ${IGCM_TMP}/${$}.restart_list_${i}.txt
101    fi
102done
103
104
105
106j=1
107while [[ $j -le $i  ]]; do
108
109### 2- creer les listes de fichiers par periode ####
110    DEM_log -1 "Creation des listes de fichiers par periode"
111### 2.1- extraire l'annee et le mois de DateBegin ###
112    date_begin=${DateBegin}
113    date_end=${DateEnd}
114
115    year_begin=$(echo ${date_begin} | cut -c 1-4 )
116    month_begin=$(echo ${date_begin} | cut -c 5-6 )
117    year_end=$(echo ${date_end} | cut -c 1-4 )
118    month_end=$(echo ${date_end} | cut -c 5-6 )
119
120
121### 2.2- creation des listes ###
122    date_begin_pack=${date_begin}
123    date_end_simulation=${date_end}
124
125    month_begin_pack=${month_begin}
126    year_begin_pack=${year_begin}
127
128    number_pack=1
129    while [ ${date_begin_pack} -le ${date_end_simulation} ]
130    do
131       
132        month_end_pack=${month_begin_pack}
133        year_end_pack=`expr ${year_begin_pack} + ${period_pack}`
134
135
136        date_end_pack=${year_end_pack}${month_end_pack}01   
137       
138        for file in `awk '{print $1}' ${IGCM_TMP}/${$}.restart_list_${j}.txt`; do   
139            extract_date_file=`echo ${file}  | sed -e "s/.*\${JobName}_//"`
140            date_file=`echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g'`
141           
142            if [  ${date_file} -lt ${date_end_pack} ]
143            then
144                if [ ${date_file} -ge ${date_begin_pack} ]
145                then
146                    echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_restart_${number_pack}.txt
147                    grep -v ${file} ${IGCM_TMP}/${$}.restart_list_${j}.txt > ${IGCM_TMP}/${$}.restart_list_${j}.txt.tmp
148                    mv ${IGCM_TMP}/${$}.restart_list_${j}.txt.tmp ${IGCM_TMP}/${$}.restart_list_${j}.txt
149                fi
150               
151            fi
152            if [  ${date_file} -gt ${date_end_pack} ]
153            then
154                break
155            fi
156        done
157
158
159
160        DEM_log -1 "On definit le datebegin de la  prochaine periode pack"
161#on definit la periode pack suivante
162        month_begin_pack=${month_end_pack}
163        year_begin_pack=${year_end_pack}
164       
165        date_begin_pack=${year_begin_pack}${month_begin_pack}01
166       
167        number_pack=`expr ${number_pack} + 1`
168
169    done
170
171    ((j = $j + 1 ))
172done
173
174compt_pack=1
175while [[ $compt_pack -le $number_pack ]]; do
176#on archive les restart - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} 
177# end etant la date du dernier fichier contenu et non pas la premiere date suivant
178    DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive "
179#On classe par ordre alphabetique les fichiers contenus dans liste_pack_restart
180#la date du dernier fichier donnera la date de fin du pack
181    if [[ -f ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt ]] ; then
182        sort ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt.tmp
183
184        first_file=$(head -n 1 ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt.tmp )
185        extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
186        DateBegin_Restart=$(echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' )
187           
188        last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt.tmp )
189        extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
190        DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
191        mv ${IGCM_TMP}/${$}.liste_pack_restart_${compt_pack}.txt.tmp ${RESTART_TAR}/${JobName}_restart_${DateBegin_Restart}_${DateEnd_Restart}.list
192    fi
193
194compt_pack=`expr ${compt_pack} + 1`
195done
196
197
198cd ${EXE_DIR}
199
200# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
201simuMonitoring_OK "$MonitoringInfo" "$config_card"
Note: See TracBrowser for help on using the repository browser.