source: TOOLS/PACK_IPSL/create_config_card.sh @ 1753

Last change on this file since 1753 was 1753, checked in by acosce, 12 years ago

Correct a little bug in create_config (mig ccrt/tgcc)

File size: 9.6 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
27DEM_log -0 "Demarrage de ${SCRIPT_NAME}"
28cd ${JOB_DIR}
29# ----
30
31DEM_log -0 "LISTE_SIMUL : ${LISTE_SIMUL}"
32DEM_log -0 "LISTE_DMNFS : ${LISTE_DMNFS}"
33
34[[ -f ${IGCM_DEM}/config_card.liste ]] && rm ${IGCM_DEM}/config_card.liste
35
36#ROOT_DIR=/dmnfs05/cont003/labetoul # soit DMFDIR, soit le tampon. a ameliorer ...
37
38
39cd ${JOB_DIR}
40
41for PATH_SIMUL_FULL in `awk  '{print $0}' ${LISTE_SIMUL}` ; do
42
43    DEM_log -3 PATH_SIMUL_FULL : ${PATH_SIMUL_FULL}
44    #PATH_SIMUL_SHORT=${PATH_SIMUL_FULL##${ROOT_DIR}} # Enleve le debut du path
45    PATH_SIMUL_SHORT=$(echo ${PATH_SIMUL_FULL} | sed 's%/[^/]*/[^/]*/[^/]*/%%' )
46    DEM_log -3 PATH_SIMUL_SHORT : ${PATH_SIMUL_SHORT}
47   
48    IGCM_DEM_SIMU=${IGCM_DEM}/${PATH_SIMUL_SHORT}
49    mkdir -p ${IGCM_DEM_SIMU}
50    rm -rf ${IGCM_DEM_SIMU}/*
51
52    #creation du repertoire permettant de stocker
53    #les listes de fichiers qui ne sont pas au format output ou restart
54    #les listes de fichiers d'analyse, les monitos et les atlas
55    OTHER_TAR=${IGCM_DEM_SIMU}/other_tar
56    STORE_CP=${IGCM_DEM_SIMU}/store_cp
57    WORK_CP=${IGCM_DEM_SIMU}/work_cp
58
59    DEM_log -2 "creation des repertoires : $OTHER_TAR  - $STORE_CP - $WORK_CP"
60
61    mkdir -p ${OTHER_TAR}
62    mkdir -p ${STORE_CP}
63    mkdir -p ${WORK_CP}
64
65    # on recherche le nom du job
66    JobName=""
67   
68    # Etablir la liste des fichiers d'Analyse
69    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Analyse  | awk '{print $3}' |  sort >> ${IGCM_TMP}/${$}.cp_analyse_files.list
70    awk -F/ '{if ($(NF)=="Analyse") print $0} ' ${IGCM_TMP}/${$}.cp_analyse_files.list > ${STORE_CP}/cp_files.list
71
72    #On recupere egalement le fichier mesh_mask si il existe
73    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep mesh_mask | awk '{print $3}' >> ${STORE_CP}/cp_files.list
74    sed '/mesh_mask/d' ${LISTE_DMNFS} > ${IGCM_TMP}/${$}.Listing_tmp.txt; mv ${IGCM_TMP}/${$}.Listing_tmp.txt ${LISTE_DMNFS}
75
76    # Etablir la liste des fichiers Monito et Atlas
77    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep  MONITORING | awk '{print $3}' | sort >> ${IGCM_TMP}/${$}.cp_monito_files.list
78    awk -F/ '{if ($(NF)=="MONITORING") print $0} ' ${IGCM_TMP}/${$}.cp_monito_files.list > ${WORK_CP}/cp_files.list
79
80    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep  ATLAS | awk '{print $3}' | sort >> ${IGCM_TMP}/${$}.cp_atlas_files.list
81    awk -F/ '{if ($(NF)=="ATLAS") print $0} ' ${IGCM_TMP}/${$}.cp_atlas_files.list >> ${WORK_CP}/cp_files.list
82   
83
84    # Etablir la liste des fichiers de restart
85    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
86
87    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires au repetoire restart/
88    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt ` ; do
89        dir=$( echo $file | sed -e "s%.*Restart/%%") 
90        testdir=$(dirname ${dir}) 
91        if [ $testdir != "." ]; then
92            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_restart_files_config.txt)  >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
93        fi
94    done
95    if [ -f ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ]; then
96        join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
97        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
98    fi
99   
100    # Etablir la liste des fichiers output
101    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Output  | awk '{print $2 " "  $3}' | grep -e '.*/Output/.*\.nc$'  | sort >> ${IGCM_TMP}/${$}.liste_output_files_config.txt
102    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires aux repetoires Output/*/
103    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_output_files_config.txt ` ; do
104        dir=$( echo $file | sed -e "s%.*Output/[^/]*/%%") 
105        testdir=$(dirname ${dir}) 
106        if [ $testdir != "." ]; then
107            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_output_files_config.txt ) >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
108        fi
109    done
110    if [ -f ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ]; then
111        join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_no_output_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
112        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_output_files_config.txt
113    fi
114
115
116
117
118    # Lecture du nom du job
119    JobName=`awk -F/ '{if (NR==1) print $(NF-3)}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt`
120    DEM_log -2 JobName ${JobName}
121
122
123# Maintenant que nous avons JobName verifions que tous les fichiers de restart/Output sont bien du type JobName_date_*
124    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_restart_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
125    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
126    join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.restart.tmp
127    sort -k 2 ${IGCM_TMP}/${$}.restart.tmp > ${IGCM_TMP}/${$}.restart_bis.tmp
128    mv ${IGCM_TMP}/${$}.restart_bis.tmp ${IGCM_DEM_SIMU}/liste_restart_files_config.txt
129# Sauvegarde des fichiers qui ne sont pas dans la norme
130    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
131    mv ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ${OTHER_TAR}/tar_no_restart_files.list
132
133
134    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_output_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
135    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
136    join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.output.tmp
137    sort -k 2 ${IGCM_TMP}/${$}.output.tmp > ${IGCM_TMP}/${$}.output_bis.tmp
138    mv ${IGCM_TMP}/${$}.output_bis.tmp ${IGCM_DEM_SIMU}/liste_output_files_config.txt
139# Sauvegarde des fichiers qui ne sont pas dans la norme
140    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
141    mv ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ${OTHER_TAR}/tar_no_output_files.list
142
143
144# Recherche de DateBegin et DateEnd pour les Restarts
145    first_file=$(        head -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
146    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
147    DateBegin_Restart=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
148   
149    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
150    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
151    DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
152   
153# Recherche de DateBegin et DateEnd pour les Output
154    first_file=$( head -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
155    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
156    DateBegin_Output=$(  echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
157   
158    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
159    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
160    DateEnd_Output=$(    echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
161   
162    DateBegin=${DateBegin_Restart}
163    DateEnd=${DateEnd_Restart}
164
165    DEM_log -2 "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
166    DEM_log -2 "DateBegin_Output DateEnd_Output : ${DateBegin_Output} ${DateEnd_Output}"
167    DEM_log -2 "DateBegin_Restart DateEnd_Restart : ${DateBegin_Restart} ${DateEnd_Restart}"
168
169    DateBegin=$( DEM_min ${DateBegin_Output} ${DateBegin} ) 
170    DateEnd=$(   DEM_max ${DateEnd_Output}   ${DateEnd}   )
171   
172    DEM_log -2  "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
173   
174    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.config_name ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
175   
176    rm -f ${IGCM_DEM_SIMU}/config_card_${JobName}
177    cat<<EOD>${IGCM_DEM_SIMU}/config_card_${JobName}
178JobName=${JobName}
179DateBegin=${DateBegin}
180DateEnd=${DateEnd}
181PATH_SIMUL_FULL=${PATH_SIMUL_FULL}
182IGCM_DEM_SIMU=${IGCM_DEM_SIMU}
183EOD
184   
185    echo "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone" >> ${IGCM_DEM}/config_card.liste
186
187    DEM_log -1 "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone >> ${IGCM_DEM}/config_card.liste"
188
189
190#si la liste des fichiers d'output est vide on tar la simul
191if [[ !  -s ${IGCM_DEM_SIMU}/liste_output_files_config.txt ]]; then
192DEM_log -2 "liste output vide"
193    ./write_liste_tar.sh ${IGCM_DEM_SIMU}/config_card_${JobName}
194fi
195
196# si les listes no_output et no_restart sont vides on les efface
197if [[ !  -s ${OTHER_TAR}/tar_no_output_files.list ]]; then
198    rm -f ${OTHER_TAR}/tar_no_output_files.list
199fi
200
201if [[ !  -s ${OTHER_TAR}/tar_no_restart_files.list ]]; then
202    rm -f ${OTHER_TAR}/tar_no_restart_files.list
203fi
204
205
206done
207
208DEM_log -0 "Fin de ${SCRIPT_NAME}"
209
Note: See TracBrowser for help on using the repository browser.