source: TOOLS/PACK_IPSL/find_directory_simul.sh @ 1852

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

Modified to take into account only simulations which have restart files

File size: 4.7 KB
Line 
1#!/bin/bash
2# set -vx # gpdebug : a virer ########
3# prend en argument le path et le nom d'un fichier param (argument de la commande
4# ccc_archive avec option ipsl_pack)
5# ex : ./find_directory_simul.job  fichier_param_test1.txt liste_fichier_dmnfs
6# ex : find_directory_simul.job param_SL.txt /cscratch/cont003/labetoul/FROM_CCRT_INFORMATIONS_DMNFS/information_dmnfs_2012-03-21
7
8#-------------------------------
9# A modifier avant utilisation :
10#--------------------------------
11
12LISTE_SIMUL=${1}
13LISTE_DMNFS=${2}
14echo $LISTE_SIMUL $LISTE_DMNFS
15# ----
16export JOB_DIR=${JOB_DIR:-${PWD}}
17export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
18export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
19mkdir -p ${IGCM_DEM}
20mkdir -p ${IGCM_TMP}
21clean_tmp=${clean_tmp:-yes}
22EXE_DIR=$(dirname ${0})
23SCRIPT_NAME=$(basename ${0} )
24source ${EXE_DIR}/DEM_utilities.sh
25
26echo "apres sources" ${SCRIPT_NAME}
27
28# gpdebug : verif si le present script a ete execute jusqu'au bout #########
29MonitoringInfo="${SCRIPT_NAME}-->OK"
30generalMonitoring "$MonitoringInfo"
31
32DEM_log -0 "Demmarrage de ${SCRIPT_NAME}"
33
34cd ${JOB_DIR}
35# ----
36# gpdebug : Execute la function errorReceive() si reception d'un signal TERM
37trap 'DEM_errorReceive' TERM ########
38
39# gpdebug : on augmente la liste des proc à détruire en cas d'erreur bloquante du présent proc
40export listPID="$$ ${listPID}" #########
41
42LISTE_SIMUL=${1}
43LISTE_DMNFS=${2}
44
45LISTE_SIMUL_NAME=$(basename ${LISTE_SIMUL} )
46
47echo "gpdebug : ${IGCM_TMP}/${$}.liste_Restart.txt" # gpdebug : a virer  #######
48
49# Pour tous les fichiers ou repertoires contenus dans le fichier de parametres
50for DIR in $( awk '{print $0}' ${LISTE_SIMUL} ) ; do
51
52    DEM_log -1 ${SCRIPT_NAME} - Inspection de ${DIR}"/"
53    # trouve la liste des repertoires restart sous l'arborescence   
54   
55    # grep ${DIR}"/" ${LISTE_DMNFS} | grep Restart | awk '{print $3}' | sed 's%/Restart.*%%'  >> ${IGCM_TMP}/${$}.liste_Restart.txt # gpdebug : suppr
56   
57    # gpdebug : s'il n'y a pas de rep Restart, on saute ###############################################################################
58    listRestart=`grep ${DIR}"/" ${LISTE_DMNFS} | grep Restart/ | awk '{print $3}' | sed 's%/Restart.*%%' `
59
60    if [ "x${listRestart}" == "x" ] ;
61    then
62        # DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Pas de Repertoire Restart dans ${DIR}" "${$}" # gpdebug : a virer ########
63        echo "########## Attention :"
64        echo "${SCRIPT_NAME}:${LINENO}:Pas de Repertoire Restart ou de fichiers Restart dans ${DIR}"
65        continue
66    fi
67    echo "${listRestart}" >> ${IGCM_TMP}/${$}.liste_Restart.txt
68    # gpdebug : fin #########################################################################################################################   
69done
70# DEM_errorSend "${SCRIPT_NAME}:${LINENO}:On arrete expres !" $$ # gpdebug : a virer ########
71
72# Pour le cas ou aucune simu n aurait ete detectee
73if [ -e  ${IGCM_TMP}/${$}.liste_Restart.txt ]
74then
75   listRestartNbLines=`cat ${IGCM_TMP}/${$}.liste_Restart.txt | wc -l `
76   if [ "x${listRestartNbLines}" == "x0" ]
77   then
78      DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Il n existe aucune simulation !" # "${$}"
79   fi
80else
81   DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Il n existe aucune simulation !" # "${$}"
82fi
83
84
85 
86# On cherche le path (deux crans au dessus des repertoires Restart)
87DEM_log -1 "Recherche du path"
88
89for DIR in  $( awk '{print $0}' ${IGCM_TMP}/${$}.liste_Restart.txt ) ; do
90    DEM_log -3 ${SCRIPT_NAME} - Recherche path : ${DIR}
91
92#gestion des cas particulier tels que la creation de l'etat initial avec lmdz (JobName/ATM/Output/Restart/ au lieu de JobName/ATM/Restart/)
93    PATH_SIM=$( dirname ${DIR} )
94    lastdir=$( echo $PATH_SIM | sed -e "s%.*/%%")
95    if [ $lastdir != "ATM" ]; then
96        dirname ${DIR} >> ${IGCM_TMP}/${$}.path_simul.txt
97    else
98        dirname ${PATH_SIM} >> ${IGCM_TMP}/${$}.path_simul.txt
99    fi
100
101done
102
103# On retire les doublons pour avoir la liste des simulations a tester
104DEM_log -1 "Suppression des doublons"
105
106awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <${IGCM_TMP}/${$}.path_simul.txt  >> liste_simul_${LISTE_SIMUL_NAME}
107awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <liste_simul_${LISTE_SIMUL_NAME}  >> liste_simul_${LISTE_SIMUL_NAME}.tmp${$}
108mv liste_simul_${LISTE_SIMUL_NAME}.tmp${$} ${IGCM_DEM}/liste_simul_${LISTE_SIMUL_NAME}
109rm -f liste_simul_${LISTE_SIMUL_NAME}
110
111# gpdebug : envoi du nombre de simu dans un "nbSimu.txt" du rep de suivi
112echo `cat ${IGCM_DEM}/liste_simul_${LISTE_SIMUL_NAME} | wc -l ` > $nbSimuFile
113
114DEM_log -1 "Fichier cree : liste_simul_${LISTE_SIMUL_NAME}"
115
116
117[[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.path_simul.txt
118[[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_Restart.txt
119
120# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
121echo $MonitoringInfo >> $generalMonitorFile
122
123DEM_log -0 "Fin de ${SCRIPT_NAME}"
Note: See TracBrowser for help on using the repository browser.