source: TOOLS/SURPACK_IPSL/create_config_card.sh @ 3740

Last change on this file since 3740 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: 9.4 KB
Line 
1#!/bin/bash
2##
3## Job permettant de recreer une partie du config.card d'une simulation
4## Champs vises : JobName / DateBegin / DateEnd / Calendar
5##
6
7# Prend en argument un fichier contenant une liste de simulations
8# cree pour chacune son config.card
9# Ex : ./create_config_card.job liste_simul_fichier_param_test1.txt liste_fichier_dmnfs
10# Ex : ./create_config_card.job liste_simul_param_SL.txt /cscratch/cont003/labetoul/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2012-03-21
11
12
13LISTE_SIMUL=${1}
14LISTE_DMNFS=${2}
15
16# ----
17export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}}
18export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
19export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
20mkdir -p ${IGCM_DEM}
21mkdir -p ${IGCM_TMP}
22clean_tmp=${clean_tmp:-yes}
23EXE_DIR=$(dirname ${0})
24SCRIPT_NAME=$(basename ${0} )
25source ${EXE_DIR}/DEM_utilities.sh
26
27# gpdebug : verif si le present script a ete execute jusqu'au bout #########
28MonitoringInfo="${SCRIPT_NAME}-->OK"
29generalMonitoring "$MonitoringInfo"
30
31DEM_log -0 "Demarrage de ${SCRIPT_NAME}"
32
33# gpdebug : on augmente la liste des proc à détruire en cas d'erreur bloquante du présent proc
34export listPID="$$ ${listPID}" #########
35
36cd ${JOB_DIR}
37# ----
38
39DEM_log -0 "LISTE_SIMUL : ${LISTE_SIMUL}"
40DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}"
41
42[[ -f ${IGCM_DEM}/config_card.liste ]] && rm ${IGCM_DEM}/config_card.liste
43
44
45for PATH_SIMUL_FULL in `awk  '{print $0}' ${LISTE_SIMUL}` ; do
46
47    DEM_log -3 PATH_SIMUL_FULL : ${PATH_SIMUL_FULL}
48    PATH_SIMUL_SHORT=$(echo ${PATH_SIMUL_FULL} | sed "s%${INPUT_DMF_DATA}/%%" ) # gpdebug : added
49    DEM_log -3 PATH_SIMUL_SHORT : ${PATH_SIMUL_SHORT}
50
51    IGCM_DEM_SIMU=${IGCM_DEM}/${PATH_SIMUL_SHORT}
52    mkdir -p ${IGCM_DEM_SIMU}
53    rm -rf ${IGCM_DEM_SIMU}/*
54
55    STORE_CP=${IGCM_DEM_SIMU}/store_cp
56    mkdir -p ${STORE_CP}
57
58### note dans cette version on ne gere pas les fichiers Monitoring ils sont deja la ou il faut et comme il faut
59    # on recherche le nom du job
60    JobName=""
61   
62
63    # Etablir la liste des fichiers d'Analyse
64    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Analyse  | awk '{print $3}' |  sort >> ${IGCM_TMP}/${$}.cp_analyse_files.list
65    awk -F/ '{if ($(NF)=="Analyse") print $0} ' ${IGCM_TMP}/${$}.cp_analyse_files.list > ${STORE_CP}/cp_files.list
66    rm -f ${IGCM_TMP}/${$}.cp_analyse_files.list
67
68
69    # Etablir la liste des fichiers de restart
70    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
71
72    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires au repetoire RESTART/
73    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt ` ; do
74        dir=$( echo $file | sed -e "s%.*RESTART/%%") 
75        testdir=$(dirname ${dir}) 
76        if [ $testdir != "." ]; then
77            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_restart_files_config.txt)  >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
78        fi
79    done
80    if [ -f ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ]; then
81        join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
82        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
83    fi
84   
85    # Etablir la liste des fichiers output
86    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Output  | awk '{print $2 " "  $3}' | grep -e '.*/Output/.*\.nc$'  | sort >> ${IGCM_TMP}/${$}.liste_output_files_config.txt
87    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires aux repetoires Output/*/
88    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_output_files_config.txt ` ; do
89        dir=$( echo $file | sed -e "s%.*Output/[^/]*/%%") 
90        testdir=$(dirname ${dir}) 
91        if [ $testdir != "." ]; then
92            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_output_files_config.txt ) >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
93        fi
94    done
95    if [ -f ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ]; then
96        join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_no_output_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
97        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_output_files_config.txt
98    fi
99
100    # Lecture du nom du job
101    JobName=`awk -F/ '{if (NR==1) print $(NF-2)}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt`
102
103    DEM_log -2 JobName ${JobName}
104
105   # traitons les listes de restart pour conserver ceux qui correspondent au format $JobName_restart_date_date.tar et $JobName_date_date_restart.tar
106   # on enleve les fichiers qui ne sont pas en .tar
107   grep -w "tar" ${IGCM_TMP}/${$}.liste_restart_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt; mv ${IGCM_TMP}/${$}.info_tmp.txt  ${IGCM_TMP}/${$}.liste_restart_files_config.txt
108   # dans ces fichiers on enleve ceux qui n'ont pas la chaine "restart" (attention suivant d'ou provient la simulation (pack ou libigcm) la chaine restart n'est pas situee au meme endroite
109   grep "restart"  ${IGCM_TMP}/${$}.liste_restart_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt; mv ${IGCM_TMP}/${$}.info_tmp.txt  ${IGCM_TMP}/${$}.liste_restart_files_config.txt
110   # dans ces fichiers on enleve ceux qui n'ont pas le jobName
111   grep $JobName ${IGCM_TMP}/${$}.liste_restart_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt; mv ${IGCM_TMP}/${$}.info_tmp.txt  ${IGCM_TMP}/${$}.liste_restart_files_config.txt   
112
113   mv ${IGCM_TMP}/${$}.liste_restart_files_config.txt    ${IGCM_DEM_SIMU}/liste_restart_files_config.txt
114
115# Maintenant que nous avons JobName verifions que tous les fichiers de Output sont bien du type JobName_date_*
116    sed -e "s%.*/${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_output_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
117    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
118    join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.output.tmp
119    sort -k 2 ${IGCM_TMP}/${$}.output.tmp > ${IGCM_TMP}/${$}.output_bis.tmp
120    mv ${IGCM_TMP}/${$}.output_bis.tmp ${IGCM_DEM_SIMU}/liste_output_files_config.txt
121
122
123## Recherche de DateBegin et DateEnd pour les Restarts
124    typeRestart=`awk -F_ '{if (NR==1) print $(NF)}'  ${IGCM_DEM_SIMU}/liste_restart_files_config.txt `
125    echo $typeRestart
126    if [[ "$typeRestart" == "restart.tar" ]]; then
127        first_file=$(        head -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
128        extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" | sed -e 's/_restart.tar//g' )
129        DateBegin_Restart=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
130
131        last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
132        extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" | sed -e 's/_restart.tar//g' )
133        DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/.*_\([0-9]\{8\}\).*$/\1/g' )
134    else
135        first_file=$(        head -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
136        extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_restart_//" | sed -e 's/\.tar//g' )
137        DateBegin_Restart=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
138
139        last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
140        extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_restart_//" | sed -e 's/\.tar//g' )
141        DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/.*_\([0-9]\{8\}\).*$/\1/g' )
142       
143    fi
144
145
146# Recherche de DateBegin et DateEnd pour les Output
147    first_file=$( head -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
148    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
149    DateBegin_Output=$(  echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
150   
151    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
152    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
153    DateEnd_Output=$(    echo ${extract_date_file}| sed 's/.*_\([0-9]\{8\}\)_.*$/\1/g' )
154   
155    DateBegin=${DateBegin_Restart}
156    DateEnd=${DateEnd_Restart}
157
158    DEM_log -2 "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
159    DEM_log -2 "DateBegin_Output DateEnd_Output : ${DateBegin_Output} ${DateEnd_Output}"
160    DEM_log -2 "DateBegin_Restart DateEnd_Restart : ${DateBegin_Restart} ${DateEnd_Restart}"
161
162    DateBegin=$( DEM_min ${DateBegin_Output} ${DateBegin} ) 
163    DateEnd=$(   DEM_max ${DateEnd_Output}   ${DateEnd}   )
164   
165    DEM_log -2  "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
166   
167    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.config_name ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
168   
169    rm -f ${IGCM_DEM_SIMU}/config_card_${JobName}
170    cat<<EOD>${IGCM_DEM_SIMU}/config_card_${JobName}
171JobName=${JobName}
172DateBegin=${DateBegin}
173DateEnd=${DateEnd}
174PATH_SIMUL_FULL=${PATH_SIMUL_FULL}
175IGCM_DEM_SIMU=${IGCM_DEM_SIMU}
176EOD
177   
178    echo "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone" >> ${IGCM_DEM}/config_card.liste
179
180    DEM_log -1 "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone >> ${IGCM_DEM}/config_card.liste"
181
182#si la liste des fichiers d'output est vide on tar la simul
183if [[ !  -s ${IGCM_DEM_SIMU}/liste_output_files_config.txt ]]; then
184DEM_log -2 "liste output vide"
185    cd ${EXE_DIR}
186    ./write_liste_tar.sh ${IGCM_DEM_SIMU}/config_card_${JobName}
187    cd ${JOB_DIR}
188fi
189
190
191done
192
193# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
194echo $MonitoringInfo >> $generalMonitorFile
195
196DEM_log -0 "Fin de ${SCRIPT_NAME}"
197
Note: See TracBrowser for help on using the repository browser.