echo OFF
REM
REM script template to run Code_Aster using MPI on windows
REM
REM
REM This template contains following Python strings formatting keys :
REM
REM     cmd_to_run         : Code_Aster command line
REM     mpi_get_procid_cmd : command to retreive processor ID
REM
REM automatically generated for job number #%(num_job)s
REM

set ASRUN_PROCID=%%%(mpi_get_procid_cmd)s%%

IF [%%ASRUN_PROCID%%] == [] (
    echo "Processor ID is not defined !"
    exit 4
)

set ASRUN_WRKDIR=%(local_wrkdir)s\proc.%%ASRUN_PROCID%%

IF EXIST %%ASRUN_WRKDIR%%\NUL (
    rd /s /q %%ASRUN_WRKDIR%%
)

IF NOT EXIST %(local_wrkdir)s\NUL (
    md %(local_wrkdir)s
)

xcopy /e /i %(wrkdir)s %%ASRUN_WRKDIR%%

if %%errorlevel%% NEQ 0 (
    echo "non zero exit status for : xcopy /e /i %(wrkdir)s %%ASRUN_WRKDIR%%"
    exit 4
)

cd %%ASRUN_WRKDIR%%
%(cmd_to_run)s
set /a iret=%%errorlevel%%
if %%ASRUN_PROCID%%==0 (
    echo "%(content_after_msg)s %%ASRUN_WRKDIR%% :"
    dir . REPE_OUT
    del /f /q %(wrkdir)s\glob.* %(wrkdir)s\bhdf.* %(wrkdir)s\pick.*
    rd /s /q %(wrkdir)s\REPE_OUT
    REM to save time during the following copy
    rd /s /q %%ASRUN_WRKDIR%%\REPE_IN %%ASRUN_WRKDIR%%\Python
    xcopy /e /i /y %%ASRUN_WRKDIR%%\* %(wrkdir)s\
    set /a iret=%%errorlevel%% + %%iret
)


cd ..
rmdir /s /q %%ASRUN_WRKDIR%%

exit /b %%iret%%
