#!/bin/bash

#MSUB -r pack_ipsl          # Nom du job                
#MSUB -e IO_parallel/launchMeasureTimeOutput/pack_ipsl_%I.e
#MSUB -o IO_parallel/launchMeasureTimeOutput/pack_ipsl_%I.o
#MSUB -n 7            # Reservation du processus
#MSUB -T 2500            # Limite de temps elapsed du job (en secondes)
#MSUB -A tgcc0013
#MSUB -q standard
# #MSUB -q large
#MSUB -Qos test



export JOB_DIR=${LS_SUBCWD:-${PWD}}
export EXE_DIR=${JOB_DIR}
source ${EXE_DIR}/DEM_utilities.sh


export IGCM_DEM=${SCRATCHDIR}/IGCM_DEM


# inputCmd="myIO/inputCmd.list"
inputCmd="inputCmd_Realistic.list"
output="IO_parallel/output.log"

> ${inputCmd}

listOfDir="output_ncrcat output_tar restart_tar debug_tar store_cp work_cp"

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

   PATH_SIMU=$( dirname $CONFIG )
   echo "PATH_SIMU=$PATH_SIMU"
   echo "------------------------------------------"
   for typeDir in $listOfDir
   do
       typeDirList=`find $PATH_SIMU -type d -name "$typeDir" `
       for dir in $typeDirList
       do
           # echo "dir=$dir"
	   listFilesInDir=`find $dir -name "*.list" `
	   for file in $listFilesInDir
	   do
	       echo "./process_list.sh $file" >> ${inputCmd}
	   done
       done
   done
   

done



startTime=$( getDateMilliSeconds )
echo "start time:$startTime" >> $timeHandlingFile

ccc_mprun  ./cmd_launch.exe ${inputCmd} 2>${output}
# ./cmd_launch.exe ${inputCmd} 2>${output}
# ccc_mprun -p standard -n ${BRIDGE_MSUB_NPROC} ./cmd_launch.exe ${inputCmd} 2>myIO/output.log
# mpirun -n 4 ./cmd_launch.exe myIO/inputCmd10.list 2>myIO/output.log

meantime=$( getTimeDiffSeconds $startTime )

endExecutionTime=$( getDateMilliSeconds )
echo "end time:$endExecutionTime" >> $timeHandlingFile


echo "meantime ncrcat = $meantime"
