source: TOOLS/PACK_IPSL/archive_restart.sh @ 3632

Last change on this file since 3632 was 2139, checked in by acosce, 11 years ago

Correct the name of restart archive to fit with libIGCM standard

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