@echo off
rem ver.1.1

rem LANG 0:Jp 1:Eng
set LANG=0

rem chcp 437

set FOLDER=%~dp0

rem 0:input param  1:fix param
set SIMPLMODE=0

set PARAMMODE=0

set RESOLUTION=600

if %LANG% == 0 (
    set TODAY=%DATE:~2,2%%DATE:~5,2%%DATE:~8,2%
) else (
    set TODAY=%DATE:~0,2%%DATE:~3,2%%DATE:~8,2%
)
set TODAY=%TODAY: =0%

set NowTime=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
set NowTime=%NowTime: =0%

rem check of tiff file
set TFLAG=FALSE
for %%f in ("%FOLDER%"\work\*.tif) do (
     set TFLAG=TRUE
)
if %TFLAG% == FALSE (
    echo;
    echo There is no tif file in the work folder under InkProcFolder.
    echo Use photoshop to convert pdf to tif format.
    pause
    exit /b
)

rem sample mode
if %SIMPLMODE% == 1 (
	set PRINTMODE=2
	set MEDIA=1
	set HTMODE=1
    set PARAMMODE=1
    goto PARAM01
)

rem parameta execute
set PARAMMODE=0
if not "%1" == "" (
    set PRINTMODE=%1
    set MEDIA=%2
    set HTMODE=%3
    set PARAMMODE=1
    goto PARAM01
)




echo;
:INPUT_CHECK
set INPUTSTR=
set /P INPUTSTR="Enter the print mode number. RICH(1)/STD(2)/ECO(3):"
set PRINTMODE=%INPUTSTR%

set INPUTSTR=
set /P INPUTSTR="Enter the paper type by number. Coat (1)/Matte (2)/Woodfree or Fine (3):"
set MEDIA=%INPUTSTR%

set INPUTSTR=
set /P INPUTSTR="Please enter the image quality type as a number. Normal (1) / HighDefinition (2):"
set HTMODE=%INPUTSTR%

rem input check
set PFLAG=FALSE
if "%PRINTMODE%" == "1" set PFLAG=TRUE
if "%PRINTMODE%" == "2" set PFLAG=TRUE
if "%PRINTMODE%" == "3" set PFLAG=TRUE
if %PFLAG% == FALSE (
    echo ""
    echo The numbers entered in print mode are not correct. Please try again.
    GOTO INPUT_CHECK
)
set MFLAG=FALSE
if "%MEDIA%" == "1" set MFLAG=TRUE
if "%MEDIA%" == "2" set MFLAG=TRUE
if "%MEDIA%" == "3" set MFLAG=TRUE
if %MFLAG% == FALSE (
    echo ""
    echo The number entered for the paper type is not correct. Please try again.
    GOTO INPUT_CHECK
)
set HTFLAG=FALSE
if "%HTMODE%" == "1" set HTFLAG=TRUE
if "%HTMODE%" == "2" set HTFLAG=TRUE
if %HTFLAG% == FALSE (
    echo ""
    echo The number you entered for the image quality type is not correct. Please try again.
    GOTO INPUT_CHECK
)

:PARAM01


for %%f in ("%FOLDER%"work\*.tif) do (

     echo ************ Processing file name:"%%~nxf" ****************

     echo ************ Processing ICC profile" ****************
     rem Processing ICC profile
     cd .\exe\ICC
     call ICC.bat "%%~dpnf" %PRINTMODE%_%MEDIA%_%HTMODE%
     cd ..\..\


     rem Ink limit processing
     echo ************ Ink limit processing in progress" ****************
     cd  .\exe\ColorMatching
     call inklimit.bat "%%~dpnf_icc" %PRINTMODE%_%MEDIA%_%HTMODE%
     cd ..\..


     rem Histogram processing
     echo ************ Histogram processing in progress" ****************
     .\exe\TotalINK\histogram.exe "%%~dpnf_icc_limit.tif" "%%~dpnf_hist.csv"


     rem Ink limit  calculate
     echo ************ Ink amount calculation in progress" ****************
     cd  .\exe\TotalINK
     call TOTAL.bat  "%%~dpnf_hist.csv" %MEDIA%_%HTMODE% "%%~dpnf_total.csv"
     cd ..\..

rem Ink limit  calculate respons addout  file
     echo "%%~nxf" >> .\work\totalinkmargfile.csv
     type "%%~dpnf_total.csv" >> .\work\totalinkmargfile.csv

)

rem ink total Ink limit  calculate and report file output
.\exe\totalinkmarg.exe %RESOLUTION% %PRINTMODE% %MEDIA% %HTMODE% .\work\totalinkmargfile.csv > report%TODAY%_%NowTime%.txt

rem delete of tif and csv in folder
del "%FOLDER%"\work\*.tif
del "%FOLDER%"\work\*.csv

echo Processing completed.

if %PARAMMODE% == 0 (
	echo Displays a report of total ink amount.
	pause
	rem  @report displays
	Start .\report%TODAY%_%NowTime%.txt
)

exit /b
