source: TOOLS/PACK_IPSL/find_directory_simul.sh @ 1838

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

Correct a bug on date end for debug pack

File size: 5.1 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    # arnaud : on teste si il y a des fichiers dans les repertoires Restart
60    nb_restart_non_vide=0
61    for irestart in $listRestart
62    do
63        if [ `find $irestart/Restart -type f | wc -l` -ne 0 ] ;
64        then
65            ((  nb_restart_non_vide = nb_restart_non_vide + 1 ))
66            continue
67        fi
68    done
69   
70    if ( [ "x${listRestart}" == "x" ] || [ $nb_restart_non_vide -eq 0 ] ) ;
71    then
72        # DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Pas de Repertoire Restart dans ${DIR}" "${$}" # gpdebug : a virer ########
73        echo "########## Attention :"
74        echo "${SCRIPT_NAME}:${LINENO}:Pas de Repertoire Restart ou de fichiers Restart dans ${DIR}"
75        continue
76    fi
77    echo "${listRestart}" >> ${IGCM_TMP}/${$}.liste_Restart.txt
78    # gpdebug : fin #########################################################################################################################   
79done
80# DEM_errorSend "${SCRIPT_NAME}:${LINENO}:On arrete expres !" $$ # gpdebug : a virer ########
81
82# Pour le cas ou aucune simu n aurait ete detectee
83if [ -e  ${IGCM_TMP}/${$}.liste_Restart.txt ]
84then
85   listRestartNbLines=`cat ${IGCM_TMP}/${$}.liste_Restart.txt | wc -l `
86   if [ "x${listRestartNbLines}" == "x0" ]
87   then
88      DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Il n existe aucune simulation !" # "${$}"
89   fi
90else
91   DEM_errorSend "${SCRIPT_NAME}:${LINENO}:Il n existe aucune simulation !" # "${$}"
92fi
93
94
95 
96# On cherche le path (deux crans au dessus des repertoires Restart)
97DEM_log -1 "Recherche du path"
98
99for DIR in  $( awk '{print $0}' ${IGCM_TMP}/${$}.liste_Restart.txt ) ; do
100    DEM_log -3 ${SCRIPT_NAME} - Recherche path : ${DIR}
101
102#gestion des cas particulier tels que la creation de l'etat initial avec lmdz (JobName/ATM/Output/Restart/ au lieu de JobName/ATM/Restart/)
103    PATH_SIM=$( dirname ${DIR} )
104    lastdir=$( echo $PATH_SIM | sed -e "s%.*/%%")
105    if [ $lastdir != "ATM" ]; then
106        dirname ${DIR} >> ${IGCM_TMP}/${$}.path_simul.txt
107    else
108        dirname ${PATH_SIM} >> ${IGCM_TMP}/${$}.path_simul.txt
109    fi
110
111done
112
113# On retire les doublons pour avoir la liste des simulations a tester
114DEM_log -1 "Suppression des doublons"
115
116awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <${IGCM_TMP}/${$}.path_simul.txt  >> liste_simul_${LISTE_SIMUL_NAME}
117awk '{if (x[$0] != "") next ; print $0 ; x[$0]=$0}' <liste_simul_${LISTE_SIMUL_NAME}  >> liste_simul_${LISTE_SIMUL_NAME}.tmp${$}
118mv liste_simul_${LISTE_SIMUL_NAME}.tmp${$} ${IGCM_DEM}/liste_simul_${LISTE_SIMUL_NAME}
119rm -f liste_simul_${LISTE_SIMUL_NAME}
120
121# gpdebug : envoi du nombre de simu dans un "nbSimu.txt" du rep de suivi
122echo `cat ${IGCM_DEM}/liste_simul_${LISTE_SIMUL_NAME} | wc -l ` > $nbSimuFile
123
124DEM_log -1 "Fichier cree : liste_simul_${LISTE_SIMUL_NAME}"
125
126
127[[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.path_simul.txt
128[[ "${clean_tmp}" = "yes" ]] && rm -f ${IGCM_TMP}/${$}.liste_Restart.txt
129
130# gpdebug : le script n'a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi
131echo $MonitoringInfo >> $generalMonitorFile
132
133DEM_log -0 "Fin de ${SCRIPT_NAME}"
Note: See TracBrowser for help on using the repository browser.