#!/bin/bash

#On decide d'archiver via tar une simulation entiere : 
# - si elle est trop petite 
# - si elle ne contient aucun fichier d'output correspondant a la norme etablie JobName_date 


config_card=${1}

# Declaration des variables

# ----
export JOB_DIR=${JOB_DIR:-${PWD}}
export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM}
export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp}
mkdir -p ${IGCM_DEM}
mkdir -p ${IGCM_TMP}
clean_tmp=${clean_tmp:-yes}
EXE_DIR=$(dirname ${0} )
SCRIPT_NAME=$(basename ${0} )
source ${EXE_DIR}/DEM_utilities.sh
DEM_log -0 "Demmarrage de ${SCRIPT_NAME}"
cd ${JOB_DIR}
# ----
DEM_log -0 "Debut de ${SCRIPT_NAME}"
DEM_log -0 "On va archiver via tar la simulation " ${PATH_SIMUL_FULL}
DEM_log -0 "config_card : ${config_card}"

eval $(grep JobName         ${config_card}) 
eval $(grep PATH_SIMUL_FULL ${config_card}) 
eval $(grep DateBegin       ${config_card}) 
eval $(grep DateEnd         ${config_card}) 
eval $(grep IGCM_DEM_SIMU   ${config_card})


echo  ${PATH_SIMUL_FULL} > ${IGCM_DEM_SIMU}/tar_full_simul.list

# Dans ce cas la on efface les eventuelles listes deja creees
rm -f ${IGCM_DEM_SIMU}/tar_no_output_files.txt
rm -f ${IGCM_DEM_SIMU}/tar_no_restart_files.txt
rm -f ${IGCM_DEM_SIMU}/work_cp/*
rm -f ${IGCM_DEM_SIMU}/store_cp/*
rm -f ${IGCM_DEM_SIMU}/other_tar/*

DEM_write_state ${IGCM_DEM}/config_card.liste ${config_card} WriteListTarDone

DEM_log -0 "Fin de ${SCRIPT_NAME}"
