source: TOOLS/PACK_IPSL/create_config_card.sh @ 1884

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

Correction suppression mesh_mask

File size: 11.2 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#    PATH_SIMUL_SHORT=$(echo ${PATH_SIMUL_FULL} | sed 's%/ccc/dmfbuf/import_data.2/ccrt/dmnfs12/cont003/bacasable/%%' )
56    echo "gpdebug : PATH_SIMUL_FULL :" # gpdebug : a virer
57    echo "$PATH_SIMUL_FULL :" # gpdebug : a virer
58    PATH_SIMUL_SHORT=$(echo ${PATH_SIMUL_FULL} | sed "s%${INPUT_DMF_DATA}/%%" ) # gpdebug : added
59    echo "gpdebug : PATH_SIMUL_SHORT :" # gpdebug : a virer
60    echo "$PATH_SIMUL_SHORT :" # gpdebug : a virer 
61    DEM_log -3 PATH_SIMUL_SHORT : ${PATH_SIMUL_SHORT}
62   
63    IGCM_DEM_SIMU=${IGCM_DEM}/${PATH_SIMUL_SHORT}
64    mkdir -p ${IGCM_DEM_SIMU}
65    rm -rf ${IGCM_DEM_SIMU}/*
66
67    #creation du repertoire permettant de stocker
68    #les listes de fichiers qui ne sont pas au format output ou restart
69    #les listes de fichiers d'analyse, les monitos et les atlas
70    OTHER_TAR=${IGCM_DEM_SIMU}/other_tar
71    STORE_CP=${IGCM_DEM_SIMU}/store_cp
72    WORK_CP=${IGCM_DEM_SIMU}/work_cp
73
74    DEM_log -2 "creation des repertoires : $OTHER_TAR  - $STORE_CP - $WORK_CP"
75
76    mkdir -p ${OTHER_TAR}
77    mkdir -p ${STORE_CP}
78    mkdir -p ${WORK_CP}
79
80    # on recherche le nom du job
81    JobName=""
82   
83    # Etablir la liste des fichiers d'Analyse
84    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Analyse  | awk '{print $3}' |  sort >> ${IGCM_TMP}/${$}.cp_analyse_files.list
85    awk -F/ '{if ($(NF)=="Analyse") print $0} ' ${IGCM_TMP}/${$}.cp_analyse_files.list > ${STORE_CP}/cp_files.list
86    rm -f ${IGCM_TMP}/${$}.cp_analyse_files.list
87
88    #On recupere egalement le fichier mesh_mask si il existe
89    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep mesh_mask | awk '{print $3}' >> ${STORE_CP}/cp_files.list
90    mesh_mask_path=$( grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep mesh_mask | awk '{print $3}' )
91    grep -v $mesh_mask_path ${LISTE_DMNFS} > ${IGCM_TMP}/${$}.Listing_tmp.txt; mv ${IGCM_TMP}/${$}.Listing_tmp.txt ${LISTE_DMNFS} 
92
93    #On copie aussi le contenu du repertoire Exe/
94    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep -w Exe | awk '{print $3}' >> ${IGCM_TMP}/${$}.cp_analyse_files.list
95    awk -F/ '{if ($(NF)=="Exe") print $0} ' ${IGCM_TMP}/${$}.cp_analyse_files.list >> ${STORE_CP}/cp_files.list
96    rm -f ${IGCM_TMP}/${$}.cp_analyse_files.list
97   
98
99    # Etablir la liste des fichiers Monito et Atlas
100    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep  MONITORING | awk '{print $3}' | sort >> ${IGCM_TMP}/${$}.cp_monito_files.list
101    awk -F/ '{if ($(NF)=="MONITORING") print $0} ' ${IGCM_TMP}/${$}.cp_monito_files.list > ${WORK_CP}/cp_files.list
102    rm -f ${IGCM_TMP}/${$}.cp_monito_files.list
103
104    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep  ATLAS | awk '{print $3}' | sort >> ${IGCM_TMP}/${$}.cp_atlas_files.list
105    awk -F/ '{if ($(NF)=="ATLAS") print $0} ' ${IGCM_TMP}/${$}.cp_atlas_files.list >> ${WORK_CP}/cp_files.list
106    rm -f ${IGCM_TMP}/${$}.cp_atlas_files.list
107
108    # Etablir la liste des fichiers de restart
109    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
110
111    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires au repetoire restart/
112    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt ` ; do
113        dir=$( echo $file | sed -e "s%.*Restart/%%") 
114        testdir=$(dirname ${dir}) 
115        if [ $testdir != "." ]; then
116            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_restart_files_config.txt)  >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
117        fi
118    done
119    if [ -f ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ]; then
120        join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
121        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
122    fi
123   
124    # Etablir la liste des fichiers output
125    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Output  | awk '{print $2 " "  $3}' | grep -e '.*/Output/.*\.nc$'  | sort >> ${IGCM_TMP}/${$}.liste_output_files_config.txt
126    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires aux repetoires Output/*/
127    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_output_files_config.txt ` ; do
128        dir=$( echo $file | sed -e "s%.*Output/[^/]*/%%") 
129        testdir=$(dirname ${dir}) 
130        if [ $testdir != "." ]; then
131            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_output_files_config.txt ) >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
132        fi
133    done
134    if [ -f ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ]; then
135        join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_no_output_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
136        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_output_files_config.txt
137    fi
138
139
140
141
142    # Lecture du nom du job
143    JobName=`awk -F/ '{if (NR==1) print $(NF-3)}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt`
144
145    if [ $JobName = "ATM" ]; then
146        JobName=`awk -F/ '{if (NR==1) print $(NF-4)}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt`
147    fi
148    DEM_log -2 JobName ${JobName}
149
150
151# Maintenant que nous avons JobName verifions que tous les fichiers de restart/Output sont bien du type JobName_date_*
152    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_restart_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
153    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
154    join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.restart.tmp
155    sort -k 2 ${IGCM_TMP}/${$}.restart.tmp > ${IGCM_TMP}/${$}.restart_bis.tmp
156    mv ${IGCM_TMP}/${$}.restart_bis.tmp ${IGCM_DEM_SIMU}/liste_restart_files_config.txt
157# Sauvegarde des fichiers qui ne sont pas dans la norme
158    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
159    mv ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ${OTHER_TAR}/tar_no_restart_files.list
160
161
162    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_output_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
163    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
164    join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.output.tmp
165    sort -k 2 ${IGCM_TMP}/${$}.output.tmp > ${IGCM_TMP}/${$}.output_bis.tmp
166    mv ${IGCM_TMP}/${$}.output_bis.tmp ${IGCM_DEM_SIMU}/liste_output_files_config.txt
167# Sauvegarde des fichiers qui ne sont pas dans la norme
168    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
169    mv ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ${OTHER_TAR}/tar_no_output_files.list
170
171
172# Recherche de DateBegin et DateEnd pour les Restarts
173    first_file=$(        head -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
174    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
175    DateBegin_Restart=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
176   
177    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
178    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
179    DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
180   
181# Recherche de DateBegin et DateEnd pour les Output
182    first_file=$( head -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
183    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
184    DateBegin_Output=$(  echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
185   
186    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
187    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
188    DateEnd_Output=$(    echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
189   
190    DateBegin=${DateBegin_Restart}
191    DateEnd=${DateEnd_Restart}
192
193    DEM_log -2 "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
194    DEM_log -2 "DateBegin_Output DateEnd_Output : ${DateBegin_Output} ${DateEnd_Output}"
195    DEM_log -2 "DateBegin_Restart DateEnd_Restart : ${DateBegin_Restart} ${DateEnd_Restart}"
196
197    DateBegin=$( DEM_min ${DateBegin_Output} ${DateBegin} ) 
198    DateEnd=$(   DEM_max ${DateEnd_Output}   ${DateEnd}   )
199   
200    DEM_log -2  "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
201   
202    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.config_name ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
203   
204    rm -f ${IGCM_DEM_SIMU}/config_card_${JobName}
205    cat<<EOD>${IGCM_DEM_SIMU}/config_card_${JobName}
206JobName=${JobName}
207DateBegin=${DateBegin}
208DateEnd=${DateEnd}
209PATH_SIMUL_FULL=${PATH_SIMUL_FULL}
210IGCM_DEM_SIMU=${IGCM_DEM_SIMU}
211EOD
212   
213    echo "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone" >> ${IGCM_DEM}/config_card.liste
214
215    DEM_log -1 "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone >> ${IGCM_DEM}/config_card.liste"
216
217
218#si la liste des fichiers d'output est vide on tar la simul
219if [[ !  -s ${IGCM_DEM_SIMU}/liste_output_files_config.txt ]]; then
220DEM_log -2 "liste output vide"
221    ./write_liste_tar.sh ${IGCM_DEM_SIMU}/config_card_${JobName}
222fi
223
224# si les listes no_output et no_restart sont vides on les efface
225if [[ !  -s ${OTHER_TAR}/tar_no_output_files.list ]]; then
226    rm -f ${OTHER_TAR}/tar_no_output_files.list
227fi
228
229if [[ !  -s ${OTHER_TAR}/tar_no_restart_files.list ]]; then
230    rm -f ${OTHER_TAR}/tar_no_restart_files.list
231fi
232
233
234done
235
236# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
237echo $MonitoringInfo >> $generalMonitorFile
238
239DEM_log -0 "Fin de ${SCRIPT_NAME}"
240
Note: See TracBrowser for help on using the repository browser.