@echo off
setlocal EnableDelayedExpansion
rem Don't remove the two jump line after than the next line [set NL=^]
set NL=^


rem "name" and "dirout" are named according to the testcase

set name=flapping1
set dirout=%name%_out
set diroutdata=%dirout%\data

rem "executables" are renamed and called from their directory

set dirbin=../../../bin/windows
set gencase="%dirbin%/GenCase_win64.exe"
set dualsphysicscpu="%dirbin%/DualSPHysics5.0CPU_win64.exe"
set dualsphysicsgpu="%dirbin%/DualSPHysics5.0_win64.exe"
set boundaryvtk="%dirbin%/BoundaryVTK_win64.exe"
set partvtk="%dirbin%/PartVTK_win64.exe"
set partvtkout="%dirbin%/PartVTKOut_win64.exe"
set measuretool="%dirbin%/MeasureTool_win64.exe"
set computeforces="%dirbin%/ComputeForces_win64.exe"
set isosurface="%dirbin%/IsoSurface_win64.exe"
set flowtool="%dirbin%/FlowTool_win64.exe"
set floatinginfo="%dirbin%/FloatingInfo_win64.exe"

:menu
if exist %dirout% ( 
	set /p option="The folder "%dirout%" already exists. Choose an option.!NL!  [1]- Delete it and continue.!NL!  [2]- Execute post-processing.!NL!  [3]- Abort and exit.!NL!"
	if "!option!" == "1" goto run else (
		if "!option!" == "2" goto postprocessing else (
			if "!option!" == "3" goto fail else ( 
				goto menu
			)
		)
	)
)

:run
rem "dirout" to store results is removed if it already exists
if exist %dirout% rd /s /q %dirout%

rem CODES are executed according the selected parameters of execution in this testcase

%gencase% %name%_Def %dirout%/%name% -save:all
if not "%ERRORLEVEL%" == "0" goto fail

%dualsphysicsgpu% -gpu %dirout%/%name% %dirout% -dirdataout data -svres
if not "%ERRORLEVEL%" == "0" goto fail

:postprocessing



set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:14 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing1
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:15 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing2
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:16 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing3
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:17 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing4

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:18 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing5
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:19 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing6
if not "%ERRORLEVEL%" == "0" goto fail



set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:23 -viscolam:0.0000148 -savecsv %dirout2%/_flappingrod1
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:24 -viscolam:0.0000148 -savecsv %dirout2%/_flappingrod2
if not "%ERRORLEVEL%" == "0" goto fail



set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:34 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing11
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:35 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing22
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:36 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing33
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:37 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing44

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:38 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing55
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:39 -viscolam:0.0000148 -savecsv %dirout2%/_flappingwing66
if not "%ERRORLEVEL%" == "0" goto fail



set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:43 -viscolam:0.0000148 -savecsv %dirout2%/_flappingrod11
if not "%ERRORLEVEL%" == "0" goto fail

set dirout2=%dirout%\forces
%computeforces% -dirin %diroutdata% -onlymk:44 -viscolam:0.0000148 -savecsv %dirout2%/_flappingrod22
if not "%ERRORLEVEL%" == "0" goto fail



:success
echo All done
goto end

:fail
echo Execution aborted.

:end
pause

