#!/bin/bash


#cree le listing du repertoire REPtoLISTE ($1) 
#exemple REPtoList=/dmnfs09/cont003/p86cadul/IGCM_OUT

REPtoList=$1


EXE_DIR=$(dirname ${0})
SCRIPT_NAME=$(basename ${0} )
export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}

source ${EXE_DIR}/DEM_utilities.sh
DEM_log -0 "Demarrage de ${SCRIPT_NAME}"

find $REPtoList -printf "%y %s %p \n" >> ${IGCM_DEM}/Listing.txt

cd $EXE_DIR
#lors de la creation de la liste on retire les repertoires SPIN qui seront traites ulterieurement par le ccrt 
sed '/SPIN/d' ${IGCM_DEM}/Listing.txt > ${IGCM_TMP}/Listing_tmp.txt; mv ${IGCM_TMP}/Listing_tmp.txt ${IGCM_DEM}/Listing.txt
# on retire les fichiers issus de liens : le champ de la premiere colonne est alors un l 
awk '{if ($1!="l") print $0}' ${IGCM_DEM}/Listing.txt > ${IGCM_TMP}/Listing_tmp.txt; mv ${IGCM_TMP}/Listing_tmp.txt ${IGCM_DEM}/Listing.txt
# on retire les fichiers run.card
sed '/run.card/d' ${IGCM_DEM}/Listing.txt > ${IGCM_TMP}/Listing_tmp.txt; mv ${IGCM_TMP}/Listing_tmp.txt ${IGCM_DEM}/Listing.txt
# on retire les fichiers Script_Output
sed '/Script_Output/d' ${IGCM_DEM}/Listing.txt > ${IGCM_TMP}/Listing_tmp.txt; mv ${IGCM_TMP}/Listing_tmp.txt ${IGCM_DEM}/Listing.txt

#possibilite de retirer d'autres types de fichiers ex: .jnl* 


DEM_log -0 "Fin de ${SCRIPT_NAME}"

