﻿@PUSHD %~dp0
@del ".\mdata.bin" >nul 2>&1
@WHERE /q terastitcher.exe teraconverter.exe
@IF %ERRORLEVEL% NEQ 0 (
    @ECHO The terastitcher.exe or teraconverter.exe application is missing. Please see the Fusion User Guide for further information.
    @PAUSE
    @EXIT /B
) ELSE (
    @ECHO Running terastitcher.exe...
    @"terastitcher.exe" -1 --imin_channel=0 --projin=".\MS42-1_10x_s02.xml" --projout=".\MS42-1_10x_s02_FirstStep.xml" --volin_plugin="TiledXY|3Dseries" --imout_depth=16 --imin_plugin=IMS_HDF5
)
@IF %ERRORLEVEL% NEQ 0 (
    @ECHO Error occured while executing first step of terastitcher.exe
    @PAUSE
    @EXIT /B
) ELSE (
    @"terastitcher.exe" --imin_channel=0 --volin_plugin="TiledXY|3Dseries" --imin_plugin=IMS_HDF5 --projin=".\MS42-1_10x_s02_FirstStep.xml" --projout=".\MS42-1_10x_s02_Out.xml" --threshold=0.6 -2 -3 -4 -5 --sH=101 --sV=101 --sD=1
)
@IF %ERRORLEVEL% NEQ 0 (
    @ECHO Error occured while executing 1-5 steps of terastitcher.exe
    @PAUSE
    @EXIT /B
)
@del ".\MS42-1_10x_s02_StitchedImage.ims" >nul 2>&1
@"teraconverter.exe" -s=".\MS42-1_10x_s02_Out.xml" -d=".\MS42-1_10x_s02_StitchedImage.ims" --imin_plugin=IMS_HDF5 --sfmt="TIFF (unstitched, 3D)" --dfmt="HDF5 (Imaris IMS)" --mdata_fname=".\MS42-1_10x_s02_F00.ims"
@IF %ERRORLEVEL% NEQ 0 (
    @ECHO Error occured while executing teraconverter.exe
    @PAUSE
    @EXIT /B
)
@POPD
