source: TOOLS/PACK_IPSL/create_config_card.sh @ 1729

Last change on this file since 1729 was 1728, checked in by acosce, 12 years ago
  • add creation of debug list
  • standardization of lists name
File size: 9.0 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 de restart
69    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
70
71    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires au repetoire restart/
72    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt ` ; do
73        dir=$( echo $file | sed -e "s%.*Restart/%%") 
74        testdir=$(dirname ${dir}) 
75        if [ $testdir != "." ]; then
76            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_restart_files_config.txt)  >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
77        fi
78    done
79    if [ -f ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ]; then
80        join -t % -v 1 ${IGCM_TMP}/${$}.liste_restart_files_config.txt ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
81        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
82    fi
83   
84    # Etablir la liste des fichiers output
85    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Output  | awk '{print $2 " "  $3}' | grep -e '.*/Output/.*\.nc$'  | sort >> ${IGCM_TMP}/${$}.liste_output_files_config.txt
86    # Retirons de la liste les fichiers que l'on n'attends pas, en particulier si il  y a des sous-repertoires aux repetoires Output/*/
87    for file in `awk  '{print $2}'  ${IGCM_TMP}/${$}.liste_output_files_config.txt ` ; do
88        dir=$( echo $file | sed -e "s%.*Output/[^/]*/%%") 
89        testdir=$(dirname ${dir}) 
90        if [ $testdir != "." ]; then
91            echo $( grep ${file} ${IGCM_TMP}/${$}.liste_output_files_config.txt ) >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
92        fi
93    done
94    if [ -f ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ]; then
95        join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_no_output_files_config.txt > ${IGCM_TMP}/${$}.info_tmp.txt
96        mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_output_files_config.txt
97    fi
98
99
100    # Etablir la liste des fichiers d'Analyse
101    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Analyse  | awk '{print $2 " "  $3}' |  sort >> ${STORE_CP}/cp_analyse_files.list
102
103
104    # Etablir la liste des fichiers Monito et Atlas
105    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep  MONITORING | awk '{print $2 " "  $3}' | sort >> ${WORK_CP}/cp_monito_files.list
106    grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep  ATLAS | awk '{print $2 " "  $3}' | sort >> ${WORK_CP}/cp_atlas_files.list
107   
108
109
110    # Lecture du nom du job
111    JobName=`awk -F/ '{if (NR==1) print $(NF-3)}'  ${IGCM_TMP}/${$}.liste_restart_files_config.txt`
112    DEM_log -2 JobName ${JobName}
113
114
115# Maintenant que nous avons JobName verifions que tous les fichiers de restart/Output sont bien du type JobName_date_*
116    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_restart_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_restart_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.restart.tmp
119    sort -k 2 ${IGCM_TMP}/${$}.restart.tmp > ${IGCM_TMP}/${$}.restart_bis.tmp
120    mv ${IGCM_TMP}/${$}.restart_bis.tmp ${IGCM_DEM_SIMU}/liste_restart_files_config.txt
121# Sauvegarde des fichiers qui ne sont pas dans la norme
122    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt
123    mv ${IGCM_TMP}/${$}.liste_no_restart_files_config.txt ${OTHER_TAR}/tar_no_restart_files.list
124
125
126    sed -e "s%.*${JobName}_\([0-9]\{8\}\)_%%" ${IGCM_TMP}/${$}.liste_output_files_config.txt  >  ${IGCM_TMP}/${$}.info_tmp.txt
127    cat ${IGCM_TMP}/${$}.info_tmp.txt |grep "/" >  ${IGCM_TMP}/${$}.info_tmp_bis.txt
128    join -t % -v 1 ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.info_tmp_bis.txt > ${IGCM_TMP}/${$}.output.tmp
129    sort -k 2 ${IGCM_TMP}/${$}.output.tmp > ${IGCM_TMP}/${$}.output_bis.tmp
130    mv ${IGCM_TMP}/${$}.output_bis.tmp ${IGCM_DEM_SIMU}/liste_output_files_config.txt
131# Sauvegarde des fichiers qui ne sont pas dans la norme
132    cat ${IGCM_TMP}/${$}.info_tmp_bis.txt >> ${IGCM_TMP}/${$}.liste_no_output_files_config.txt
133    mv ${IGCM_TMP}/${$}.liste_no_output_files_config.txt ${OTHER_TAR}/tar_no_output_files.list
134
135
136# Recherche de DateBegin et DateEnd pour les Restarts
137    first_file=$(        head -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
138    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
139    DateBegin_Restart=$( echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
140   
141    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_restart_files_config.txt )
142    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
143    DateEnd_Restart=$(   echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
144   
145# Recherche de DateBegin et DateEnd pour les Output
146    first_file=$( head -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
147    extract_date_file=$( echo ${first_file}  | sed -e "s/.*${JobName}_//" )
148    DateBegin_Output=$(  echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
149   
150    last_file=$(         tail -n 1 ${IGCM_DEM_SIMU}/liste_output_files_config.txt )
151    extract_date_file=$( echo ${last_file}  | sed -e "s/.*${JobName}_//" )
152    DateEnd_Output=$(    echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
153   
154    DateBegin=${DateBegin_Restart}
155    DateEnd=${DateEnd_Restart}
156
157    DEM_log -2 "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
158    DEM_log -2 "DateBegin_Output DateEnd_Output : ${DateBegin_Output} ${DateEnd_Output}"
159    DEM_log -2 "DateBegin_Restart DateEnd_Restart : ${DateBegin_Restart} ${DateEnd_Restart}"
160
161    DateBegin=$( DEM_min ${DateBegin_Output} ${DateBegin} )
162    DateEnd=$(   DEM_max ${DateEnd_Output}   ${DateEnd}   )
163   
164    DEM_log -2  "DateBegin DateEnd : ${DateBegin} ${DateEnd}"
165   
166    [[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.config_name ${IGCM_TMP}/${$}.liste_output_files_config.txt ${IGCM_TMP}/${$}.liste_restart_files_config.txt
167   
168    rm -f ${IGCM_DEM_SIMU}/config_card_${JobName}
169    cat<<EOD>${IGCM_DEM_SIMU}/config_card_${JobName}
170JobName=${JobName}
171DateBegin=${DateBegin}
172DateEnd=${DateEnd}
173PATH_SIMUL_FULL=${PATH_SIMUL_FULL}
174IGCM_DEM_SIMU=${IGCM_DEM_SIMU}
175EOD
176   
177    echo "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone" >> ${IGCM_DEM}/config_card.liste
178
179    DEM_log -1 "${IGCM_DEM_SIMU}/config_card_${JobName} ListToBeDone >> ${IGCM_DEM}/config_card.liste"
180
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    ./write_liste_tar.sh ${IGCM_DEM_SIMU}/config_card_${JobName}
186fi 
187
188# si les listes no_output et no_restart sont vides on les efface
189if [[ !  -s ${OTHER_TAR}/tar_no_output_files.list ]]; then
190    rm -f ${OTHER_TAR}/tar_no_output_files.list
191fi
192
193if [[ !  -s ${OTHER_TAR}/tar_no_restart_files.list ]]; then
194    rm -f ${OTHER_TAR}/tar_no_restart_files.list
195fi
196
197
198done
199
200DEM_log -0 "Fin de ${SCRIPT_NAME}"
201
Note: See TracBrowser for help on using the repository browser.