#!/bin/bash
######################
## TITANE   CEA ##
######################
#MSUB -r ipsl_pack      # Nom du job                
#MSUB -eo
#MSUB -n 1              # Reservation du processus
#MSUB -T 86400          # Limite de temps elapsed du job
#MSUB -p gen2211
#MSUB -q mono

# ex : ./launch_ipsl_enlarge.sh

export JOB_DIR=${LS_SUBCWD:-${PWD}}
export EXE_DIR=${JOB_DIR}

export INPUT_DMF_DATA=${SCRATCHDIR}/PSEUDO_DMNFS
export OUTPUT_STORE=${SCRATCHDIR}/PSEUDO_DMNFS_STORE
export OUTPUT_WORK=${SCRATCHDIR}/PSEUDO_DMNFS_WORK

SCRIPT_NAME=$(basename ${0} )

export IGCM_DEM=${SCRATCHDIR}/IGCM_DEM
export IGCM_TMP=${SCRATCHDIR}/IGCM_DEM/tmp
export clean_tmp=${clean_tmp:-yes}
export DEM_LOG=${JOB_DIR}/dem_${LSB_JOBID:-${$}}.log
export LOG_LEV=2

export config_card=${IGCM_DEM}/config_card.liste

source ${EXE_DIR}/DEM_utilities.sh

DEM_log -0 "Demarrage de ${SCRIPT_NAME}"

for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste ) ; do 

    DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${CONFIG} )

    if [[ "${DEM_state}" != "WriteListTarDone" ]] ; then

	DEM_write_state ${IGCM_DEM}/config_card.liste ${CONFIG} PackRunning
	export PATH_SIMU=$( dirname $CONFIG )
	${EXE_DIR}/enlarge_my_files.sh ${INPUT_DMF_DATA} ${OUTPUT_STORE} ${OUTPUT_WORK}
    
	DEM_write_state ${IGCM_DEM}/config_card.liste ${CONFIG} PackDone

    fi

done

DEM_log -0 "Fin de ${SCRIPT_NAME}"
