source: TOOLS/PACK_IPSL/create_config_card.sh @ 1822

Last change on this file since 1822 was 1822, checked in by aclsce, 12 years ago

Modifications done by Guillaume P :

  • error handling for the whole script
  • check of nco version
  • restart tool for list script
  • progress visualization for both scripts
  • "force" option -f added for both scripts
  • timing information added for pack script
File size: 10.4 KB
Line 
1#!/bin/bash
2
3##
4## Job permettant de recreer une partie du config.card d'une simulation
5## Champs vises : JobName / DateBegin / DateEnd / Calendar
6##
7
8# Prend en argument un fichier contenant une liste de simulations
9# cree pour chacune son config.card
10# Ex : ./create_config_card.job liste_simul_fichier_param_test1.txt liste_fichier_dmnfs
11# Ex : ./create_config_card.job liste_simul_param_SL.txt /cscratch/cont003/labetoul/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2012-03-21
12
13
14LISTE_SIMUL=${1}
15LISTE_DMNFS=${2}
16
17# ----
18export JOB_DIR=${JOB_DIR:-${PWD}}
19export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
20export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
21mkdir -p ${IGCM_DEM}
22mkdir -p ${IGCM_TMP}
23clean_tmp=${clean_tmp:-yes}
24EXE_DIR=$(dirname ${0})
25SCRIPT_NAME=$(basename ${0} )
26source ${EXE_DIR}/DEM_utilities.sh
27
28# gpdebug : verif si le present script a ete execute jusqu'au bout #########
29MonitoringInfo="${SCRIPT_NAME}-->OK"
30generalMonitoring "$MonitoringInfo"
31
32DEM_log -0 "Demarrage de ${SCRIPT_NAME}"
33
34# gpdebug : on augmente la liste des proc à détruire en cas d'erreur bloquante du présent proc
35export listPID="$$ ${listPID}" #########
36
37cd ${JOB_DIR}
38# ----
39
40DEM_log -0 "LISTE_SIMUL : ${LISTE_SIMUL}"
41DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}"
42
43[[ -f ${IGCM_DEM}/config_card.liste ]] && rm ${IGCM_DEM}/config_card.liste
44
45#ROOT_DIR=/dmnfs05/cont003/labetoul # soit DMFDIR, soit le tampon. a ameliorer ...
46
47
48cd ${JOB_DIR}
49
50for PATH_SIMUL_FULL in `awk  '{print $0}' ${LISTE_SIMUL}` ; do
51
52    DEM_log -3 PATH_SIMUL_FULL : ${PATH_SIMUL_FULL}
53    #PATH_SIMUL_SHORT=${PATH_SIMUL_FULL##${ROOT_DIR}} # Enleve le debut du path
54    PATH_SIMUL_SHORT=$(echo ${PATH_SIMUL_FULL} | sed 's%/[^/]*/[^/]*/[^/]*/%%' )
55    DEM_log -3 PATH_SIMUL_SHORT : ${PATH_SIMUL_SHORT}
56   
57    IGCM_DEM_SIMU=${IGCM_DEM}/${PATH_SIMUL_SHORT}
58    mkdir -p ${IGCM_DEM_SIMU}
59    rm -rf ${IGCM_DEM_SIMU}/*
60
61    #creation du repertoire permettant de stocker
62    #les listes de fichiers qui ne sont pas au format output ou restart
63    #les listes de fichiers d'analyse, les monitos et les atlas
64    OTHER_TAR=${IGCM_DEM_SIMU}/other_tar
65    STORE_CP=${IGCM_DEM_SIMU}/store_cp
66    WORK_CP=${IGCM_DEM_SIMU}/work_cp
67
68    DEM_log -2 "creation des repertoires : $OTHER_TAR  - $STORE_CP - $WORK_CP"
69
70    mkdir -p ${OTHER_TAR}
71    mkdir -p ${STORE_CP}
72    mkdir -p ${WORK_CP}
73
74    # on recherche le nom du job
75    JobName=""
76   
77    # Etablir la liste des fichiers d'Analyse
78    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Analyse  | awk '{print $3}' |  sort >> ${IGCM_TMP}/${$}.cp_analyse_files.list
79    awk -F/ '{if ($(NF)=="Analyse") print $0} ' ${IGCM_TMP}/${$}.cp_analyse_files.list > ${STORE_CP}/cp_files.list
80    rm -f ${IGCM_TMP}/${$}.cp_analyse_files.list
81
82    #On recupere egalement le fichier mesh_mask si il existe
83    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep mesh_mask | awk '{print $3}' >> ${STORE_CP}/cp_files.list
84    sed '/mesh_mask/d' ${LISTE_DMNFS} > ${IGCM_TMP}/${$}.Listing_tmp.txt; mv ${IGCM_TMP}/${$}.Listing_tmp.txt ${LISTE_DMNFS}
85
86    #On copie aussi le contenu du repertoire Exe/
87    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep -w Exe | awk '{print $3}' >> ${IGCM_TMP}/${$}.cp_analyse_files.list
88    awk -F/ '{if ($(NF)=="Exe") print $0} ' ${IGCM_TMP}/${$}.cp_analyse_files.list >> ${STORE_CP}/cp_files.list
89   
90
91    # Etablir la liste des fichiers Monito et Atlas
92    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep  MONITORING | awk '{print $3}' | sort >> ${IGCM_TMP}/${$}.cp_monito_files.list
93    awk -F/ '{if ($(NF)=="MONITORING") print $0} ' ${IGCM_TMP}/${$}.cp_monito_files.list > ${WORK_CP}/cp_files.list
94
95    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep  ATLAS | awk '{print $3}' | sort >> ${IGCM_TMP}/${$}.cp_atlas_files.list
96    awk -F/ '{if ($(NF)=="ATLAS") print $0} ' ${IGCM_TMP}/${$}.cp_atlas_files.list >> ${WORK_CP}/cp_files.list
97   
98
99    # Etablir la liste des fichiers de restart
100    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Restart | awk '{print $2 " " $3}' | grep -e '.*/Restart/.*\..*' |grep -v "jnl" | sort  >> ${IGCM_TMP}/${$}.liste_restart_files_config.txt
101
102    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires au repetoire restart/
103    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt ` ; do
104        dir=$( echo $file | sed -e "s%.*Restart/%%") 
105        testdir=$(dirname ${dir}) 
106        if [ $testdir != "." ]; then
107            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_restart_files_config.txt)  >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
108        fi
109    done
110    if [ -f ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ]; then
111        join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
112        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
113    fi
114   
115    # Etablir la liste des fichiers output
116    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Output  | awk '{print $2 " "  $3}' | grep -e '.*/Output/.*\.nc$'  | sort >> ${IGCM_TMP}/${$}.liste_output_files_config.txt
117    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires aux repetoires Output/*/
118    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_output_files_config.txt ` ; do
119        dir=$( echo $file | sed -e "s%.*Output/[^/]*/%%") 
120        testdir=$(dirname ${dir}) 
121        if [ $testdir != "." ]; then
122            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_output_files_config.txt ) >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
123        fi
124    done
125    if [ -f ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ]; then
126        join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_no_output_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
127        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_output_files_config.txt
128    fi
129
130
131
132
133    # Lecture du nom du job
134    JobName=`awk -F/ '{if (NR==1) print $(NF-3)}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt`
135    DEM_log -2 JobName ${JobName}
136
137
138# Maintenant que nous avons JobName verifions que tous les fichiers de restart/Output sont bien du type JobName_date_*
139    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_restart_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
140    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
141    join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.restart.tmp
142    sort -k 2 ${IGCM_TMP}/${$}.restart.tmp > ${IGCM_TMP}/${$}.restart_bis.tmp
143    mv ${IGCM_TMP}/${$}.restart_bis.tmp ${IGCM_DEM_SIMU}/liste_restart_files_config.txt
144# Sauvegarde des fichiers qui ne sont pas dans la norme
145    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
146    mv ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ${OTHER_TAR}/tar_no_restart_files.list
147
148
149    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_output_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
150    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
151    join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.output.tmp
152    sort -k 2 ${IGCM_TMP}/${$}.output.tmp > ${IGCM_TMP}/${$}.output_bis.tmp
153    mv ${IGCM_TMP}/${$}.output_bis.tmp ${IGCM_DEM_SIMU}/liste_output_files_config.txt
154# Sauvegarde des fichiers qui ne sont pas dans la norme
155    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
156    mv ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ${OTHER_TAR}/tar_no_output_files.list
157
158
159# Recherche de DateBegin et DateEnd pour les Restarts
160    first_file=$(        head -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
161    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
162    DateBegin_Restart=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
163   
164    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
165    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
166    DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
167   
168# Recherche de DateBegin et DateEnd pour les Output
169    first_file=$( head -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
170    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
171    DateBegin_Output=$(  echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
172   
173    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
174    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
175    DateEnd_Output=$(    echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
176   
177    DateBegin=${DateBegin_Restart}
178    DateEnd=${DateEnd_Restart}
179
180    DEM_log -2 "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
181    DEM_log -2 "DateBegin_Output DateEnd_Output : ${DateBegin_Output} ${DateEnd_Output}"
182    DEM_log -2 "DateBegin_Restart DateEnd_Restart : ${DateBegin_Restart} ${DateEnd_Restart}"
183
184    DateBegin=$( DEM_min ${DateBegin_Output} ${DateBegin} ) 
185    DateEnd=$(   DEM_max ${DateEnd_Output}   ${DateEnd}   )
186   
187    DEM_log -2  "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
188   
189    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.config_name ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
190   
191    rm -f ${IGCM_DEM_SIMU}/config_card_${JobName}
192    cat<<EOD>${IGCM_DEM_SIMU}/config_card_${JobName}
193JobName=${JobName}
194DateBegin=${DateBegin}
195DateEnd=${DateEnd}
196PATH_SIMUL_FULL=${PATH_SIMUL_FULL}
197IGCM_DEM_SIMU=${IGCM_DEM_SIMU}
198EOD
199   
200    echo "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone" >> ${IGCM_DEM}/config_card.liste
201
202    DEM_log -1 "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone >> ${IGCM_DEM}/config_card.liste"
203
204
205#si la liste des fichiers d'output est vide on tar la simul
206if [[ !  -s ${IGCM_DEM_SIMU}/liste_output_files_config.txt ]]; then
207DEM_log -2 "liste output vide"
208    ./write_liste_tar.sh ${IGCM_DEM_SIMU}/config_card_${JobName}
209fi
210
211# si les listes no_output et no_restart sont vides on les efface
212if [[ !  -s ${OTHER_TAR}/tar_no_output_files.list ]]; then
213    rm -f ${OTHER_TAR}/tar_no_output_files.list
214fi
215
216if [[ !  -s ${OTHER_TAR}/tar_no_restart_files.list ]]; then
217    rm -f ${OTHER_TAR}/tar_no_restart_files.list
218fi
219
220
221done
222
223# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
224echo $MonitoringInfo >> $generalMonitorFile
225
226DEM_log -0 "Fin de ${SCRIPT_NAME}"
227
Note: See TracBrowser for help on using the repository browser.